Skip to content
module

neo3.api.helpers.unwrap

Helper functions to easily fetch native values from the ResultStack returned as response by various RPC methodssuch as invoke_function(), invoke_script(), get_application_log_transaction() and get_application_log_block().

Includes sanity checking.

Functions
  • as_address(res, idx) (str) Convert the stack item at idx to a NEO3 address.
  • as_bool(res, idx) (bool) Convert the stack item at idx to a bool.
  • as_bytes(res, idx) (bytes) Convert the stack item at idx to bytes.
  • as_dict(res, idx) (dict) Convert the stack item at idx to a dictionary.
  • as_int(res, idx) (int) Convert the stack item at idx to an int.
  • as_list(res, idx) (list) Convert the stack item at idx to a list.
  • as_none(res, idx) Convert the stack item at idx to None.
  • as_public_key(res, idx) (ECPoint) Convert the stack item at idx to a public key.
  • as_str(res, idx) (str) Convert the stack item at idx to a str.
  • as_uint160(res, idx) (UInt160) Convert the stack item at idx to an UInt160.
  • as_uint256(res, idx) (UInt256) Convert the stack item at idx to an UInt256.
  • check_state_ok(res) Check if the execution of the transaction finished in a success state.
  • item(res, idx) (StackItem) Fetch the stack item at idx from the result stack. Performs basic validation and bounds checking.
function

neo3.api.helpers.unwrap.as_address(res, idx=0) → str

Convert the stack item at idx to a NEO3 address.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to a NEO3 address.
function

neo3.api.helpers.unwrap.as_bool(res, idx=0) → bool

Convert the stack item at idx to a bool.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to a bool.
function

neo3.api.helpers.unwrap.as_bytes(res, idx=0) → bytes

Convert the stack item at idx to bytes.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to bytes.
function

neo3.api.helpers.unwrap.as_dict(res, idx=0) → dict

Convert the stack item at idx to a dictionary.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) idx: the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to a dict.

Warning

Accepted key types on the Virtual Machine side are int, str and bytes. However, when data is returned there is no way to differentiate between the key being of type str or bytes as the RPC node will encode both as a ByteString. The dictionary returned will return such types as bytes and it is the user responsibility to decode them to a str if needed.

function

neo3.api.helpers.unwrap.as_int(res, idx=0) → int

Convert the stack item at idx to an int.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to an int.
function

neo3.api.helpers.unwrap.as_list(res, idx=0) → list

Convert the stack item at idx to a list.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to a list.
function

neo3.api.helpers.unwrap.as_none(res, idx=0)

Convert the stack item at idx to None.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value is not None.
function

neo3.api.helpers.unwrap.as_public_key(res, idx=0) → ECPoint

Convert the stack item at idx to a public key.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ECCException if the resulting key is not valid on the SECP256R1 curve.
  • ValueError if the index is out of range, or the value cannot be converted to a bool.
function

neo3.api.helpers.unwrap.as_str(res, idx=0) → str

Convert the stack item at idx to a str.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to a str.
function

neo3.api.helpers.unwrap.as_uint160(res, idx=0) → UInt160

Convert the stack item at idx to an UInt160.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to an UInt160.
function

neo3.api.helpers.unwrap.as_uint256(res, idx=0) → UInt256

Convert the stack item at idx to an UInt256.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.
Raises
  • ValueError if the index is out of range, or the value cannot be converted to an UInt256.
function

neo3.api.helpers.unwrap.check_state_ok(res)

Check if the execution of the transaction finished in a success state.

Raises
  • ValueError if the VM state is not HALT.
function

neo3.api.helpers.unwrap.item(res, idx=0) → StackItem

Fetch the stack item at idx from the result stack. Performs basic validation and bounds checking.

Parameters
  • res (ExecutionResult) execution result.
  • idx (int, optional) the index in the result stack to fetch the stack item from.