• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python web3.Web3类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中web3.Web3的典型用法代码示例。如果您正苦于以下问题:Python Web3类的具体用法?Python Web3怎么用?Python Web3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_soliditySha3_ens

    def test_soliditySha3_ens(self, web3, types, values, expected):
        with ens_addresses(web3, {
            'one.eth': "0x49EdDD3769c0712032808D86597B84ac5c2F5614",
            'two.eth': "0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5",
        }):
            # when called as class method, any name lookup attempt will fail
            with pytest.raises(InvalidAddress):
                Web3.soliditySha3(types, values)

            # when called as instance method method, ens lookups can succeed
            actual = web3.soliditySha3(types, values)
            assert actual == expected
开发者ID:syngraph,项目名称:web3.py,代码行数:12,代码来源:web3_module.py


示例2: test_labelhash

def test_labelhash(ens, label, expected_hash):
    if isinstance(expected_hash, type):
        with pytest.raises(expected_hash):
            ens.labelhash(label)
    else:
        labelhash = ens.labelhash(label)
        assert isinstance(labelhash, bytes)
        hash_hex = Web3.toHex(labelhash)
        assert hash_hex == expected_hash
开发者ID:miohtama,项目名称:web3.py,代码行数:9,代码来源:test_get_registry.py


示例3: hash_balance_data

def hash_balance_data(
        transferred_amount: typing.TokenAmount,
        locked_amount: typing.TokenAmount,
        locksroot: typing.Locksroot,
) -> str:
    return Web3.soliditySha3(
        ['uint256', 'uint256', 'bytes32'],
        [transferred_amount, locked_amount, locksroot],
    )
开发者ID:AlphaX-IBS,项目名称:raiden,代码行数:9,代码来源:utils.py


示例4: bytes32

def bytes32(val):
    if isinstance(val, int):
        result = Web3.toBytes(val)
    else:
        raise TypeError('val %r could not be converted to bytes')
    if len(result) < 32:
        return result.rjust(32, b'\0')
    else:
        return result
开发者ID:pipermerriam,项目名称:web3.py,代码行数:9,代码来源:conftest.py


示例5: hash_balance_data

def hash_balance_data(
        transferred_amount: TokenAmount,
        locked_amount: TokenAmount,
        locksroot: Locksroot,
) -> bytes:
    assert locksroot != b''
    assert len(locksroot) == 32
    if transferred_amount == 0 and locked_amount == 0 and locksroot == EMPTY_HASH:
        return EMPTY_HASH

    return Web3.soliditySha3(  # pylint: disable=no-value-for-parameter
        ['uint256', 'uint256', 'bytes32'],
        [transferred_amount, locked_amount, locksroot],
    )
开发者ID:hackaugusto,项目名称:raiden,代码行数:14,代码来源:utils.py


示例6: test_eth_account_sign_transaction_from_eth_test

def test_eth_account_sign_transaction_from_eth_test(acct, transaction_info):
    expected_raw_txn = transaction_info['signed']
    key = transaction_info['key']

    transaction = dissoc(transaction_info, 'signed', 'key', 'unsigned')

    # validate r, in order to validate the transaction hash
    # There is some ambiguity about whether `r` will always be deterministically
    # generated from the transaction hash and private key, mostly due to code
    # author's ignorance. The example test fixtures and implementations seem to agree, so far.
    # See ecdsa_raw_sign() in /eth_keys/backends/native/ecdsa.py
    signed = acct.signTransaction(transaction, key)
    assert signed.r == Web3.toInt(hexstr=expected_raw_txn[-130:-66])

    # confirm that signed transaction can be recovered to the sender
    expected_sender = acct.privateKeyToAccount(key).address
    assert acct.recoverTransaction(signed.rawTransaction) == expected_sender
开发者ID:miohtama,项目名称:web3.py,代码行数:17,代码来源:test_accounts.py


示例7: test_set_address

def test_set_address(ens, name, full_name, namehash_hex):
    assert ens.address(name) is None
    owner = ens.owner('tester')

    ens.setup_address(name, TEST_ADDRESS)
    assert ens.address(name) == TEST_ADDRESS

    # check that .eth is only appended if guess_tld is True
    namehash = Web3.toBytes(hexstr=namehash_hex)
    normal_name = ens.nameprep(full_name)
    if ens.nameprep(name) == normal_name:
        assert ens.address(name, guess_tld=False) == TEST_ADDRESS
    else:
        assert ens.address(name, guess_tld=False) is None

    # check that the correct namehash is set:
    assert ens.resolver(normal_name).addr(namehash) == TEST_ADDRESS

    # check that the correct owner is set:
    assert ens.owner(name) == owner

    ens.setup_address(name, None)
    assert ens.address(name) is None
