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


Python Web3.keccak方法代码示例

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


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

示例1: get_address_from_public_key

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def get_address_from_public_key(cls, public_key: str) -> str:
        """
        Get the address from the public key.

        :param public_key: the public key
        :return: str
        """
        keccak_hash = Web3.keccak(hexstr=public_key)
        raw_address = keccak_hash[-20:].hex().upper()
        address = Web3.toChecksumAddress(raw_address)
        return address 
开发者ID:fetchai,项目名称:agents-aea,代码行数:13,代码来源:ethereum.py

示例2: keccak

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def keccak():
    return Web3.keccak 
开发者ID:vyperlang,项目名称:vyper,代码行数:4,代码来源:conftest.py

示例3: generate_tx_nonce

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def generate_tx_nonce(self, seller: Address, client: Address) -> str:
        """
        Generate a unique hash to distinguish txs with the same terms.

        :param seller: the address of the seller.
        :param client: the address of the client.
        :return: return the hash in hex.
        """
        time_stamp = int(time.time())
        aggregate_hash = Web3.keccak(
            b"".join([seller.encode(), client.encode(), time_stamp.to_bytes(32, "big")])
        )
        return aggregate_hash.hex() 
开发者ID:fetchai,项目名称:agents-aea,代码行数:15,代码来源:ethereum.py

示例4: test_keccak_text

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_text(message, digest):
    assert Web3.keccak(text=message) == digest 
开发者ID:ethereum,项目名称:web3.py,代码行数:4,代码来源:test_keccak.py

示例5: test_keccak_hexstr

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_hexstr(hexstr, digest):
    assert Web3.keccak(hexstr=hexstr) == digest 
开发者ID:ethereum,项目名称:web3.py,代码行数:4,代码来源:test_keccak.py

示例6: test_keccak_primitive_invalid

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_primitive_invalid(primitive, exception):
    with pytest.raises(exception):
        Web3.keccak(primitive) 
开发者ID:ethereum,项目名称:web3.py,代码行数:5,代码来源:test_keccak.py

示例7: test_keccak_primitive

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_primitive(primitive, digest):
    assert Web3.keccak(primitive) == digest 
开发者ID:ethereum,项目名称:web3.py,代码行数:4,代码来源:test_keccak.py

示例8: test_keccak_raise_if_primitive_and

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_raise_if_primitive_and(kwargs):
    # must not set more than one input
    with pytest.raises(TypeError):
        Web3.keccak('', **kwargs) 
开发者ID:ethereum,项目名称:web3.py,代码行数:6,代码来源:test_keccak.py

示例9: test_keccak_raise_if_no_args

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_keccak_raise_if_no_args():
    with pytest.raises(TypeError):
        Web3.keccak() 
开发者ID:ethereum,项目名称:web3.py,代码行数:5,代码来源:test_keccak.py

示例10: test_deprecated_bound_method

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_deprecated_bound_method():
    w3 = Web3()
    h = HexBytes('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8')
    with pytest.warns(DeprecationWarning, match='sha3 is deprecated in favor of keccak'):
        assert w3.sha3(text='cowmö') == h 
开发者ID:ethereum,项目名称:web3.py,代码行数:7,代码来源:test_keccak.py

示例11: eth_sign_hash_message

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def eth_sign_hash_message(encoded_message: bytes) -> bytes:
    signature_prefix = "\x19Ethereum Signed Message:\n"
    return Web3.keccak(
        Web3.toBytes(text=signature_prefix)
        + Web3.toBytes(text=str(len(encoded_message)))
        + encoded_message
    ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:9,代码来源:proofs.py

示例12: test_updateReward

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def test_updateReward(
    monitoring_service_internals: Contract,
    ms_address: HexAddress,
    token_network: Contract,
    monitor_data_internal: Dict,
) -> None:
    A, B = monitor_data_internal["participants"]
    reward_identifier = Web3.keccak(
        encode_single("uint256", monitor_data_internal["channel_identifier"])
        + Web3.toBytes(hexstr=token_network.address)
    )

    def update_with_nonce(nonce: int) -> None:
        call_and_transact(
            monitoring_service_internals.functions.updateRewardPublic(
                token_network.address,
                A,
                B,
                REWARD_AMOUNT,
                nonce,
                ms_address,
                monitor_data_internal["non_closing_signature"],
                monitor_data_internal["reward_proof_signature"],
            ),
            {"from": ms_address},
        )

    # normal first call succeeds
    update_with_nonce(2)
    assert monitoring_service_internals.functions.rewardNonce(reward_identifier).call() == 2

    # calling again with same nonce fails
    with pytest.raises(TransactionFailed, match="stale nonce"):
        update_with_nonce(2)

    # calling again with higher nonce succeeds
    update_with_nonce(3)
    assert monitoring_service_internals.functions.rewardNonce(reward_identifier).call() == 3 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:40,代码来源:test_monitoring_service.py

示例13: _get_hash

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import keccak [as 别名]
def _get_hash(
    tx_sender_addr: Address,
    tx_counterparty_addr: Address,
    good_ids: List[int],
    sender_supplied_quantities: List[int],
    counterparty_supplied_quantities: List[int],
    tx_amount: int,
    tx_nonce: int,
) -> bytes:
    """
    Generate a hash from transaction information.

    :param tx_sender_addr: the sender address
    :param tx_counterparty_addr: the counterparty address
    :param good_ids: the list of good ids
    :param sender_supplied_quantities: the quantities supplied by the sender (must all be positive)
    :param counterparty_supplied_quantities: the quantities supplied by the counterparty (must all be positive)
    :param tx_amount: the amount of the transaction
    :param tx_nonce: the nonce of the transaction
    :return: the hash
    """
    aggregate_hash = Web3.keccak(
        b"".join(
            [
                good_ids[0].to_bytes(32, "big"),
                sender_supplied_quantities[0].to_bytes(32, "big"),
                counterparty_supplied_quantities[0].to_bytes(32, "big"),
            ]
        )
    )
    for idx, good_id in enumerate(good_ids):
        if not idx == 0:
            aggregate_hash = Web3.keccak(
                b"".join(
                    [
                        aggregate_hash,
                        good_id.to_bytes(32, "big"),
                        sender_supplied_quantities[idx].to_bytes(32, "big"),
                        counterparty_supplied_quantities[idx].to_bytes(32, "big"),
                    ]
                )
            )

    m_list = []  # type: List[bytes]
    m_list.append(tx_sender_addr.encode("utf-8"))
    m_list.append(tx_counterparty_addr.encode("utf-8"))
    m_list.append(aggregate_hash)
    m_list.append(tx_amount.to_bytes(32, "big"))
    m_list.append(tx_nonce.to_bytes(32, "big"))
    return Web3.keccak(b"".join(m_list)) 
开发者ID:fetchai,项目名称:agents-aea,代码行数:52,代码来源:helpers.py


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