event_reader.conversion

Documentation for eth_defi.event_reader.conversion Python module.

Raw log event data conversion helpers.

Functions

convert_address_to_bytes32(address)

Convert address to bytes32 for passing raw ABI packed payload.

convert_bytes32_to_address(bytes32)

Convert raw uint256 from EncodedCall to address.

convert_bytes32_to_uint(bytes32)

Convert raw bytes32 blob to uint.

convert_int256_bytes_to_int(bytes32, *[, signed])

Convert raw bytes32 from log data to addresses ints.

convert_jsonrpc_value_to_int(val)

Convert hex string or int to int.

convert_solidity_bytes_to_string(byte_data, ...)

Load string from contract function call.

convert_string_to_bytes32(s)

Convert string to bytes32 for passing raw ABI packed payload.

convert_uin256_to_bytes(value)

Convert uint256 to bytes32.

convert_uint256_bytes_to_address(raw)

Convert raw uin256 from log data to addresses.

convert_uint256_hex_string_to_address(hex)

Convert raw uin256 from log data to address.

convert_uint256_string_to_address(bytes32)

Convert raw uint256 from log data to address.

convert_uint256_string_to_int(bytes32, *[, ...])

Convert raw uint256 from log data to int.

decode_data(data)

Split data of a log to uin256 results

Exceptions

BadAddressError

Cannot convert to address.

exception BadAddressError

Bases: Exception

Cannot convert to address.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

decode_data(data)

Split data of a log to uin256 results

Parameters

data (str) –

Return type

list[bytes]

convert_uin256_to_bytes(value)

Convert uint256 to bytes32.

Parameters

value (int) –

Return type

bytes

convert_uint256_bytes_to_address(raw)

Convert raw uin256 from log data to addresses.

Note

Ethereum address checksum might have a speed penalty for high speed operations.

Parameters

raw (bytes | hexbytes.main.HexBytes) – Raw uint256 byte blob

Returns

Checksummed Ethereum address

Raises

BadAddressError – If the returned data does not lot look like an address.

Return type

eth_typing.evm.ChecksumAddress

convert_uint256_hex_string_to_address(hex)

Convert raw uin256 from log data to address.

Parameters

hex (str) – Hex string byte blob

Returns

Checksummed Ethereum address

Return type

eth_typing.evm.ChecksumAddress

convert_int256_bytes_to_int(bytes32, *, signed=False)

Convert raw bytes32 from log data to addresses ints.

Parameters
  • signed (bool) – Default to unsigned uint256. Set true for int256.

  • bytes32 (bytes) –

Return type

int

convert_uint256_string_to_address(bytes32)

Convert raw uint256 from log data to address.

Note

Ethereum address checksum might have a speed penalty for high speed operations.

Parameters

bytes32 (str) – E.g. 0x00000000000000000000000006af07097c9eeb7fd685c692751d5c66db49c215

Return type

eth_typing.evm.ChecksumAddress

convert_bytes32_to_address(bytes32)

Convert raw uint256 from EncodedCall to address.

Note

Ethereum address checksum might have a speed penalty for high speed operations.

Parameters

bytes32 (bytes) – E.g. b`0x00000000000000000000000006af07097c9eeb7fd685c692751d5c66db49c215`

Return type

eth_typing.evm.ChecksumAddress

convert_bytes32_to_uint(bytes32)

Convert raw bytes32 blob to uint.

Parameters

bytes32 (bytes) – E.g. b`0x00000000000000000000000006af07097c9eeb7fd685c692751d5c66db49c215`

Return type

int

convert_uint256_string_to_int(bytes32, *, signed=False)

Convert raw uint256 from log data to int.

Parameters
  • bytes32 (str) – E.g. 0x00000000000000000000000006af07097c9eeb7fd685c692751d5c66db49c215

  • signed (bool) –

Return type

int

convert_jsonrpc_value_to_int(val)

Convert hex string or int to int.

Depending on the used JSON-RPC node, they may return hex encoded values or JSON numbers in JSON-RPC type. We need to be able to support both node and do the compatibility hack here.

Parameters

val (str | int) –

Return type

int

convert_solidity_bytes_to_string(byte_data, max_length, errors='ignore')

Load string from contract function call.

  • Decodes UTF-8, sanitise input and chops to max length

Returns

Empty string if the string cannot be decoded

Parameters
  • byte_data (bytes) –

  • max_length (int) –

Return type

str

convert_string_to_bytes32(s)

Convert string to bytes32 for passing raw ABI packed payload.

Parameters

s (str) – Input string

Returns

E.g. 0x746573740

Return type

bytes

convert_address_to_bytes32(address)

Convert address to bytes32 for passing raw ABI packed payload.

Returns

E.g. 0x00000000000000000000000006af07097c9eeb7fd685c692751d5c66db49c215

Parameters

address (Union[str, eth_typing.evm.HexAddress]) –

Return type

bytes