def publish_py_contract(account_name, code, abi, vm_type=1, includes = [], entry='apply'): m = hashlib.sha256() code = compile(code, "contract", 'exec') code = marshal.dumps(code) m.update(code) code_hash = m.hexdigest() r = eosapi.get_code(account_name) if code_hash != r['code_hash']: eosapi.set_contract(account_name, code, abi, 1) return True
def deploy_contract(account_name, contract_name, contracts_path=None): if not contracts_path: contracts_path = os.path.dirname(__file__) contracts_path = os.path.join(contracts_path, 'contracts') code_path = os.path.join(contracts_path, f'{contract_name}/{contract_name}.wasm') abi_path = os.path.join(contracts_path, f'{contract_name}/{contract_name}.abi') logger.info(code_path) code = open(code_path, 'rb').read() abi = open(abi_path, 'rb').read() m = hashlib.sha256() m.update(code) code_hash = m.hexdigest() try: r = eosapi.get_code(account_name) logger.info((code_hash, r['code_hash'])) if code_hash != r['code_hash']: logger.info(f"++++++++++set contract: {contract_name}") r = eosapi.set_contract(account_name, code, abi, 0) return True except Exception as e: print(e)
def publish_cpp_contract(account_name, code, abi='', includes = [], entry='apply'): code = compile_cpp_src(account_name, code, includes, entry=entry) code = open(f'tmp/{account_name}.wasm', 'rb').read() m = hashlib.sha256() m.update(code) code_hash = m.hexdigest() r = eosapi.get_code(account_name) if code_hash != r['code_hash']: r = eosapi.set_contract(account_name, code, abi, 0) return True
def publish_cpp_contract_from_file(account_name, file_name, includes = [], entry='apply'): code = compile_cpp_file(file_name, includes, entry=entry) assert code m = hashlib.sha256() m.update(code) code_hash = m.hexdigest() r = eosapi.get_code(account_name) if code_hash != r['code_hash']: print('update contract') abi = open(f'{file_name}.abi', 'r').read() r = eosapi.set_contract(account_name, code, abi, 0) return True
# send_inline('hello', 'sayhello', b'hello,world', {'hello':'active'}) # play() ''' print(type(code)) abi = b''' { "version": "eosio::abi/1.0", "structs": [{ "name": "message", "base": "", "fields": [ {"name":"msg", "type":"string"} ] } ], "actions": [{ "name": "sayhello", "type": "raw" } ] } ''' r = hello._eosapi.pack_abi(abi) print(r) #import sys;sys.exit(0) eosapi.set_contract('hello', code, abi, 1) r = eosapi.push_action('hello', 'sayhello', b'hello,world', {'hello': 'active'}) print(r)