ethereum.muir_glacier.utils.hexadecimalethereum.berlin.utils.hexadecimal

Utility Functions For Hexadecimal Strings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Introduction

Hexadecimal utility functions used in this specification, specific to Muir Glacier types.Berlin 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:
21
    """
22
    Convert hex string to trie root.
23
24
    Parameters
25
    ----------
26
    hex_string :
27
        The hexadecimal string to be converted to trie root.
28
29
    Returns
30
    -------
31
    root : `Root`
32
        Trie root obtained from the given hexadecimal string.
33
    """
34
    return Root(bytes.fromhex(remove_hex_prefix(hex_string)))

hex_to_bloom

Convert hex string to bloom.

Parameters

hex_string : The hexadecimal string to be converted to bloom.

Returns

bloom : Bloom Bloom obtained from the given hexadecimal string.

def hex_to_bloom(hex_string: str) -> Bloom:
38
    """
39
    Convert hex string to bloom.
40
41
    Parameters
42
    ----------
43
    hex_string :
44
        The hexadecimal string to be converted to bloom.
45
46
    Returns
47
    -------
48
    bloom : `Bloom`
49
        Bloom obtained from the given hexadecimal string.
50
    """
51
    return Bloom(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:
55
    """
56
    Convert hex string to Address (20 bytes).
57
58
    Parameters
59
    ----------
60
    hex_string :
61
        The hexadecimal string to be converted to Address.
62
63
    Returns
64
    -------
65
    address : `Address`
66
        The address obtained from the given hexadecimal string.
67
    """
68
    return Address(bytes.fromhex(remove_hex_prefix(hex_string).rjust(40, "0")))