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


Python eth_abi.encode_single方法代码示例

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


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

示例1: find_transaction_details_in_redeem_event

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def find_transaction_details_in_redeem_event(self, recipient_address: str, secret_hash: str, block_number: int):
        # web3.gastracker.io node does not support filtering
        # etc-geth.0xinfra.com not is not stable so it is used only for filtering
        filterable_web3 = Web3(HTTPProvider('https://etc-geth.0xinfra.com/'))

        event_signature_hash = self.web3.sha3(text="RedeemSwap(address,bytes20,bytes32)").hex()
        filter_options = {
            'fromBlock': block_number,
            'address': self.contract_address,
            'topics': [
                event_signature_hash,
                '0x' + encode_single('address', recipient_address).hex(),
                '0x' + encode_single('bytes20', bytes.fromhex(secret_hash)).hex()
            ]
        }

        event_filter = filterable_web3.eth.filter(filter_options)

        for _ in range(ETH_FILTER_MAX_ATTEMPTS):
            events = event_filter.get_all_entries()
            if events:
                return {
                    'secret': events[0]['data'][2:],
                    'transaction_hash': events[0]['transactionHash'].hex()
                } 
开发者ID:Lamden,项目名称:clove,代码行数:27,代码来源:ethereum_classic.py

示例2: pack_balance_proof

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def pack_balance_proof(
    token_network_address: HexAddress,
    chain_identifier: ChainID,
    channel_identifier: ChannelID,
    balance_hash: BalanceHash,
    nonce: Nonce,
    additional_hash: AdditionalHash,
    msg_type: MessageTypeId,
) -> bytes:
    return (
        Web3.toBytes(hexstr=token_network_address)
        + encode_single("uint256", chain_identifier)
        + encode_single("uint256", msg_type)
        + encode_single("uint256", channel_identifier)
        + balance_hash
        + encode_single("uint256", nonce)
        + additional_hash
    ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:20,代码来源:proofs.py

示例3: pack_cooperative_settle_message

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def pack_cooperative_settle_message(
    token_network_address: HexAddress,
    chain_identifier: ChainID,
    channel_identifier: ChannelID,
    participant1_address: HexAddress,
    participant1_balance: TokenAmount,
    participant2_address: HexAddress,
    participant2_balance: TokenAmount,
) -> bytes:
    return (
        Web3.toBytes(hexstr=token_network_address)
        + encode_single("uint256", chain_identifier)
        + encode_single("uint256", MessageTypeId.COOPERATIVE_SETTLE)
        + encode_single("uint256", channel_identifier)
        + Web3.toBytes(hexstr=participant1_address)
        + encode_single("uint256", participant1_balance)
        + Web3.toBytes(hexstr=participant2_address)
        + encode_single("uint256", participant2_balance)
    ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:21,代码来源:proofs.py

示例4: pack_withdraw_message

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def pack_withdraw_message(
    token_network_address: HexAddress,
    chain_identifier: ChainID,
    channel_identifier: ChannelID,
    participant: HexAddress,
    amount_to_withdraw: TokenAmount,
    expiration_block: BlockExpiration,
) -> bytes:
    return (
        Web3.toBytes(hexstr=token_network_address)
        + encode_single("uint256", chain_identifier)
        + encode_single("uint256", MessageTypeId.WITHDRAW)
        + encode_single("uint256", channel_identifier)
        + Web3.toBytes(hexstr=participant)
        + encode_single("uint256", amount_to_withdraw)
        + encode_single("uint256", expiration_block)
    ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:19,代码来源:proofs.py

示例5: pack_reward_proof

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def pack_reward_proof(
    monitoring_service_contract_address: HexAddress,
    chain_id: ChainID,
    token_network_address: HexAddress,
    non_closing_participant: HexAddress,
    non_closing_signature: Signature,
    reward_amount: TokenAmount,
) -> bytes:
    return (
        Web3.toBytes(hexstr=monitoring_service_contract_address)
        + encode_single("uint256", chain_id)
        + encode_single("uint256", MessageTypeId.MSReward)
        + Web3.toBytes(hexstr=token_network_address)
        + Web3.toBytes(hexstr=non_closing_participant)
        + non_closing_signature
        + encode_single("uint256", reward_amount)
    ) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:19,代码来源:proofs.py

示例6: sign_one_to_n_iou

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def sign_one_to_n_iou(
    privatekey: PrivateKey,
    sender: HexAddress,
    receiver: HexAddress,
    amount: TokenAmount,
    expiration_block: BlockExpiration,
    one_to_n_address: HexAddress,
    chain_id: ChainID,
    v: int = 27,
) -> bytes:
    iou_hash = eth_sign_hash_message(
        Web3.toBytes(hexstr=one_to_n_address)
        + encode_single("uint256", chain_id)
        + encode_single("uint256", MessageTypeId.IOU)
        + Web3.toBytes(hexstr=sender)
        + Web3.toBytes(hexstr=receiver)
        + encode_single("uint256", amount)
        + encode_single("uint256", expiration_block)
    )
    return sign(privkey=privatekey, msg_hash=iou_hash, v=v) 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:22,代码来源:proofs.py

示例7: test_hashed_indexed_topics_calldata

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def test_hashed_indexed_topics_calldata(tester, keccak, get_contract):
    loggy_code = """
event MyLog:
    arg1: indexed(Bytes[36])
    arg2: indexed(int128[2])
    arg3: indexed(String[7])

@external
def foo(a: Bytes[36], b: int128[2], c: String[7]):
    log MyLog(a, b, c)
    """

    c = get_contract(loggy_code)
    tx_hash = c.foo(b"bar", [1, 2], "weird", transact={})
    receipt = tester.get_transaction_receipt(tx_hash.hex())

    # Event id is always the first topic
    event_id = keccak(b"MyLog(bytes,int128[2],string)")
    assert receipt["logs"][0]["topics"][0] == event_id.hex()

    topic1 = f"0x{keccak256(b'bar').hex()}"
    assert receipt["logs"][0]["topics"][1] == topic1

    topic2 = f"0x{keccak256(eth_abi.encode_single('int128[2]', [1,2])).hex()}"
    assert receipt["logs"][0]["topics"][2] == topic2

    topic3 = f"0x{keccak256(b'weird').hex()}"
    assert receipt["logs"][0]["topics"][3] == topic3

    # Event abi is created correctly
    assert c._classic_contract.abi[0] == {
        "name": "MyLog",
        "inputs": [
            {"type": "bytes", "name": "arg1", "indexed": True},
            {"type": "int128[2]", "name": "arg2", "indexed": True},
            {"type": "string", "name": "arg3", "indexed": True},
        ],
        "anonymous": False,
        "type": "event",
    } 
开发者ID:vyperlang,项目名称:vyper,代码行数:42,代码来源:test_logging.py

示例8: test_hashed_indexed_topics_storxxage

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def test_hashed_indexed_topics_storxxage(tester, keccak, get_contract):
    loggy_code = """
event MyLog:
    arg1: indexed(Bytes[64])
    arg2: indexed(int128[3])
    arg3: indexed(String[21])

@external
def foo():
    log MyLog(b"wow", [6,66,666], "madness!")
    """

    c = get_contract(loggy_code)
    tx_hash = c.foo(transact={})
    receipt = tester.get_transaction_receipt(tx_hash.hex())

    # Event id is always the first topic
    event_id = keccak(b"MyLog(bytes,int128[3],string)")
    assert receipt["logs"][0]["topics"][0] == event_id.hex()

    topic1 = f"0x{keccak256(b'wow').hex()}"
    assert receipt["logs"][0]["topics"][1] == topic1

    topic2 = f"0x{keccak256(eth_abi.encode_single('int128[3]', [6, 66, 666])).hex()}"
    assert receipt["logs"][0]["topics"][2] == topic2

    topic3 = f"0x{keccak256(b'madness!').hex()}"
    assert receipt["logs"][0]["topics"][3] == topic3 
开发者ID:vyperlang,项目名称:vyper,代码行数:30,代码来源:test_logging.py

示例9: packed_data

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def packed_data(self) -> bytes:
        return (
            self.one_to_n_address
            + encode_single("uint256", self.chain_id)
            + encode_single("uint256", MessageTypeId.IOU)
            + self.sender
            + self.receiver
            + encode_single("uint256", self.amount)
            + encode_single("uint256", self.expiration_block)
        ) 
开发者ID:raiden-network,项目名称:raiden-services,代码行数:12,代码来源:iou.py

示例10: session_id

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def session_id(self) -> str:
        """Session ID as used for OneToN.settled_sessions"""
        return encode_hex(
            keccak(self.receiver + self.sender + encode_single("uint256", self.expiration_block))
        ) 
开发者ID:raiden-network,项目名称:raiden-services,代码行数:7,代码来源:iou.py

示例11: find_transaction_details_in_redeem_event

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def find_transaction_details_in_redeem_event(
        self,
        recipient_address: str,
        secret_hash: str,
        block_number: int,
    ) -> Optional[dict]:
        '''
        Searching for transaction details of redeem transaction in Atomic Swap contract events.

        Args:
            recipient_address (str): recipient address
            secret_hash (str): hash of the secret
            block_number (int): number of the block from which filtering should be started

        Returns:
            dict, None: dictionary with secret and transaction hash, None if no redeem transaction where found

        Raises:
            NotImplementedError: if the network doesn't support event filtering
        '''
        if not self.filtering_supported:
            raise NotImplementedError

        event_signature_hash = self.web3.sha3(text="RedeemSwap(address,bytes20,bytes32)").hex()
        filter_options = {
            'fromBlock': block_number,
            'address': self.contract_address,
            'topics': [
                event_signature_hash,
                '0x' + encode_single('address', recipient_address).hex(),
                '0x' + encode_single('bytes20', bytes.fromhex(secret_hash)).hex()
            ]
        }

        event_filter = self.web3.eth.filter(filter_options)

        for _ in range(ETH_FILTER_MAX_ATTEMPTS):
            events = event_filter.get_all_entries()
            if events:
                return {
                    'secret': events[0]['data'][2:],
                    'transaction_hash': events[0]['transactionHash'].hex()
                } 
开发者ID:Lamden,项目名称:clove,代码行数:45,代码来源:base.py

示例12: test_hashed_indexed_topics_memory

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def test_hashed_indexed_topics_memory(tester, keccak, get_contract):
    loggy_code = """
event MyLog:
    arg1: indexed(Bytes[10])
    arg2: indexed(int128[3])
    arg3: indexed(String[44])

@external
def foo():
    a: Bytes[10] = b"potato"
    b: int128[3] = [-777, 42, 8008135]
    c: String[44] = "why hello, neighbor! how are you today?"
    log MyLog(a, b, c)
    """

    c = get_contract(loggy_code)
    tx_hash = c.foo(transact={})
    receipt = tester.get_transaction_receipt(tx_hash.hex())

    # Event id is always the first topic
    event_id = keccak(b"MyLog(bytes,int128[3],string)")
    assert receipt["logs"][0]["topics"][0] == event_id.hex()

    topic1 = f"0x{keccak256(b'potato').hex()}"
    assert receipt["logs"][0]["topics"][1] == topic1

    topic2 = f"0x{keccak256(eth_abi.encode_single('int128[3]', [-777,42,8008135])).hex()}"
    assert receipt["logs"][0]["topics"][2] == topic2

    topic3 = f"0x{keccak256(b'why hello, neighbor! how are you today?').hex()}"
    assert receipt["logs"][0]["topics"][3] == topic3

    # Event abi is created correctly
    assert c._classic_contract.abi[0] == {
        "name": "MyLog",
        "inputs": [
            {"type": "bytes", "name": "arg1", "indexed": True},
            {"type": "int128[3]", "name": "arg2", "indexed": True},
            {"type": "string", "name": "arg3", "indexed": True},
        ],
        "anonymous": False,
        "type": "event",
    } 
开发者ID:vyperlang,项目名称:vyper,代码行数:45,代码来源:test_logging.py

示例13: test_hashed_indexed_topics_storage

# 需要导入模块: import eth_abi [as 别名]
# 或者: from eth_abi import encode_single [as 别名]
def test_hashed_indexed_topics_storage(tester, keccak, get_contract):
    loggy_code = """
event MyLog:
    arg1: indexed(Bytes[32])
    arg2: indexed(int128[2])
    arg3: indexed(String[6])

a: Bytes[32]
b: int128[2]
c: String[6]


@external
def setter(_a: Bytes[32], _b: int128[2], _c: String[6]):
    self.a = _a
    self.b = _b
    self.c = _c

@external
def foo():
    log MyLog(self.a, self.b, self.c)
    """

    c = get_contract(loggy_code)
    c.setter(b"zonk", [838, -2109], "yessir", transact={})
    tx_hash = c.foo(transact={})
    receipt = tester.get_transaction_receipt(tx_hash.hex())

    # Event id is always the first topic
    event_id = keccak(b"MyLog(bytes,int128[2],string)")
    assert receipt["logs"][0]["topics"][0] == event_id.hex()

    topic1 = f"0x{keccak256(b'zonk').hex()}"
    assert receipt["logs"][0]["topics"][1] == topic1

    topic2 = f"0x{keccak256(eth_abi.encode_single('int128[2]', [838,-2109])).hex()}"
    assert receipt["logs"][0]["topics"][2] == topic2

    topic3 = f"0x{keccak256(b'yessir').hex()}"
    assert receipt["logs"][0]["topics"][3] == topic3

    # Event abi is created correctly
    assert c._classic_contract.abi[0] == {
        "name": "MyLog",
        "inputs": [
            {"type": "bytes", "name": "arg1", "indexed": True},
            {"type": "int128[2]", "name": "arg2", "indexed": True},
            {"type": "string", "name": "arg3", "indexed": True},
        ],
        "anonymous": False,
        "type": "event",
    } 
开发者ID:vyperlang,项目名称:vyper,代码行数:54,代码来源:test_logging.py


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