ethereum.forks.amsterdam.utils.hexadecimal

Utility Functions For Hexadecimal Strings.

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

Introduction

Hexadecimal utility functions used in this specification, specific to Amsterdam 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:
22
    """
23
    Convert hex string to trie root.
24
25
    Parameters
26
    ----------
27
    hex_string :
28
        The hexadecimal string to be converted to trie root.
29
30
    Returns
31
    -------
32
    root : `Root`
33
        Trie root obtained from the given hexadecimal string.
34
35
    """
36
    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:
40
    """
41
    Convert hex string to Address (20 bytes).
42
43
    Parameters
44
    ----------
45
    hex_string :
46
        The hexadecimal string to be converted to Address.
47
48
    Returns
49
    -------
50
    address : `Address`
51
        The address obtained from the given hexadecimal string.
52
53
    """
54
    return Address(Bytes.fromhex(remove_hex_prefix(hex_string).rjust(40, "0")))