ethereum.spurious_dragon.utils.hexadecimal
Utility Functions For Hexadecimal Strings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Hexadecimal utility functions used in this specification, specific to Spurious Dragon types.
1""" 2Utility Functions For Hexadecimal Strings 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12Hexadecimal utility functions used in this specification, specific to 13Spurious Dragon types. 14""" 15from ethereum.utils.hexadecimal import remove_hex_prefix 16 17from ..fork_types import Address, Bloom, Root 18 19 20def 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))) 35 36 37def 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))) 52 53 54def 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")))
21def 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 return Root(bytes.fromhex(remove_hex_prefix(hex_string)))
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.
38def hex_to_bloom(hex_string: str) -> Bloom: 39 """ 40 Convert hex string to bloom. 41 42 Parameters 43 ---------- 44 hex_string : 45 The hexadecimal string to be converted to bloom. 46 47 Returns 48 ------- 49 bloom : `Bloom` 50 Bloom obtained from the given hexadecimal string. 51 """ 52 return Bloom(bytes.fromhex(remove_hex_prefix(hex_string)))
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.
55def hex_to_address(hex_string: str) -> Address: 56 """ 57 Convert hex string to Address (20 bytes). 58 59 Parameters 60 ---------- 61 hex_string : 62 The hexadecimal string to be converted to Address. 63 64 Returns 65 ------- 66 address : `Address` 67 The address obtained from the given hexadecimal string. 68 """ 69 return Address(bytes.fromhex(remove_hex_prefix(hex_string).rjust(40, "0")))
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.