Example #1
0
    def compile(self):
        ezo = self.app.ezo
        log = self.app.log

        for filename in self.app.pargs.extra_args:
            log.info(cyan("compiling contracts in {}".format(filename)))

            filename = get_contract_path(self.app.config["ezo"], filename)
            contracts_source, err = Contract.load(filename)
            if err:
                log.error(red("error loading contracts file: {}".format(err)))
                return err

            contracts, err = Contract.compile(contracts_source, ezo)
            if err:
                log.error(
                    red("error compiling contracts source: {}".format(err)))
                return err

            # persist the compiled contract
            for contract in contracts:
                contract.source = contracts_source
                iid, err = contract.save(overwrite=self.app.pargs.overwrite)
                if err:
                    log.error(
                        red("error while persisting Contract to datastore: {}".
                            format(err)))
                    return err
                else:
                    log.info(cyan("contract saved: {}".format(iid)))
                    print("pytest>>CONTRACT_SAVED")
            return
Example #2
0
    def handlers(self):
        log = self.app.log
        ezo = self.app.ezo
        args = self.app.pargs

        # set the Source template directory from config
        Source.templates_dir = ezo.config["templates-dir"]

        # go through each contract hash and create handlers
        for h in args.extra_args:
            log.info(
                cyan("generating any missing event handlers for contract: {}".
                     format(h)))
            c, err = Contract.get(h, ezo)
            if err:
                log.error(red("error getting contract: {}".format(err)))
                continue
            if not c:
                log.error(
                    red("no contract was found for {} - was it compiled?".
                        format(h)))
                continue
            _, err = c.generate_event_handlers(overwrite=args.overwrite)
            if err:
                log.error(
                    red("error generating handlers for {}: {}".format(h, err)))
                continue
            log.info(cyan("handlers for contract {} generated".format(h)))
        return
Example #3
0
def view_deploys(results):
    l = list()
    for res in results:
        for key, value in res.items():
            key = key.replace(EZO.DEPLOYED + ":", "").split(':')
            l.append(
                "contract: {:35s} target: {:20s} hash: {:27s} address: {:35s} timestamp: {:25s}"
                .format(cyan(key[0]), magenta(key[1]), blue(key[2]),
                        blue(value["address"]), cyan(value["timestamp"])))
    return l
Example #4
0
    def deploy(self):

        ezo = self.app.ezo
        log = self.app.log
        args = self.app.pargs

        # inject password into the environment
        if args.password:
            os.environ["EZO_PASSWORD"] = args.password

        log.debug("deploying...")

        if not args.target:
            log.error(
                red("target must be set with the -t option before deploying"))
            return

        _, err = ezo.dial(args.target)
        if err:
            log.error(red("unable to dial node"))
            log.error(red("error: {}".format(err)))
            return

        for h in args.extra_args:
            log.info(cyan("deploying contract {} to {}".format(h,
                                                               args.target)))

            # get the compiled contract by it's Contract Name
            c, err = Contract.get(h, ezo)
            if err:
                log.error(
                    red("error loading contract from storage: {}".format(err)))
                return
            if not c:
                log.error(
                    red("contract '{}' not found -- has it been compiled?").
                    format((h)))
                return

            # deploy the contract
            addr, err = c.deploy(target=args.target,
                                 overwrite=self.app.pargs.overwrite)
            if err:
                log.error(
                    red("error deploying contract {} to {}".format(
                        c.hash, args.target)))
                log.error(red("message: {}".format(err)))
                return

            log.info(
                cyan(
                    "successfully deployed contract {} named {} to stage '{}' at address {}"
                    .format(c.hash, c.name, args.target, addr)))

        return
Example #5
0
def view_contracts(results):
    l = list()
    for res in results:
        for key, value in res.items():
            key = key.replace(EZO.CONTRACT + ":", "")
            l.append(
                bright(
                    "contract: {:35s} hash: {:25s} timestamp: {:25s}".format(
                        cyan(key), format(blue(value["hash"])),
                        cyan(value["timestamp"]))))
    return l
Example #6
0
    def start(self):

        log = self.app.log
        ezo = self.app.ezo
        args = self.app.pargs

        # inject password into the environment
        if args.password:
            os.environ["EZO_PASSWORD"] = args.password

        log.debug("starting ezo")
        if not args.target:
            log.error("target must be set with the -t option before deploying")
            return


#        ezo.target = args.target
        _, err = ezo.dial(args.target)
        if err:
            log.error(red("error with node: {}".format(err)))
            return err

        if not args.extra_args:
            log.error(red("error: missing contract name"))
            return

        res, err = ezo.start(args.extra_args, target=args.target)
        if err:
            log.error(red("error: {}".format(err)))
        else:
            log.info(cyan("result: {}".format(res)))
Example #7
0
def create_ethereum_account():
    ac = Account.create()
    wf = xp.locate_wordfile()
    words = xp.generate_wordlist(wordfile=wf, min_length=5, max_length=8)

    password_str = xp.generate_xkcdpassword(words)
    print(
        cyan(
            "password string to decrypt private key -- please store in safe location:"
        ))
    print()
    print(yellow(password_str))
    print()
    print(cyan("address:"))
    print(yellow(ac.address))

    ks = json.dumps(Account.encrypt(ac.privateKey, password_str), indent=2)
    print(red(ks))
Example #8
0
    def tx(self):
        params = self.app.pargs.c_args
        ezo = self.app.ezo
        args = self.app.pargs
        log = self.app.log

        # inject password into the environment
        if args.password:
            os.environ["EZO_PASSWORD"] = args.password

        if not args.target:
            log.error("target must be set with the -t option before deploying")
            return

        if len(params) != 3:
            self.app.log.error(
                red("missing parameters for send tx - 3 required"))
            return
        _, err = ezo.dial(args.target)
        if err:
            log.error(red("error with node: {}".format(err)))
            return err

        name = params[0]
        method = params[1]
        data = params[2]

        resp, err = Contract.send(ezo, name, method, data, target=args.target)
        if err:
            self.app.log.error(red("tx error: {}".format(err)))
            return err

        self.app.log.info(bright(blue("==============")))
        for k, v in resp.items():
            self.app.log.info("{}: {}".format(yellow(k), cyan(v)))
        self.app.log.info(blue("=============="))
        self.app.log.info(reset(""))