def start_single(self, name, path, p2p_address, http_port, p2p_port, genesis_node_address, genesis_path): try: nodepath = join(path, self.folder_scheme + name) if not os.path.isdir(nodepath): os.makedirs(nodepath) os.chdir(nodepath) config = ConfigurationParser() config.read(join(self.parent_dir, 'config/template_config.ini')) config.set('blocks-dir', join(nodepath, 'blocks')) config.set('http-server-address', '0.0.0.0:' + http_port) config.set('p2p-listen-endpoint', '0.0.0.0:' + p2p_port) config.set('p2p-server-address', '%s:%s' % (p2p_address, p2p_port)) config.set('producer-name', name) pair = self.wallet.create_import() config.set('signature-provider', self.create_sig_provider(pair)) plugins = [ 'eosio::http_plugin', 'eosio::chain_plugin', 'eosio::chain_api_plugin', 'eosio::history_plugin', 'eosio::history_api_plugin', 'eosio::net_plugin', 'eosio::net_api_plugin', 'eosio::producer_plugin' ] config.append('plugin', plugins) config.set('p2p-peer-address', genesis_node_address) config.write(join(nodepath, 'config.ini')) copyfile(genesis_path, join(nodepath, "genesis.json")) node = Node(name, nodepath) node.start(1.0) self.update_node_state(node) self.save() except FileNotFoundError as e: print(e)
def set_system_contracts(self, contract_names): try: for contract in contract_names: name = contract['name'] path = join(os.path.abspath(self.telos_dir), join(self.contracts, name)) self.set_contract(contract['owner'], path) except IOError as e: print(e)
def start(self, delay_time=1.0): if not os.path.isdir(self.path): os.makedirs(self.path) cmd = NodeFactory.nodeos_dir + ' --config-dir %s --genesis-json %s --delete-all-blocks' genesis_dir = join(self.path, 'genesis.json') print('Starting node: %s' % self.name) start_background_proc(cmd % (self.path, genesis_dir), log_file(join(self.path, 'stderr.txt')), join(self.path, 'node.pid')) sleep(delay_time)
def start_wallet(self): if not os.path.isdir(self.wallet_state): os.makedirs(self.wallet_state) start_background_proc( self.keosd_dir + ' --unlock-timeout %d --http-server-address 127.0.0.1:8999' % (self.unlockTimeout), log_file(join(self.wallet_state, 'stderr.txt')), join(self.wallet_state, 'keosd.pid')) sleep(.4)
def restart(self, delay_time=1.0): if self.is_running(): self.stop() if os.path.isdir(self.path): cmd = NodeFactory.nodeos_dir + ' --config-dir %s --hard-replay-blockchain' start_background_proc(cmd % self.path, log_file(join(self.path, 'stderr.txt')), join(self.path, 'node.pid')) sleep(delay_time) else: print('nodeos folder path: %s does not exist' % self.path)
def boot_strap_node(self, address): self.set_host_address(address) #TODO: Make sure full node has eosio root key in wallet self.account_factory.create_system_accounts(self.systemAccounts) self.set_system_contracts(self.systemContracts) self.issue_token(self.token_supply, self.token_issue) system_contract = join(join(self.telos_dir, self.contracts), 'eosio.system') run(self.teclos_dir + ' --url %s set contract eosio %s -p eosio' % (self.host_address, system_contract)) run(self.teclos_dir + ' --url %s push action eosio setpriv \'[\"eosio.msig\", 1]\' -p eosio@active' % self.host_address)
def start(self, delay_time=1.0, flags={}): print(flags) if not os.path.isdir(self.path): os.makedirs(self.path) cmd = NodeFactory.nodeos + ' --config-dir %s --genesis-json %s --delete-all-blocks' for key in flags: cmd += " --{} {}".format(key, flags[key]) genesis_dir = join(self.path, 'genesis.json') print('Starting node: %s' % self.name) start_background_proc(cmd % (self.path, genesis_dir), log_file(join(self.path, 'stderr.txt')), join(self.path, 'node.pid')) sleep(delay_time)
def __init__(self, wallet_state, keosd_dir, unlockTimeout=120): self.wallet_state = wallet_state self.wallet_dir = join(os.path.expanduser('~'), 'telos-wallet') self.keosd_dir = keosd_dir self.unlockTimeout = unlockTimeout self.api = API( api_root_url='http://127.0.0.1:8999/v1/wallet', params={}, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }, timeout=2, append_slash=False, json_encode_body=True, ) self.api.add_resource(resource_name='wallet', resource_class=WalletResource) self.pid = -1 if not self.is_running(): print('Creating new instance of tkeosd') self.start_wallet() if not self.wallet_exists('default'): print('Default wallet not found, creating new default wallet') self.create('default')
def get_pid(self): path = join(self.path, 'node.pid') if os.path.isfile(path): pid = int(file_get_contents(path)) self.pid = pid return pid return -1
def __init__(self, wallet_state, teclos_dir, telos_dir, keosd_dir, unlockTimeout=120, forceRestart=False): self.wallet_state = wallet_state self.wallet_dir = join(os.path.expanduser('~'), 'telos-wallet') self.teclos_dir = teclos_dir self.telos_dir = telos_dir self.keosd_dir = keosd_dir self.wallet_address = 'http://127.0.0.1:8999' self.teclos_start = '%s --wallet-url %s' % (teclos_dir, self.wallet_address) self.unlockTimeout = unlockTimeout self.pid = -1 if forceRestart: self.reset() if not self.is_running(): #print("Init start wallet function") self.start_wallet() if not self.exists() and os.path.isfile(teclos_dir): #print("Creating wallet because none exists") self.create()
def get_pid(self): #print("get_pid()") path = join(self.wallet_state, 'keosd.pid') if os.path.isfile(path): pid = int(file_get_contents(path)) self.pid = pid return pid
def boot_strap_node(self, address): self.set_host_address(address) self.account_factory.set_host_address(address) # TODO: Make sure full node has eosio root key in wallet self.account_factory.create_pre_accounts(self.pre_accounts) self.set_system_contracts(self.pre_accounts) self.issue_token(self.token_supply, self.token_issue) system_contract = join(self.contracts_dir, 'eosio.system') res = requests.post( self.host_address + '/v1/producer/schedule_protocol_feature_activations', data=toJson({ 'protocol_features_to_activate': [ "0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd" ] })) print(res) print(res.content) sleep(2) run(self.teclos_dir + ' --url %s set contract eosio %s -p eosio' % (self.host_address, system_contract)) args = toJson([0, "4,TLOS"]) run(self.teclos_dir + ' --url %s push action eosio init \'%s\' -p eosio' % (self.host_address, args)) run(self.teclos_dir + ' --url %s push action eosio setpriv \'[\"eosio.msig\", 1]\' -p eosio@active' % self.host_address) self.account_factory.create_post_accounts(self.post_accounts, self.setup_post_account)
def update_pid(self, pid): path = join(self.wallet_state, 'keosd.pid') if os.path.isfile(path): os.rmdir() with open(path, 'w') as pid_file: pid_file.write(pid) return pid return 0
def create(self): if not self.is_running(): self.start_wallet() if not os.path.exists(self.wallet_state): os.makedirs(self.wallet_state) o = get_output(self.teclos_start + ' wallet create --to-console') f = open(join(self.wallet_state, 'wallet_pw.txt'), 'w') f.write(self.parse_pw(o))
def set_system_contracts(self, contract_names): try: for contract in contract_names: if 'contract' in contract: name = contract['contract'] path = join(self.contracts_dir, name) self.set_contract(contract['name'], path, contract['name']) except IOError as e: print(e)
def get_pw(self): try: p = join(self.wallet_state, "wallet_pw.txt") if os.path.exists(p): f = open(p, 'r') return f.readline() else: print('wallet password does not exist') except Exception as e: print(e)
def __init__(self, working, parent, nodeos, wallet): self.folder_scheme = 'tn-' NodeFactory.nodeos_dir = nodeos self.parent_dir = parent self.working_dir = working self.config_dir = join(parent, 'config/nodes.json') self.state = json.loads(file_get_contents(self.config_dir)) if 'nodes' not in self.state: self.state['nodes'] = {} self.wallet = wallet
def get_pw(self, name): try: p = join(self.wallet_state, "wallet_pw.json") if os.path.isfile(p): j = json.loads(file_get_contents(p)) if name in j: return j[name] return None except Exception as e: print(e)
def set_peers(self, peers): tmp = peers.copy() self.remove_self(tmp) endpoints = [] for name in tmp: endpoints.append(tmp[name]) self.config.append('p2p-peer-address', endpoints) self.config.write(join(self.path, 'config.ini'))
def __init__(self, parent_dir, contracts, teclos, host_address, account_factory): self.contracts_dir = join(os.path.abspath(contracts), 'build/contracts') self.teclos_dir = teclos self.host_address = host_address self.account_factory = account_factory accounts = fromJson( file_get_contents(parent_dir + '/config/accounts.json')) self.pre_accounts = accounts['pre-accounts'] self.post_accounts = accounts['post-accounts']
def create_producer_node(self, account, path, p2p_address): try: nodepath = join(path, self.folder_scheme + account.name) if not os.path.isdir(nodepath): os.makedirs(nodepath) os.chdir(nodepath) config = ConfigurationParser() config.read(join(self.parent_dir, 'config/template_config.ini')) config.set('blocks-dir', join(nodepath, 'blocks')) config.set('http-server-address', '0.0.0.0:' + str(self.get_open_port())) p2p_port = str(self.get_open_port()) config.set('p2p-listen-endpoint', '0.0.0.0:' + p2p_port) config.set('p2p-server-address', '%s:%s' % (str(p2p_address), str(p2p_port))) config.set('producer-name', account.name) config.set('signature-provider', self.create_sig_provider(account.keypair)) plugins = ['eosio::producer_plugin'] config.append('plugin', plugins) config.write(join(nodepath, 'config.ini')) copyfile(join(self.parent_dir, 'config/genesis.json'), join(nodepath, "genesis.json")) node = Node(account.name, nodepath) return node except FileNotFoundError as e: print(e)
def set_pw(self, name, pw): try: print('setting new wallet password') p = join(self.wallet_state, "wallet_pw.json") j = {} if not os.path.isdir(self.wallet_state): os.mkdir(self.wallet_state) if os.path.isfile(p): j = json.loads(file_get_contents(p)) j[name] = pw with open(p, 'w') as pw_file: print('writing new password file') pw_file.write(json.dumps(j)) except Exception as e: raise e
def __init__(self, wallet_state, cleos, keosd, unlockTimeout=120, forceRestart=False): self.wallet_state = wallet_state self.wallet_dir = join(os.path.expanduser('~'), 'eosio-wallet') self.cleos = cleos self.keosd = keosd self.wallet_address = 'http://127.0.0.1:8999' self.teclos_start = '%s --wallet-url %s' % (cleos, self.wallet_address) self.unlockTimeout = unlockTimeout self.pid = -1 if not self.open(): self.create()
def start_full(self, path, p2p_address, http_port, p2p_port, a_plugins=[]): try: flags = {} nodepath = join(path, self.folder_scheme + 'genesis') if not os.path.isdir(nodepath): os.makedirs(nodepath) os.chdir(nodepath) config = ConfigurationParser() config.read(join(self.parent_dir, 'config/template_config.ini')) config.set('blocks-dir', join(nodepath, 'blocks')) config.set('http-server-address', '0.0.0.0:' + http_port) config.set('p2p-listen-endpoint', '0.0.0.0:' + p2p_port) config.set('p2p-server-address', '%s:%s' % (p2p_address, p2p_port)) config.set('enable-stale-production', True) config.set('producer-name', 'eosio') pair = self.wallet.create_import() self.edit_new_genesis(pair.public) config.set('signature-provider', self.create_sig_provider(pair)) plugins = [ 'eosio::http_plugin', 'eosio::chain_plugin', 'eosio::chain_api_plugin', 'eosio::producer_plugin', 'eosio::producer_api_plugin', 'eosio::history_plugin', 'eosio::history_api_plugin' ] + a_plugins if "eosio::mongo_db_plugin" in plugins: flags['mongodb-uri'] = "mongodb://127.0.0.1:27017/EOS" flags['mongodb-wipe'] = '' config.append('plugin', plugins) config.write(join(nodepath, 'config.ini')) copyfile(join(self.parent_dir, 'config/genesis.json'), join(nodepath, "genesis.json")) node = Node('genesis', nodepath) node.start(3.0, flags) self.update_node_state(node) self.save() except FileNotFoundError as e: print(e)
def show_output(self): tail(join(self.path, 'stderr.txt'))
def create(self): if not os.path.exists(self.wallet_state): os.makedirs(self.wallet_state) run(self.cleos + ' wallet create --file ' + join(self.wallet_state, 'wallet_pw.txt'))
def __init__(self, name, path): self.config = ConfigurationParser() self.path = os.path.abspath(path) self.name = name self.config.read(join(path, 'config.ini')) self.pid = self.get_pid()
def edit_new_genesis(self, public): j = json.loads( file_get_contents(join(self.parent_dir, 'config/genesis.json'))) j['initial_key'] = public create_file(join(self.parent_dir, 'config/genesis.json'), json.dumps(j))