开发者ID:syngraph,项目名称:web3.py,代码行数:23,代码来源:test_setup_address.py


示例8: test_setup_name

def test_setup_name(ens, name, normalized_name, namehash_hex):
    address = ens.web3.eth.accounts[3]
    assert not ens.name(address)
    owner = ens.owner('tester')

    ens.setup_name(name, address)
    assert ens.name(address) == normalized_name

    # check that .eth is only appended if guess_tld is True
    if ens.nameprep(name) != normalized_name:
        assert ens.address(name, guess_tld=False) is None

    # check that the correct namehash is set:
    node = Web3.toBytes(hexstr=namehash_hex)
    assert ens.resolver(normalized_name).addr(node) == address

    # check that the correct owner is set:
    assert ens.owner(name) == owner

    ens.setup_name(None, address)
    ens.setup_address(name, None)
    assert not ens.name(address)
    assert not ens.address(name)
开发者ID:syngraph,项目名称:web3.py,代码行数:23,代码来源:test_setup_name.py


示例9: check_gas_reserve

def check_gas_reserve(raiden):
    """ Check periodically for gas reserve in the account """
    while True:
        has_enough_balance, estimated_required_balance = gas_reserve.has_enough_gas_reserve(
            raiden,
            channels_to_open=0,
        )
        estimated_required_balance_eth = Web3.fromWei(estimated_required_balance, 'ether')

        if not has_enough_balance:
            log.info('Missing gas reserve', required_wei=estimated_required_balance)
            click.secho(
                (
                    'WARNING\n'
                    "Your account's balance is below the estimated gas reserve of "
                    f'{estimated_required_balance_eth} eth. This may lead to a loss of '
                    'of funds because your account will be unable to perform on-chain '
                    'transactions. Please add funds to your account as soon as possible.'
                ),
                fg='red',
            )

        gevent.sleep(CHECK_GAS_RESERVE_INTERVAL)
开发者ID:hackaugusto,项目名称:raiden,代码行数:23,代码来源:tasks.py


示例10: getBalance

 def getBalance(self):
     wei_balance = self.web3.eth.getBalance(self.address)
     ether_balance = Web3.fromWei(wei_balance, unit='ether')
     return ether_balance
开发者ID:nud3l,项目名称:agent-local,代码行数:4,代码来源:ContractHandler.py


示例11: test_to_text_hexstr

def test_to_text_hexstr(val, expected):
    assert Web3.toText(hexstr=val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例12: test_to_text

def test_to_text(val, expected):
    assert Web3.toText(val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例13: test_to_text_identity

def test_to_text_identity():
    assert Web3.toText(text='pass-through') == 'pass-through'
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例14: test_sha3_primitive_invalid

def test_sha3_primitive_invalid(primitive, exception):
    with pytest.raises(exception):
        Web3.sha3(primitive)
开发者ID:syngraph,项目名称:web3.py,代码行数:3,代码来源:test_sha3.py


示例15: test_sha3_primitive

def test_sha3_primitive(primitive, digest):
    assert Web3.sha3(primitive) == digest
开发者ID:syngraph,项目名称:web3.py,代码行数:2,代码来源:test_sha3.py


示例16: test_sha3_raise_if_hexstr_and_text

def test_sha3_raise_if_hexstr_and_text():
    with pytest.raises(TypeError):
        Web3.sha3(hexstr='0x', text='')
开发者ID:syngraph,项目名称:web3.py,代码行数:3,代码来源:test_sha3.py


示例17: test_to_hex_text

def test_to_hex_text(val, expected):
    assert Web3.toHex(text=val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例18: test_to_hex

def test_to_hex(val, expected):
    assert Web3.toHex(val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例19: test_to_int_hexstr

def test_to_int_hexstr(val, expected):
    assert Web3.toInt(hexstr=val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:2,代码来源:test_conversions.py


示例20: test_to_int_text

def test_to_int_text(val, expected):
    if isinstance(expected, type):
        with pytest.raises(expected):
            Web3.toInt(text=val)
    else:
        assert Web3.toInt(text=val) == expected
开发者ID:miohtama,项目名称:web3.py,代码行数:6,代码来源:test_conversions.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python contract.Contract类代码示例发布时间:2022-05-26
下一篇:
Python tests.ApprovedEventFactory类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap