本文整理匯總了Python中eth_utils.decode_hex方法的典型用法代碼示例。如果您正苦於以下問題:Python eth_utils.decode_hex方法的具體用法?Python eth_utils.decode_hex怎麽用?Python eth_utils.decode_hex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類eth_utils
的用法示例。
在下文中一共展示了eth_utils.decode_hex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute_valid_ssz_test
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def execute_valid_ssz_test(test_case, sedes):
value = from_formatted_dict(test_case["value"], sedes, CustomCodec)
serial = decode_hex(test_case["ssz"])
try:
decoded = ssz.decode(serial, sedes)
except SSZException:
raise FailedTestCase("Deserializing valid SSZ failed")
else:
if decoded != value:
raise FailedTestCase(f"Deserializing SSZ returned wrong result {decoded}")
try:
encoded = ssz.encode(value, sedes)
except SSZException:
raise FailedTestCase("Serializing valid value failed")
else:
if encoded != serial:
raise FailedTestCase(f"Serializing value retunred wrong result {encoded}")
示例2: execute_invalid_ssz_test
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def execute_invalid_ssz_test(test_case, sedes):
if "value" in test_case and "ssz" in test_case:
raise ValueError("Test case for invalid inputs contains both value and ssz")
if "value" in test_case:
value = from_formatted_dict(test_case["value"], sedes, CustomCodec)
try:
ssz.encode(value, sedes)
except SSZException:
pass
else:
raise FailedTestCase("Serializing invalid value did not yield an exception")
elif "ssz" in test_case:
serial = decode_hex(test_case["ssz"])
try:
ssz.decode(serial, sedes)
except SSZException:
pass
else:
raise FailedTestCase("Deserializing invalid SSZ did not yield an exception")
else:
raise ValueError("Test case for invalid inputs contains neither value nor ssz")
示例3: test_mr_with_unknown_signatures
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_mr_with_unknown_signatures(context: Context):
""" The signatures are valid but don't belong to the participants.
"""
context = setup_state_with_closed_channel(context)
def assert_mr_is_ignored(mr):
context.database.upsert_monitor_request(mr)
event = ActionMonitoringTriggeredEvent(
token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
non_closing_participant=DEFAULT_PARTICIPANT2,
)
action_monitoring_triggered_event_handler(event, context)
assert not context.monitoring_service_contract.functions.monitor.called
assert_mr_is_ignored(
create_signed_monitor_request(closing_privkey=PrivateKey(decode_hex(get_random_privkey())))
)
assert_mr_is_ignored(
create_signed_monitor_request(
nonclosing_privkey=PrivateKey(decode_hex(get_random_privkey()))
)
)
示例4: churn_storage_once
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def churn_storage_once(chain, contract_addr, nonce):
# invoke function shuffle the storage, with a width of 64
# shuffle(uint256)
func_id = decode_hex("0xef6537b5")
# width is how many different storage slots to fill before wrapping
width = b'\x40'
# join call with parameters and pad:
method_invocation = func_id + width.rjust(32, b'\0')
tx = chain.create_unsigned_transaction(
nonce=nonce,
gas_price=1234,
gas=300000,
to=contract_addr,
value=0,
data=method_invocation,
)
_, _, computation = chain.apply_transaction(tx.as_signed_transaction(FUNDED_ACCT))
computation.raise_if_error()
示例5: _delete_storage_twice
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def _delete_storage_twice(chain, contract_addr, nonce):
# invoke function shuffle the storage, with a width of 64
# delete_twice(uint256)
func_id = decode_hex("0x622ff59a")
# width is how many different storage slots might be deletable
width = b'\x40'
# join call with parameters and pad:
method_invocation = func_id + width.rjust(32, b'\0')
tx = chain.create_unsigned_transaction(
nonce=nonce,
gas_price=1235,
gas=123458,
to=contract_addr,
value=0,
data=method_invocation,
)
_, _, computation = chain.apply_transaction(tx.as_signed_transaction(FUNDED_ACCT))
computation.raise_if_error()
示例6: test_beam_syncer_with_checkpoint
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_beam_syncer_with_checkpoint(
request,
event_loop,
event_bus,
chaindb_fresh,
chaindb_churner):
checkpoint = Checkpoint(
block_hash=decode_hex('0x5b8d32e4aebda3da7bdf2f0588cb42256e2ed0c268efec71b38278df8488a263'),
score=55,
)
await test_beam_syncer_loads_recent_state_root(
request,
event_loop,
event_bus,
chaindb_fresh,
chaindb_churner,
beam_to_block=66,
checkpoint=checkpoint,
)
示例7: _decoder
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def _decoder(
# NOTE: mypy incorrectly thinks `Field` is a generic type
data: Dict[str, EncodedConfigTypes],
fields: Collection[Field], # type: ignore
) -> Iterable[Tuple[str, ConfigTypes]]:
# NOTE: this code is unwieldly but it satisfies `mypy`
for field in fields:
if field.type is Gwei:
yield field.name, Gwei(cast(int, data[field.name]))
elif field.type is Slot:
yield field.name, Slot(cast(int, data[field.name]))
elif field.type is Epoch:
yield field.name, Epoch(cast(int, data[field.name]))
elif field.type is Second:
yield field.name, Second(cast(int, data[field.name]))
elif field.type is bytes:
yield field.name, decode_hex(cast(str, data[field.name]))
else:
yield field.name, int(data[field.name])
示例8: create_keypair_and_mock_withdraw_credentials
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def create_keypair_and_mock_withdraw_credentials(
config: Eth2Config, key_set: Sequence[Dict[str, Any]]
) -> Tuple[Tuple[BLSPubkey, ...], Tuple[int, ...], Tuple[Hash32, ...]]:
"""
NOTE: this function mixes the parsing of keying material with the generation of derived values.
Prefer other functions in this module that do the derivation directly.
"""
pubkeys: Tuple[BLSPubkey, ...] = ()
privkeys: Tuple[int, ...] = ()
withdrawal_credentials: Tuple[Hash32, ...] = ()
for key_pair in key_set:
pubkey = BLSPubkey(decode_hex(key_pair["pubkey"]))
privkey = int.from_bytes(decode_hex(key_pair["privkey"]), "big")
withdrawal_credential = Hash32(
config.BLS_WITHDRAWAL_PREFIX + hash_eth2(pubkey)[1:]
)
pubkeys += (pubkey,)
privkeys += (privkey,)
withdrawal_credentials += (withdrawal_credential,)
return (pubkeys, privkeys, withdrawal_credentials)
示例9: encode_int
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def encode_int(s):
a = "%x" % s
return b"" if s == 0 else decode_hex("0" * (len(a) % 2) + a)[::-1]
示例10: from_uri
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def from_uri(cls, uri: str) -> "Node":
parsed = urlparse.urlparse(uri)
pubkey = keys.PublicKey(decode_hex(parsed.username))
return cls(pubkey, Address(parsed.hostname, parsed.port))
示例11: test_v5_handlers
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_v5_handlers(monkeypatch):
# Ensure we dispatch v5 messages to the appropriate handlers.
# These are hex-encoded messages sent by geth over the wire, obtained via wireshark using the
# ethereum dissectors (https://github.com/ConsenSys/ethereum-dissectors).
qkc_hex = "qkc1 topic discovery".encode().hex()
v5_handlers = dict(
recv_topic_register=qkc_hex
+ "4b1f9f999e3cf283e42270742eb3b52b1c0b63ede116ea58632517ffccc7516c794f6fc20f199b3a3a887f3e961b453bb9213eebad4581aaf9b2a60da7e5ba7b0106e2da954c455332406434653536373430663837366165663883666f6f8204d283666f6f", # noqa: E501
recv_pong_v5=qkc_hex
+ "6cb538da9382c022cc6d9b860b7cc7660718c731e1e6331de86a7cabfba8f01c061b5d6c09dd84de1d6c653536bb8ad31fb140d55d317dfaea5225a6907f49450102f855cb84a5a587f2827660827660a0b484b40a3712766dbbe8498f110bab968a543f9d0d57ec4cfa3b38b32ef2f237831f5ca3a0bd1ea218eaf7cddc6b068a414ae08876315f92bd134e214d5f3961d1a3e8e35b4ec13c", # noqa: E501
recv_ping_v5=qkc_hex
+ "c26911f1d2a320f17fa683397028e6cc7ebe114623e28e933d870634aa6050f45960679170192ec0f133dbc3f4e627eef468dbdb48bf4a7848412938da21be8a0001f84104d79000000000000000000000000000000000827660827660cb84b0201d9282848b82848b845b7e5593d6954c4553324064346535363734306638373661656638", # noqa: E501
recv_find_nodehash=qkc_hex
+ "58dc895847c5d2cc9ab6f722f25b9ff1b9c188af6ff7ed7c716a3cde2e93f3ec1e2b897acb1a33aa1d345c72ea34912287b21480c80ef99241d4bd9fd53711ee0105e6a038f7bb96e94bcd39866baa56038367ad6145de1ee8f4a8b0993ebdf8883a0ad8845b7e5593", # noqa: E501
recv_topic_query=qkc_hex
+ "308621f1ed59a67613da52da3f84bac3d927d0dc1650b27552b10a0a823fb2133cebf3680f68bf88457bb0c07787031357430985d03afa1af0574e8ef0eab7fc0007d7954c455332406434653536373430663837366165663880", # noqa: E501
recv_topic_nodes=qkc_hex
+ "e33166b59d20f206f0df2502be59186cb971c76ee91dba94ea9b1bbeb1308a5f4efbdf945ead9ba89d7c2c55d5d841dacdef69a455c98e1a5415e489508afa450008f87ea0cff0456ecbf2e6b0a40bc6541bd209c60ced192509470b405c256a17443674b3f85bf8599000000000000000000000ffff904c1f9c82765f82765fb840e7d624c642b86d3d48cea3e395305345c3a0226fc4c2dfdfbeb94cb6891e5e72b4467c69684ac14b072d2e4fa9c7a731cc1fdf0283abe41186d00b4c879f80ed", # noqa: E501
recv_neighbours_v5=qkc_hex
+ "8f6671ae9611c82c9cb04538aeed13a8b4e8eb8ad0d0dbba4b161ded52b195846c6086a0d42eef44cfcc0b793a0b9420613727958a8956139c127810b94d4e830004f90174f9016cf8599000000000000000000000ffff59401a22826597826597b840d723e264da67820fb0cedb0d03d5d975cc82bffdadd2879f3e5fa58b5525de5fdd0b90002bba44ac9232247dfbccb2a730e5ea98201bab1f1fe72422aa58143ff8599000000000000000000000ffffae6c601a82765f82765fb840779f19056e0a0486c3f6838896a931bf920cd8f551f664022a50690d4cca4730b50a97058aac11a5aa0cc55db6f9207e12a9cd389269f414a98e5b6a2f6c9f89f8599000000000000000000000ffff287603df827663827663b84085c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaff8599000000000000000000000ffff0d4231b0820419820419b8407b46cc366b6cbaec088a7d15688a2c12bb8ba4cf7ee8e01b22ab534829f9ff13f7cc4130f10a4021f7d77e9b9c80a9777f5ddc035efb130fe3b6786434367973845b7e5569", # noqa: E501
)
proto = get_discovery_protocol()
addr = random_address()
for handler, msg in v5_handlers.items():
mock_handler = MockHandler()
monkeypatch.setattr(proto, handler, mock_handler)
proto.datagram_received(decode_hex(msg), (addr.ip, addr.udp_port))
assert mock_handler.called
示例12: test_decrypt_known_good_handshake
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_decrypt_known_good_handshake():
# Data taken from https://gist.github.com/fjl/3a78780d17c755d22df2
privkey = keys.PrivateKey(
decode_hex("c45f950382d542169ea207959ee0220ec1491755abe405cd7498d6b16adb6df8")
)
auth_ciphertext = decode_hex(
"04a0274c5951e32132e7f088c9bdfdc76c9d91f0dc6078e848f8e3361193dbdc43b94351ea3d89e4ff33ddcefbc80070498824857f499656c4f79bbd97b6c51a514251d69fd1785ef8764bd1d262a883f780964cce6a14ff206daf1206aa073a2d35ce2697ebf3514225bef186631b2fd2316a4b7bcdefec8d75a1025ba2c5404a34e7795e1dd4bc01c6113ece07b0df13b69d3ba654a36e35e69ff9d482d88d2f0228e7d96fe11dccbb465a1831c7d4ad3a026924b182fc2bdfe016a6944312021da5cc459713b13b86a686cf34d6fe6615020e4acf26bf0d5b7579ba813e7723eb95b3cef9942f01a58bd61baee7c9bdd438956b426a4ffe238e61746a8c93d5e10680617c82e48d706ac4953f5e1c4c4f7d013c87d34a06626f498f34576dc017fdd3d581e83cfd26cf125b6d2bda1f1d56"
) # noqa: E501
auth_plaintext = decode_hex(
"884c36f7ae6b406637c1f61b2f57e1d2cab813d24c6559aaf843c3f48962f32f46662c066d39669b7b2e3ba14781477417600e7728399278b1b5d801a519aa570034fdb5419558137e0d44cd13d319afe5629eeccb47fd9dfe55cc6089426e46cc762dd8a0636e07a54b31169eba0c7a20a1ac1ef68596f1f283b5c676bae4064abfcce24799d09f67e392632d3ffdc12e3d6430dcb0ea19c318343ffa7aae74d4cd26fecb93657d1cd9e9eaf4f8be720b56dd1d39f190c4e1c6b7ec66f077bb1100"
) # noqa: E501
decrypted = ecies.decrypt(auth_ciphertext, privkey)
assert auth_plaintext == decrypted
示例13: test_ecdh
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_ecdh(privkey_hex, pubkey_hex, ecdh_expected):
privkey = keys.PrivateKey(decode_hex(privkey_hex))
pubkey = keys.PublicKey(decode_hex(pubkey_hex))
assert ecdh_expected == encode_hex(ecies.ecdh_agree(privkey, pubkey))
# FIXME: Document those values; this test was lifted from pydevp2p:
# https://github.com/ethereum/pydevp2p/blob/e1ef07a782b9369d18a8441c3b9bcf12456e0608/devp2p/tests/test_ecies.py#L31
示例14: test_kdf
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_kdf():
input_ = decode_hex(
"0x961c065873443014e0371f1ed656c586c6730bf927415757f389d92acf8268df"
)
expected_key = decode_hex(
"0x4050c52e6d9c08755e5a818ac66fabe478b825b1836fd5efc4d44e40d04dabcc"
)
key = ecies.kdf(input_)
assert key == expected_key
示例15: test_eip8_hello
# 需要導入模塊: import eth_utils [as 別名]
# 或者: from eth_utils import decode_hex [as 別名]
def test_eip8_hello():
# Data taken from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8.md
payload = decode_hex(
"f87137916b6e6574682f76302e39312f706c616e39cdc5836574683dc6846d6f726b1682270fb840"
"fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569"
"bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877c883666f6f836261720304"
)
Hello(cmd_id_offset=0).decode_payload(payload)