def deploy_mpy(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in libs: print('deploy ', file_name) src_code = eosapi.mp_compile(os.path.join(src_dir, file_name)) file_name = file_name.replace('.py', '.mpy') src_id = eosapi.hash64(file_name, 0) itr = db.find_i64(code, code, code, src_id) if itr >= 0: #Something went wrong in mp_compile. #Generating different bytecode each time with the same source code, walkaround this problem for now continue old_src = db.get_i64(itr) if old_src[1:] == src_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(1, 1, 'little') # compiled python bytecode msg += src_code print('++++++++++++++++deply:', file_name) r = eosapi.push_action('backyard','deploy',msg,{'backyard':'active'}) assert r
def test2(count=100): contracts = [] functions = [] args = [] per = [] for i in range(count): functions.append('setgreeting') arg = str(i) args.append(arg) contracts.append('greeter') per.append({'greeter': 'active'}) ret = eosapi.push_messages(contracts, functions, args, per, True) assert ret cost = ret['cost_time'] print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count))) eosapi.produce_block() code = eosapi.N('greeter') id = eosapi.hash64('greeting', 0) greeting = 0 itr = eoslib.db_find_i64(code, code, code, id) if itr >= 0: greeting = eoslib.db_get_i64(itr) print(greeting[1:])
def deploy_mpy(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in libs: print('deploy ', file_name) src_code = eosapi.mp_compile(os.path.join(src_dir, file_name)) file_name = file_name.replace('.py', '.mpy') src_id = eosapi.hash64(file_name, 0) itr = eoslib.db_find_i64(code, code, code, src_id) if itr >= 0: old_src = eoslib.db_get_i64(itr) if old_src[1:] == src_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(1, 1, 'little') # compiled code msg += src_code print('++++++++++++++++deply:', file_name) r = eosapi.push_message('backyard', 'deploy', msg, {'backyard': 'active'}) assert r producer.produce_block()
def deploy_wast(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in ('math.wast', ): print('deploy ', file_name) bin_code = None with open(os.path.join(src_dir, file_name), 'rb') as f: bin_code = eosapi.wast2wasm(f.read()) src_id = eosapi.hash64(file_name, 0) itr = db.find_i64(code, code, code, src_id) if itr >= 0: old_src = db.get_i64(itr) if old_src[1:] == bin_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(3, 1, 'little') # compiled cpp bytecode msg += bin_code print(msg) print('++++++++++++++++deply:', file_name) r = eosapi.push_action('backyard', 'deploy', msg, {'backyard': 'active'}) assert r
def need_update(self, src_dir, src_file, mpy=False): if mpy: id = eosapi.hash64(src_file.replace('.py', '.mpy')) else: id = eosapi.hash64(src_file) code = eosapi.N(self.account) itr = eoslib.db_find_i64(code, code, code, id) if itr < 0: return True old_src = eoslib.db_get_i64(itr) _full_file_path = os.path.join(src_dir, src_file) if not mpy: with open(_full_file_path, 'rb') as f: if old_src[1:] == f.read(): return False else: src_code = eosapi.mp_compile(_full_file_path) if old_src[1:] == src_code: return False return True
def test2(count=100): actions = [] for i in range(count): action = ['greeter', 'setgreeting', str(i), {'greeter':'active'}] actions.append(action) ret, cost = eosapi.push_actions(actions, True) assert ret print('total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f'%(cost/1e6, cost/count/1000, 1*1e6/(cost/count))) eosapi.produce_block() code = eosapi.N('greeter') id = eosapi.hash64('greeting', 0) greeting = 0 itr = db.find_i64(code, code, code, id) if itr >= 0: greeting = db.get_i64(itr) print(greeting[1:])
def deploy(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in libs: src_code = open(os.path.join(src_dir, file_name), 'rb').read() src_id = eosapi.hash64(file_name, 0) itr = db.find_i64(code, code, code, src_id) if itr >= 0: old_src = db.get_i64(itr) if old_src[1:] == src_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(0, 1, 'little') # source code msg += src_code print('++++++++++++++++deply:', file_name) r = eosapi.push_action('backyard','deploy',msg,{'backyard':'active'}) assert r producer.produce_block()