ethereum.forks.cancun.utils.hexadecimalethereum.forks.prague.utils.hexadecimal

Utility Functions For Hexadecimal Strings.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Hexadecimal utility functions used in this specification, specific to Cancun types.Prague types.

hex_to_root

Convert hex string to trie root.

Parameters

hex_string : The hexadecimal string to be converted to trie root.

Returns

root : Root Trie root obtained from the given hexadecimal string.

def hex_to_root(hex_string: str) -> Root:
23
    """
24
    Convert hex string to trie root.
25
26
    Parameters
27
    ----------
28
    hex_string :
29
        The hexadecimal string to be converted to trie root.
30
31
    Returns
32
    -------
33
    root : `Root`
34
        Trie root obtained from the given hexadecimal string.
35
36
    """
37
    return Root(Bytes.fromhex(remove_hex_prefix(hex_string)))

hex_to_address

Convert hex string to Address (20 bytes).

Parameters

hex_string : The hexadecimal string to be converted to Address.

Returns

address : Address The address obtained from the given hexadecimal string.

def hex_to_address(hex_string: str) -> Address:
41
    """
42
    Convert hex string to Address (20 bytes).
43
44
    Parameters
45
    ----------
46
    hex_string :
47
        The hexadecimal string to be converted to Address.
48
49
    Returns
50
    -------
51
    address : `Address`
52
        The address obtained from the given hexadecimal string.
53
54
    """
55
    return Address(Bytes.fromhex(remove_hex_prefix(hex_string).rjust(40, "0")))