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.
as_address
(
res
,idx
)
(str) — Convert the stack item atidx
to a NEO3 address.as_bool
(
res
,idx
)
(bool) — Convert the stack item atidx
to abool
.as_bytes
(
res
,idx
)
(bytes) — Convert the stack item atidx
tobytes
.as_dict
(
res
,idx
)
(dict) — Convert the stack item atidx
to a dictionary.as_int
(
res
,idx
)
(int) — Convert the stack item atidx
to anint
.as_list
(
res
,idx
)
(list) — Convert the stack item atidx
to alist
.as_none
(
res
,idx
)
— Convert the stack item atidx
toNone
.as_public_key
(
res
,idx
)
(ECPoint) — Convert the stack item atidx
to a public key.as_str
(
res
,idx
)
(str) — Convert the stack item atidx
to astr
.as_uint160
(
res
,idx
)
(UInt160) — Convert the stack item atidx
to anUInt160
.as_uint256
(
res
,idx
)
(UInt256) — Convert the stack item atidx
to anUInt256
.check_state_ok
(
res
)
— Check if the execution of the transaction finished in a success state.item
(
res
,idx
)
(StackItem) — Fetch the stack item atidx
from the result stack. Performs basic validation and bounds checking.
neo3.api.helpers.unwrap.
as_address
(
res
, idx=0
)
→ str
Convert the stack item at idx
to a NEO3 address.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to a NEO3 address.
neo3.api.helpers.unwrap.
as_bool
(
res
, idx=0
)
→ bool
Convert the stack item at idx
to a bool
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to a bool.
neo3.api.helpers.unwrap.
as_bytes
(
res
, idx=0
)
→ bytes
Convert the stack item at idx
to bytes
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to bytes.
neo3.api.helpers.unwrap.
as_dict
(
res
, idx=0
)
→ dict
Convert the stack item at idx
to a dictionary.
res
(ExecutionResult) — execution result.idx
(int, optional) — idx: the index in the result stack to fetch the stack item from.
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.
neo3.api.helpers.unwrap.
as_int
(
res
, idx=0
)
→ int
Convert the stack item at idx
to an int
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to an int.
neo3.api.helpers.unwrap.
as_list
(
res
, idx=0
)
→ list
Convert the stack item at idx
to a list
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to a list.
neo3.api.helpers.unwrap.
as_none
(
res
, idx=0
)
Convert the stack item at idx
to None
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value is notNone
.
neo3.api.helpers.unwrap.
as_public_key
(
res
, idx=0
)
→ ECPoint
Convert the stack item at idx
to a public key.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
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.
neo3.api.helpers.unwrap.
as_str
(
res
, idx=0
)
→ str
Convert the stack item at idx
to a str
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to astr
.
neo3.api.helpers.unwrap.
as_uint160
(
res
, idx=0
)
→ UInt160
Convert the stack item at idx
to an UInt160
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to an UInt160.
neo3.api.helpers.unwrap.
as_uint256
(
res
, idx=0
)
→ UInt256
Convert the stack item at idx
to an UInt256
.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.
ValueError
— if the index is out of range, or the value cannot be converted to an UInt256.
neo3.api.helpers.unwrap.
check_state_ok
(
res
)
Check if the execution of the transaction finished in a success state.
ValueError
— if the VM state is not HALT.
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.
res
(ExecutionResult) — execution result.idx
(int, optional) — the index in the result stack to fetch the stack item from.