async def listen(self, address, target): ''' starts event listener for the contract :return: ''' if not address: return None, "listening address not provided" EZO.log.info(bright("hello ezo::listening to address: {}".format(blue(address)))) interval = self._ezo.config["poll-interval"] event_filter = self._ezo.w3.eth.filter({"address": address, "toBlock": "latest"}) loop = asyncio.new_event_loop() try: while True: for event in event_filter.get_new_entries(): if EZO.log: EZO.log.debug(bright("event received: {}".format(event))) ContractEvent.handler(event, self, target) await asyncio.sleep(interval) except Exception as e: return None, e finally: loop.close()
def deploys(self): ezo = self.app.ezo log = self.app.log res, err = get_deploys(self.app.pargs.term, ezo) if err: log.error(red("error viewing deployments")) log.error(red(err)) return err v = view_deploys(res) print() print(bright(blue("+-------+"))) for vs in v: print(yellow(vs)) print(blue("+--------------+")) print(yellow("ezo deployments: {}".format(bright(len(res))))) print(reset("")) return len(res)
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
def project(self): ezo = self.app.ezo # set the Source template directory from config Source.templates_dir = ezo.config["templates-dir"] res, err = EZO.create_project(self.app.pargs.term) if err: print(err) return err print( bright( blue("new ezo project '{}' created".format( self.app.pargs.term)))) print(reset("")) return
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(""))
def create_project(name, include_examples=True): ''' creates the initial project skeleton and files :param name: the project name :return: ''' # from the start directory, create a project directory with the project name path = "{}/{}".format(os.getcwd(), name) if os.path.exists(path): return None, "path {} already exists".format(path) print(bright("creating new ezo project '{}".format(name))) # make project directory os.mkdir(path) print(bright("created project directory: '{}".format(path))) # create an empty contracts directory contracts_dir = "{}/{}".format(path, "contracts") os.mkdir(contracts_dir) print(bright("created contract directory: '{}".format(contracts_dir))) if include_examples: c = [(create_sample_contracts_1(), 'contract1.sol'), (create_sample_contracts_2(), 'contract2.sol')] for s in c: c, fn = s file_path = "{}/{}".format(contracts_dir, fn) try: with open(file_path, "w+") as outfile: outfile.write(c) except Exception as e: print(bright("problem creating sample file: '{}".format(path))) return None, e print(bright("created sample contract: '{}".format(fn))) # create the handlers directory handlers_dir = "{}/{}".format(path, "handlers") os.mkdir(handlers_dir) print(bright("created handlers directory: '{}".format(handlers_dir))) # leveldb directory (created by level) leveldb = "{}/{}".format(path, "ezodb") # create the initial config.json file cfg = create_blank_config_obj() cfg["ezo"]["contract-dir"] = contracts_dir cfg["ezo"]["handlers-dir"] = handlers_dir cfg["ezo"]["project-name"] = name cfg["ezo"]["leveldb"] = leveldb print(bright("creating configuration: '{}".format(path))) # write the file to the root project dir config_file_path = "{}/{}".format(path, "ezo.conf") try: with open(config_file_path, "w+") as outfile: json.dump(cfg, outfile, indent=2) except Exception as e: print(bright("problem creating configuration file: '{}".format(path))) return None, e return None, None