Utility Functions For Hexadecimal Strings

Introduction

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

Module Contents

Functions

hex_to_root

Convert hex string to trie root.

hex_to_bloom

Convert hex string to bloom.

hex_to_address

Convert hex string to Address (20 bytes).

Module Details

hex_to_root

hex_to_root(hex_string: str)ethereum.istanbul.fork_types.Root

Convert hex string to trie root.

Parameters

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

Returns

root – Trie root obtained from the given hexadecimal string.

Return type

Root

def hex_to_root(hex_string: str) -> Root:
    return Root(bytes.fromhex(remove_hex_prefix(hex_string)))

hex_to_bloom

hex_to_bloom(hex_string: str)ethereum.istanbul.fork_types.Bloom

Convert hex string to bloom.

Parameters

hex_string – The hexadecimal string to be converted to bloom.

Returns

bloom – Bloom obtained from the given hexadecimal string.

Return type

Bloom

def hex_to_bloom(hex_string: str) -> Bloom:
    return Bloom(bytes.fromhex(remove_hex_prefix(hex_string)))

hex_to_address

hex_to_address(hex_string: str)ethereum.istanbul.fork_types.Address

Convert hex string to Address (20 bytes).

Parameters

hex_string – The hexadecimal string to be converted to Address.

Returns

address – The address obtained from the given hexadecimal string.

Return type

Address

def hex_to_address(hex_string: str) -> Address:
    return Address(bytes.fromhex(remove_hex_prefix(hex_string).rjust(40, "0")))