當前位置: 首頁>>代碼示例>>Python>>正文


Python abi.ContractTranslator方法代碼示例

本文整理匯總了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) 
開發者ID:yaronvel,項目名稱:smart_contracts,代碼行數:24,代碼來源:post_contract_ui.py

示例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") 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:22,代碼來源:encode_function_call.py

示例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) 
開發者ID:yaronvel,項目名稱:smart_contracts,代碼行數:6,代碼來源:post_contract_ui.py

示例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) 
開發者ID:KyberNetwork,項目名稱:exchange-simulator,代碼行數:6,代碼來源:web3_interface.py

示例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)

# 
開發者ID:KyberNetwork,項目名稱:exchange-simulator,代碼行數:31,代碼來源:web3_interface.py

示例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() 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:15,代碼來源:test_gnt.py

示例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() 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:12,代碼來源:test_gnt.py

示例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() 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:10,代碼來源:test_gnt.py

示例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() 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:10,代碼來源:test_gnt.py

示例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) 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:8,代碼來源:test_allowance_wallet.py

示例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 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:12,代碼來源:test_proxy.py

示例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 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:15,代碼來源:test_wallet.py

示例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 
開發者ID:golemfactory,項目名稱:golem-crowdfunding,代碼行數:8,代碼來源:test_wallet.py

示例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) 
開發者ID:omgnetwork,項目名稱:plasma-mvp,代碼行數:6,代碼來源:conftest.py

示例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 
開發者ID:omgnetwork,項目名稱:plasma-mvp,代碼行數:11,代碼來源:conftest.py


注:本文中的ethereum.abi.ContractTranslator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。