当前位置: 首页>>代码示例>>Python>>正文


Python utils.privtoaddr方法代码示例

本文整理汇总了Python中ethereum.utils.privtoaddr方法的典型用法代码示例。如果您正苦于以下问题:Python utils.privtoaddr方法的具体用法?Python utils.privtoaddr怎么用?Python utils.privtoaddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ethereum.utils的用法示例。


在下文中一共展示了utils.privtoaddr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: call_const_function

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [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: __init__

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def __init__(self,
                 contract_address,
                 contract_abi_string,
                 ethereum_chain_id,
                 http_provider,
                 websocket_provider,
                 gas_price_gwei,
                 gas_limit,
                 contract_owner_private_key):

        super(MintableERC20Processor, self).__init__(contract_address,
                                                     contract_abi_string,
                                                     ethereum_chain_id,
                                                     http_provider,
                                                     websocket_provider,
                                                     gas_price_gwei,
                                                     gas_limit)

        self.master_wallet_private_key = contract_owner_private_key
        self.master_wallet_address = Web3.toChecksumAddress(utils.privtoaddr(self.master_wallet_private_key)) 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:22,代码来源:ethereum_processor.py

示例3: deploy_safes

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def deploy_safes(number, owners, private_key):
    safes = []
    funding_public_key = checksum_encode(privtoaddr(private_key))
    funding_nonce = w3.eth.getTransactionCount(funding_public_key, 'pending')
    for _ in range(number):
        payload_json = generate_payload(owners)
        r = requests.post(SAFES_URL, json=payload_json)
        assert r.ok
        safe_created = r.json()
        safe_address = safe_created['safe']
        payment = int(safe_created['payment'])

        logging.info('Created safe=%s, need payment=%d', safe_address, payment)
        send_eth(private_key, safe_address, payment, funding_nonce)
        logging.info('Sent payment=%s to safe=%s', payment, safe_address)
        r = requests.put(get_safes_notify_url(safe_address))
        assert r.ok
        funding_nonce += 1
        safes.append(safe_address)

    with open('safes.txt', mode='a') as safes_file:
        safes_file.write('\n'.join(safes))


# notify_safes() 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:27,代码来源:create_multiple_safes.py

示例4: test_gas_for_migrate_all

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def test_gas_for_migrate_all(self):
        factory_key = urandom(32)
        addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
        self.state.mine(1)
        for i, k in enumerate(tester.keys):
            v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
            self.c.create(sender=k, value=v)
        self.state.mine(2)
        self.c.finalize()
        m_addr, _ = self.deploy_migration_contract(addr)
        t_addr, _ = self.deploy_target_contract(m_addr)
        self.c.setMigrationAgent(m_addr, sender=factory_key)
        self.m.setTargetToken(t_addr, sender=tester.k9)
        self.state.mine()
        self.state.block.coinbase = urandom(20)
        costs = []
        for i, k in enumerate(tester.keys):
            b = self.c.balanceOf(tester.accounts[i])
            m = self.monitor(i)
            self.c.migrate(b, sender=k)
            costs.append(m.gas())
        print(costs)
        assert max(costs) <= 99304
        assert min(costs) >= 56037 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:26,代码来源:test_gnt.py

示例5: test_gas_for_migrate_half

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def test_gas_for_migrate_half(self):
        factory_key = urandom(32)
        addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
        self.state.mine(1)
        for i, k in enumerate(tester.keys):
            v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
            self.c.create(sender=k, value=v)
        self.state.mine(2)
        self.c.finalize()
        m_addr, _ = self.deploy_migration_contract(addr)
        t_addr, _ = self.deploy_target_contract(m_addr)
        self.c.setMigrationAgent(m_addr, sender=factory_key)
        self.m.setTargetToken(t_addr, sender=tester.k9)
        self.state.mine()
        self.state.block.coinbase = urandom(20)
        costs = []
        for i, k in enumerate(tester.keys):
            b = self.c.balanceOf(tester.accounts[i])
            m = self.monitor(i)
            self.c.migrate(b / 2, sender=k)
            costs.append(m.gas())
        print(costs)
        assert max(costs) <= 114304
        assert min(costs) >= 71037 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:26,代码来源:test_gnt.py

示例6: test_gas_for_set_migration_agent_and_master

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def test_gas_for_set_migration_agent_and_master(self):
        factory_key = urandom(32)
        addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
        self.state.mine(1)
        for i, k in enumerate(tester.keys):
            v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
            self.c.create(sender=k, value=v)
        self.state.mine(2)
        self.c.finalize()
        m_addr, _ = self.deploy_migration_contract(addr)
        self.state.mine()

        lg = self.state.block.gas_used
        self.c.setMigrationAgent(m_addr, sender=factory_key)
        g = self.state.block.gas_used - lg
        assert g == 44169

        lg = self.state.block.gas_used
        self.c.setMigrationMaster(m_addr, sender=factory_key)
        g = self.state.block.gas_used - lg
        assert g == 28570 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:23,代码来源:test_gnt.py

示例7: make_transaction

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def make_transaction( src_priv_key, dst_address, value, data ):
    src_address = b2h( utils.privtoaddr(src_priv_key) )
    nonce = get_num_transactions( src_address )
    gas_price = get_gas_price_in_wei()
    data_as_string = b2h(data)
    start_gas = eval_startgas( src_address, dst_address, value, data_as_string, gas_price )
    
    nonce = int( nonce, 16 )
    gas_price = int( gas_price, 16 )
    start_gas = int( start_gas, 16 ) + 100000
    
    tx = transactions.Transaction( nonce,
                                   gas_price,
                                   start_gas,
                                   dst_address,
                                   value,
                                   data ).sign(src_priv_key)
    
    
                                   
    tx_hex  = b2h(rlp.encode(tx))
    tx_hash = b2h( tx.hash )
    if use_ether_scan:
        params = [{"hex" : "0x" + tx_hex }]
    else:
        params = ["0x" + tx_hex]
    return_value = json_call( "eth_sendRawTransaction", params )                       
    if return_value == "0x0000000000000000000000000000000000000000000000000000000000000000":
        print "Transaction failed"
        return False
    wait_for_confirmation(tx_hash)
    return return_value 
开发者ID:yaronvel,项目名称:smart_contracts,代码行数:34,代码来源:post_contract_ui.py

示例8: get_account_balance

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def get_account_balance( key ):
    url = "https://testnet.etherscan.io/api"
    payload = {"module" : "account",
               "action" : "balance",
               "tag" : "latest",
               "address" : "0x" + b2h( utils.privtoaddr(key) ), 
               "apikey" : ether_scan_api_key }
    response = requests.post( url, params=payload )
    balance = response.json()[ 'result' ]
    if balance is None:
        return 0
    return int(balance) 
开发者ID:yaronvel,项目名称:smart_contracts,代码行数:14,代码来源:post_contract_ui.py

示例9: construct_master_wallet_approval_tasks

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def construct_master_wallet_approval_tasks(self, account_to_approve_encoded_pk, credit_transfer_id):

        private_key = self.decode_private_key(account_to_approve_encoded_pk)

        address = Web3.toChecksumAddress(utils.privtoaddr(private_key))

        gas_required, gas_price = self.estimate_load_ether_gas_and_price()

        return [
            celery_tasks.load_ether.si(address, gas_required, gas_price),
            celery_tasks.create_transaction_response.s(credit_transfer_id),
            celery_tasks.approve_master_for_transfers.si(account_to_approve_encoded_pk, gas_required, gas_price),
            celery_tasks.create_transaction_response.s(credit_transfer_id)
        ] 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:16,代码来源:ethereum_processor.py

示例10: call_const_function

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [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

示例11: address

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def address(self):
        a = privtoaddr(self.privkey)
        assert len(a) == 20
        assert isinstance(a, bytes)
        return a 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:7,代码来源:accounts.py

示例12: __init__

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def __init__(self, private_key=None):
        self.private_key = private_key
        if private_key is None:
            self.private_key = SigningKey.generate(curve=SECP256k1).to_string().hex()
        self._raw_address = utils.privtoaddr(self.private_key)
        self.address = utils.checksum_encode(self._raw_address) 
开发者ID:Lamden,项目名称:clove,代码行数:8,代码来源:wallet.py

示例13: account_public_key

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def account_public_key(account_private_key):
    from ethereum.utils import privtoaddr
    from testrpc.client.utils import encode_address
    return encode_address(privtoaddr(account_private_key)) 
开发者ID:pipermerriam,项目名称:eth-testrpc,代码行数:6,代码来源:conftest.py

示例14: process_transaction

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def process_transaction(self,
                            signing_private_key,
                            credit_transfer_id=None,
                            unbuilt_transaction=None,
                            partial_txn_dict={},
                            transaction_type=None,
                            gas_limit_override=None,
                            gas_price_override=None):

        signing_address = Web3.toChecksumAddress(utils.privtoaddr(signing_private_key))

        network_nonce = self.w3.eth.getTransactionCount(signing_address, block_identifier='pending')

        nonce, transaction_id = self.claim_transaction_spot(signing_address, network_nonce)


        print('@@@@@@@@@@@@@@ using nonce @@@@@@@@@@@@@@: {}'.format(nonce))


        txn = {
            'chainId': self.ethereum_chain_id,
            'gas': gas_limit_override or self.gas_limit,
            'gasPrice': gas_price_override or self.get_gas_price(),
            'nonce': nonce
        }

        if unbuilt_transaction:
            txn = unbuilt_transaction.buildTransaction(txn)
        else:
            txn = {**txn, **partial_txn_dict}

        signed_txn = self.w3.eth.account.signTransaction(txn, private_key=signing_private_key)

        transaction_data = {
            'transaction_hash': signed_txn.hash.hex(),
            'transaction_nonce': nonce,
            'transaction_type': transaction_type,
            'signing_address': signing_address,
            'submitted_date': str(datetime.datetime.utcnow()),
            'credit_transfer_id': credit_transfer_id,
            'transaction_id': transaction_id
        }

        self.send_blockchain_result_to_app(transaction_data)

        try:
            result = self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)

        except ValueError as e:

            transaction_data['status'] = 'FAILED'
            transaction_data['message'] = str(e)

            raise PreBlockchainError(transaction_data)

        print('*****************transaction_data:*****************')
        print(transaction_data)

        return transaction_data 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:61,代码来源:ethereum_processor.py

示例15: make_transaction

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import privtoaddr [as 别名]
def make_transaction(src_priv_key, dst_address, value, data):
    # global global_nonce

    src_address = b2h(utils.privtoaddr(src_priv_key))
    nonce = get_num_transactions(src_address)
    gas_price = get_gas_price_in_wei()
    data_as_string = b2h(data)
    # print len(data_as_string)
    # if len(data) > 0:
    #    data_as_string = "0x" + data_as_string
    # start_gas = eval_startgas(src_address, dst_address, value,
    # data_as_string, gas_price)
    start_gas = "0xF4240"

    nonce = int(nonce, 16)
    # if(global_nonce < 0):
    # global_nonce = nonce

    # nonce = global_nonce
    # global_nonce += 1

    # print(nonce)

    gas_price = int(gas_price, 16)
    # int(gas_price, 16)/20
    start_gas = int(start_gas, 16) + 100000

    tx = transactions.Transaction(nonce,
                                  gas_price,
                                  start_gas,
                                  dst_address,
                                  value,
                                  data).sign(src_priv_key)

    tx_hex = b2h(rlp.encode(tx))
    tx_hash = b2h(tx.hash)

    params = ["0x" + tx_hex]
    return_value = json_call("eth_sendRawTransaction", params)
    if return_value == "0x0000000000000000000000000000000000000000000000000000000000000000":
        print("Transaction failed")
        return return_value

    return return_value 
开发者ID:KyberNetwork,项目名称:exchange-simulator,代码行数:46,代码来源:web3_interface.py


注:本文中的ethereum.utils.privtoaddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。