本文整理汇总了Python中ethereum.abi.ContractTranslator方法的典型用法代码示例。如果您正苦于以下问题:Python abi.ContractTranslator方法的具体用法?Python abi.ContractTranslator怎么用?Python abi.ContractTranslator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.abi
的用法示例。
在下文中一共展示了abi.ContractTranslator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_const_function
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def call_const_function( priv_key, value, contract_hash, contract_abi, function_name, args ):
src_address = b2h( utils.privtoaddr(priv_key) )
translator = ContractTranslator(contract_abi)
call = translator.encode_function_call(function_name, args)
nonce = get_num_transactions( src_address )
gas_price = get_gas_price_in_wei()
start_gas = eval_startgas( src_address, contract_hash, value, b2h(call), gas_price )
nonce = int( nonce, 16 )
gas_price = int( gas_price, 16 )
start_gas = int( start_gas, 16 ) + 100000
params = { "from" : "0x" + src_address,
"to" : "0x" + contract_hash,
"gas" : "0x" + str(start_gas),
"gasPrice" : "0x" + str(gas_price),
"value" : str(value),
"data" : "0x" + b2h(call) }
return_value = json_call( "eth_call", [params])
return_value = h2b(return_value[2:]) # remove 0x
return translator.decode(function_name, return_value)
示例2: methods
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def methods(name, contract_abi, sought=None, args=None):
translator = abi.ContractTranslator(contract_abi)
args = args or []
printed = False
if not isinstance(args, (list, tuple)):
args = [args]
for fn in translator.function_data:
if not sought or fn.lower() == sought.lower():
if not printed:
print "\n----", name, "----\n"
printed = True
try:
encoded = translator.encode_function_call(fn, args).encode('hex')
print FMT.format(fn, encoded)
except Exception:
print FMT.format(fn, "INVALID ARGUMENTS")
示例3: call_function
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def call_function( priv_key, value, contract_hash, contract_abi, function_name, args ):
translator = ContractTranslator(contract_abi)
call = translator.encode_function_call(function_name, args)
return make_transaction(priv_key, contract_hash, value, call)
示例4: call_function
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def call_function(priv_key, value, contract_hash, contract_abi, function_name, args):
translator = ContractTranslator(json.loads(contract_abi))
call = translator.encode_function_call(function_name, args)
return make_transaction(priv_key, contract_hash, value, call)
示例5: call_const_function
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def call_const_function(priv_key, value, contract_hash, contract_abi, function_name, args):
# src_address = b2h(utils.privtoaddr(priv_key))
translator = ContractTranslator(json.loads(contract_abi))
call = translator.encode_function_call(function_name, args)
# nonce = get_num_transactions(src_address)
# gas_price = get_gas_price_in_wei()
# start_gas = eval_startgas(
# src_address, contract_hash, value, b2h(call), gas_price)
# nonce = int(nonce, 16)
# gas_price = int(gas_price, 16)
# start_gas = int(start_gas, 16) + 100000
# start_gas = 7612288
params = {
# "from": "0x" + src_address,
"to": "0x" + contract_hash,
# "gas": "0x" + "%x" % start_gas,
# "gasPrice": "0x" + "%x" % gas_price,
# "value": "0x" + str(value),
"data": "0x" + b2h(call)
}
return_value = json_call("eth_call", [params, "latest"])
# print return_value
return_value = h2b(return_value[2:]) # remove 0x
return translator.decode_function_result(function_name, return_value)
#
示例6: deploy_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def deploy_contract(self, founder, start, end,
creator_idx=9, migration_master=None):
if migration_master is None:
migration_master = founder
owner = self.monitor(creator_idx)
t = abi.ContractTranslator(GNT_ABI)
args = t.encode_constructor_arguments((founder, migration_master,
self.starting_block + start,
self.starting_block + end))
addr = self.state.evm(GNT_INIT + args,
sender=owner.key)
self.c = tester.ABIContract(self.state, GNT_ABI, addr)
return addr, owner.gas()
示例7: deploy_wallet
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def deploy_wallet(self, _founder, creator_idx=9):
assert not hasattr(self, 'c')
owner = self.monitor(creator_idx)
t = abi.ContractTranslator(WALLET_ABI)
args = t.encode_constructor_arguments([])
addr = self.state.evm(WALLET_INIT + args,
sender=owner.key)
self.wallet = tester.ABIContract(self.state, WALLET_ABI, addr)
return addr, owner.gas()
示例8: deploy_migration_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def deploy_migration_contract(self, source_contract, creator_idx=9):
owner = self.monitor(creator_idx)
t = abi.ContractTranslator(MIGRATION_ABI)
args = t.encode_constructor_arguments([source_contract])
addr = self.state.evm(MIGRATION_INIT + args,
sender=owner.key)
self.m = tester.ABIContract(self.state, MIGRATION_ABI, addr)
return addr, owner.gas()
示例9: deploy_target_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def deploy_target_contract(self, migration_contract, creator_idx=9):
owner = self.monitor(creator_idx)
t = abi.ContractTranslator(TARGET_ABI)
args = t.encode_constructor_arguments([migration_contract])
addr = self.state.evm(TARGET_INIT + args,
sender=owner.key)
self.t = tester.ABIContract(self.state, TARGET_ABI, addr)
return addr, owner.gas()
示例10: __deploy_wallet
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def __deploy_wallet(self, owner_key, owners, required=1, daylimit=WALLET_DAY_LIMIT):
t = abi.ContractTranslator(WALLET_ABI)
args = t.encode_constructor_arguments((owners, required, daylimit))
addr = self.state.evm(WALLET_INIT + args,
sender=owner_key)
return tester.ABIContract(self.state, WALLET_ABI, addr)
示例11: __deploy_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def __deploy_contract(self, _bin, _abi, creator_idx, *args):
gas_before = self.state.block.gas_used
t = abi.ContractTranslator(_abi)
args = t.encode_constructor_arguments(args)
addr = self.state.evm(_bin + args,
sender=tester.keys[creator_idx])
contract = tester.ABIContract(self.state, _abi, addr)
return contract, addr, self.state.block.gas_used - gas_before
示例12: deploy_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def deploy_contract(self, start, end, creator_idx=9, migration_master=None, founder=None):
if founder is None:
founder = tester.accounts[creator_idx]
if migration_master is None:
migration_master = founder
t = abi.ContractTranslator(GNT_ABI)
args = t.encode_constructor_arguments((founder, migration_master,
self.state.block.number + start,
self.state.block.number + end))
addr = self.state.evm(GNT_INIT + args,
sender=tester.keys[creator_idx])
return tester.ABIContract(self.state, GNT_ABI, addr), t
示例13: __deploy_wallet
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def __deploy_wallet(self, owner_key, owners, required=1):
t = abi.ContractTranslator(WALLET_ABI)
args = t.encode_constructor_arguments((owners, required))
addr = self.state.evm(WALLET_INIT + args,
sender=owner_key)
return tester.ABIContract(self.state, WALLET_ABI, addr), t
示例14: create_abi
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def create_abi(path):
path, extra_args = get_dirs(path)
abi = _solidity.compile_last_contract(path, combined='abi', extra_args=extra_args)['abi']
return ContractTranslator(abi)
示例15: get_contract
# 需要导入模块: from ethereum import abi [as 别名]
# 或者: from ethereum.abi import ContractTranslator [as 别名]
def get_contract(t, u):
def create_contract(path, args=(), sender=t.k0):
abi, hexcode = deployer.get_contract_data(path)
bytecode = u.decode_hex(hexcode)
ct = ContractTranslator(abi)
code = bytecode + (ct.encode_constructor_arguments(args) if args else b'')
address = t.chain.tx(sender=sender, to=b'', startgas=(4 * 10 ** 6 + 5 * 10 ** 5), value=0, data=code)
return t.ABIContract(t.chain, abi, address)
return create_contract