Trait soroban_env_guest::Env
source · [−]pub trait Env: EnvBase {
Show 95 methods
fn log_value(&self, v: RawVal) -> RawVal;
fn get_invoking_contract(&self) -> Object;
fn obj_cmp(&self, a: RawVal, b: RawVal) -> i64;
fn contract_event(&self, v: RawVal) -> RawVal;
fn system_event(&self, v: RawVal) -> RawVal;
fn get_current_contract(&self) -> Object;
fn obj_from_u64(&self, v: u64) -> Object;
fn obj_to_u64(&self, obj: Object) -> u64;
fn obj_from_i64(&self, v: i64) -> Object;
fn obj_to_i64(&self, obj: Object) -> i64;
fn map_new(&self) -> Object;
fn map_put(&self, m: Object, k: RawVal, v: RawVal) -> Object;
fn map_get(&self, m: Object, k: RawVal) -> RawVal;
fn map_del(&self, m: Object, k: RawVal) -> Object;
fn map_len(&self, m: Object) -> RawVal;
fn map_has(&self, m: Object, k: RawVal) -> RawVal;
fn map_prev_key(&self, m: Object, k: RawVal) -> RawVal;
fn map_next_key(&self, m: Object, k: RawVal) -> RawVal;
fn map_min_key(&self, m: Object) -> RawVal;
fn map_max_key(&self, m: Object) -> RawVal;
fn map_keys(&self, m: Object) -> Object;
fn map_values(&self, m: Object) -> Object;
fn vec_new(&self, c: RawVal) -> Object;
fn vec_put(&self, v: Object, i: RawVal, x: RawVal) -> Object;
fn vec_get(&self, v: Object, i: RawVal) -> RawVal;
fn vec_del(&self, v: Object, i: RawVal) -> Object;
fn vec_len(&self, v: Object) -> RawVal;
fn vec_push(&self, v: Object, x: RawVal) -> Object;
fn vec_pop(&self, v: Object) -> Object;
fn vec_front(&self, v: Object) -> RawVal;
fn vec_back(&self, v: Object) -> RawVal;
fn vec_insert(&self, v: Object, i: RawVal, x: RawVal) -> Object;
fn vec_append(&self, v1: Object, v2: Object) -> Object;
fn vec_slice(&self, v: Object, start: RawVal, end: RawVal) -> Object;
fn put_contract_data(&self, k: RawVal, v: RawVal) -> RawVal;
fn has_contract_data(&self, k: RawVal) -> RawVal;
fn get_contract_data(&self, k: RawVal) -> RawVal;
fn del_contract_data(&self, k: RawVal) -> RawVal;
fn create_contract_from_ed25519(
&self,
v: Object,
salt: Object,
key: Object,
sig: Object
) -> Object;
fn create_contract_from_contract(&self, v: Object, salt: Object) -> Object;
fn call(&self, contract: Object, func: Symbol, args: Object) -> RawVal;
fn try_call(&self, contract: Object, func: Symbol, args: Object) -> RawVal;
fn bigint_from_u64(&self, x: u64) -> Object;
fn bigint_to_u64(&self, x: Object) -> u64;
fn bigint_from_i64(&self, x: i64) -> Object;
fn bigint_to_i64(&self, x: Object) -> i64;
fn bigint_add(&self, x: Object, y: Object) -> Object;
fn bigint_sub(&self, x: Object, y: Object) -> Object;
fn bigint_mul(&self, x: Object, y: Object) -> Object;
fn bigint_div(&self, x: Object, y: Object) -> Object;
fn bigint_rem(&self, x: Object, y: Object) -> Object;
fn bigint_and(&self, x: Object, y: Object) -> Object;
fn bigint_or(&self, x: Object, y: Object) -> Object;
fn bigint_xor(&self, x: Object, y: Object) -> Object;
fn bigint_shl(&self, x: Object, y: Object) -> Object;
fn bigint_shr(&self, x: Object, y: Object) -> Object;
fn bigint_cmp(&self, x: Object, y: Object) -> RawVal;
fn bigint_is_zero(&self, x: Object) -> RawVal;
fn bigint_neg(&self, x: Object) -> Object;
fn bigint_not(&self, x: Object) -> Object;
fn bigint_gcd(&self, x: Object, y: Object) -> Object;
fn bigint_lcm(&self, x: Object, y: Object) -> Object;
fn bigint_pow(&self, x: Object, y: Object) -> Object;
fn bigint_pow_mod(&self, p: Object, q: Object, m: Object) -> Object;
fn bigint_sqrt(&self, x: Object) -> Object;
fn bigint_bits(&self, x: Object) -> u64;
fn bigint_to_bytes_be(&self, x: Object) -> Object;
fn bigint_to_radix_be(&self, x: Object, radix: RawVal) -> Object;
fn serialize_to_binary(&self, v: RawVal) -> Object;
fn deserialize_from_binary(&self, b: Object) -> RawVal;
fn binary_copy_to_linear_memory(
&self,
b: Object,
b_pos: RawVal,
lm_pos: RawVal,
len: RawVal
) -> RawVal;
fn binary_copy_from_linear_memory(
&self,
b: Object,
b_pos: RawVal,
lm_pos: RawVal,
len: RawVal
) -> Object;
fn binary_new_from_linear_memory(&self, lm_pos: RawVal, len: RawVal) -> Object;
fn binary_new(&self) -> Object;
fn binary_put(&self, b: Object, i: RawVal, u: RawVal) -> Object;
fn binary_get(&self, b: Object, i: RawVal) -> RawVal;
fn binary_del(&self, b: Object, i: RawVal) -> Object;
fn binary_len(&self, b: Object) -> RawVal;
fn binary_push(&self, b: Object, u: RawVal) -> Object;
fn binary_pop(&self, b: Object) -> Object;
fn binary_front(&self, b: Object) -> RawVal;
fn binary_back(&self, b: Object) -> RawVal;
fn binary_insert(&self, b: Object, i: RawVal, u: RawVal) -> Object;
fn binary_append(&self, b1: Object, b2: Object) -> Object;
fn binary_slice(&self, b: Object, start: RawVal, end: RawVal) -> Object;
fn hash_from_binary(&self, x: Object) -> Object;
fn hash_to_binary(&self, x: Object) -> Object;
fn public_key_from_binary(&self, x: Object) -> Object;
fn public_key_to_binary(&self, x: Object) -> Object;
fn compute_hash_sha256(&self, x: Object) -> Object;
fn verify_sig_ed25519(&self, x: Object, k: Object, s: Object) -> RawVal;
fn account_get_low_threshold(&self, a: Object) -> RawVal;
fn account_get_medium_threshold(&self, a: Object) -> RawVal;
fn account_get_high_threshold(&self, a: Object) -> RawVal;
fn account_get_signer_weight(&self, a: Object, s: Object) -> RawVal;
}
Expand description
This trait represents the interface between Host and Guest, used by client contract code and implemented (via CheckedEnv) by the host. It consists of functions that take or return only 64-bit values such as RawVal or u64.
Required Methods
fn get_invoking_contract(&self) -> Object
fn get_invoking_contract(&self) -> Object
Get the binary contractID of the contract which invoked the running contract. Traps if the running contract was not invoked by a contract.
fn contract_event(&self, v: RawVal) -> RawVal
fn system_event(&self, v: RawVal) -> RawVal
fn get_current_contract(&self) -> Object
fn get_current_contract(&self) -> Object
Get the binary contractID of the contract which invoked the running contract. Traps if the running contract was not invoked by a contract.
fn obj_from_u64(&self, v: u64) -> Object
fn obj_to_u64(&self, obj: Object) -> u64
fn obj_from_i64(&self, v: i64) -> Object
fn obj_from_i64(&self, v: i64) -> Object
Convert an i64 to an object containing an i64.
fn obj_to_i64(&self, obj: Object) -> i64
fn obj_to_i64(&self, obj: Object) -> i64
Convert an object containing an i64 to an i64.
Insert a key/value mapping into an existing map, and return the map object handle. If the map already has a mapping for the given key, the previous value is overwritten.
Get the value for a key from a map. Traps if key is not found.
Remove a key/value mapping from a map if it exists, traps if doesn’t.
Test for the presence of a key in a map. Returns (SCStatic) TRUE/FALSE.
fn map_prev_key(&self, m: Object, k: RawVal) -> RawVal
fn map_prev_key(&self, m: Object, k: RawVal) -> RawVal
Given a key, find the first key less than itself in the map’s sorted order. If such a key does not exist, return an SCStatus containing the error code (TBD).
fn map_next_key(&self, m: Object, k: RawVal) -> RawVal
fn map_next_key(&self, m: Object, k: RawVal) -> RawVal
Given a key, find the first key greater than itself in the map’s sorted order. If such a key does not exist, return an SCStatus containing the error code (TBD).
fn map_min_key(&self, m: Object) -> RawVal
fn map_min_key(&self, m: Object) -> RawVal
Find the minimum key from a map. If the map is empty, return an SCStatus containing the error code (TBD).
fn map_max_key(&self, m: Object) -> RawVal
fn map_max_key(&self, m: Object) -> RawVal
Find the maximum key from a map. If the map is empty, return an SCStatus containing the error code (TBD).
Return a new vector containing all the keys in a map. The new vector is ordered in the original map’s key-sorted order.
fn map_values(&self, m: Object) -> Object
fn map_values(&self, m: Object) -> Object
Return a new vector containing all the values in a map. The new vector is ordered in the original map’s key-sorted order.
Creates a new vector with an optional capacity hint c
.
If c
is ScStatic::Void
, no hint is assumed and the new vector is empty.
Otherwise, c
is parsed as an u32
that represents the initial capacity of the new vector.
Update the value at index i
in the vector. Return the new vector.
Trap if the index is out of bounds.
Returns the element at index i
of the vector. Traps if the index is out of bound.
Delete an element in a vector at index i
, shifting all elements after it to the left.
Return the new vector. Traps if the index is out of bound.
Appends an element to the back of the vector.
Removes the last element from the vector and returns the new vector. Traps if original vector is empty.
Return the first element in the vector. Traps if the vector is empty
Return the last element in the vector. Traps if the vector is empty
Inserts an element at index i
within the vector, shifting all elements after it to the right.
Traps if the index is out of bound
fn vec_append(&self, v1: Object, v2: Object) -> Object
fn vec_append(&self, v1: Object, v2: Object) -> Object
Clone the vector v1
, then moves all the elements of vector v2
into it.
Return the new vector. Traps if number of elements in the vector overflows a u32.
Copy the elements from start
index until end
index, exclusive, in the vector and create a new vector from it.
Return the new vector. Traps if the index is out of bound.
fn put_contract_data(&self, k: RawVal, v: RawVal) -> RawVal
fn has_contract_data(&self, k: RawVal) -> RawVal
fn get_contract_data(&self, k: RawVal) -> RawVal
fn del_contract_data(&self, k: RawVal) -> RawVal
fn create_contract_from_ed25519(
&self,
v: Object,
salt: Object,
key: Object,
sig: Object
) -> Object
fn create_contract_from_contract(&self, v: Object, salt: Object) -> Object
Calls a function in another contract with arguments contained in vector args
.
If the call is successful, forwards the result of the called function. Traps otherwise.
Calls a function in another contract with arguments contained in vector args
. Returns:
- if successful, result of the called function.
- otherwise, an
SCStatus
containing the error status code.
fn bigint_from_u64(&self, x: u64) -> Object
fn bigint_from_u64(&self, x: u64) -> Object
Constructs a BigInt from an u64.
fn bigint_to_u64(&self, x: Object) -> u64
fn bigint_to_u64(&self, x: Object) -> u64
Converts a BigInt to an u64. Traps if the value cannot fit into u64.
fn bigint_from_i64(&self, x: i64) -> Object
fn bigint_from_i64(&self, x: i64) -> Object
Constructs a BigInt from an i64.
fn bigint_to_i64(&self, x: Object) -> i64
fn bigint_to_i64(&self, x: Object) -> i64
Converts a BigInt to an i64. Traps if the value cannot fit into i64.
fn bigint_add(&self, x: Object, y: Object) -> Object
fn bigint_add(&self, x: Object, y: Object) -> Object
Performs the +
operation.
fn bigint_sub(&self, x: Object, y: Object) -> Object
fn bigint_sub(&self, x: Object, y: Object) -> Object
Performs the -
operation.
fn bigint_mul(&self, x: Object, y: Object) -> Object
fn bigint_mul(&self, x: Object, y: Object) -> Object
Performs the *
operation.
fn bigint_div(&self, x: Object, y: Object) -> Object
fn bigint_div(&self, x: Object, y: Object) -> Object
Performs the /
operation. Traps if y
is zero.
fn bigint_rem(&self, x: Object, y: Object) -> Object
fn bigint_rem(&self, x: Object, y: Object) -> Object
Performs the %
operation. Traps if y
is zero.
fn bigint_and(&self, x: Object, y: Object) -> Object
fn bigint_and(&self, x: Object, y: Object) -> Object
Performs the &
operation.
fn bigint_xor(&self, x: Object, y: Object) -> Object
fn bigint_xor(&self, x: Object, y: Object) -> Object
Performs the ^
operation.
fn bigint_shl(&self, x: Object, y: Object) -> Object
fn bigint_shl(&self, x: Object, y: Object) -> Object
Performs the <<
operation. Traps if y
is negative or larger than the size of u64.
fn bigint_shr(&self, x: Object, y: Object) -> Object
fn bigint_shr(&self, x: Object, y: Object) -> Object
Performs the >>
operation. Traps if y
is negative or larger than the size of u64.
fn bigint_cmp(&self, x: Object, y: Object) -> RawVal
fn bigint_cmp(&self, x: Object, y: Object) -> RawVal
Returns an ordering between x
and y
: -1 (less), 0 (equal) or 1 (greater).
fn bigint_is_zero(&self, x: Object) -> RawVal
fn bigint_is_zero(&self, x: Object) -> RawVal
Returns true if x
is equal to the additive identity.
fn bigint_neg(&self, x: Object) -> Object
fn bigint_neg(&self, x: Object) -> Object
Performs the unary -
operation.
fn bigint_not(&self, x: Object) -> Object
fn bigint_not(&self, x: Object) -> Object
Performs the unary !
operation.
fn bigint_gcd(&self, x: Object, y: Object) -> Object
fn bigint_gcd(&self, x: Object, y: Object) -> Object
Calculates the Greatest Common Divisor (GCD) of x
and y
.
fn bigint_lcm(&self, x: Object, y: Object) -> Object
fn bigint_lcm(&self, x: Object, y: Object) -> Object
Calculates the Lowest Common Multiple (LCM) of x
and y
.
fn bigint_pow(&self, x: Object, y: Object) -> Object
fn bigint_pow(&self, x: Object, y: Object) -> Object
Calculates x
to the power y
. Traps if y
is negative or larger than the size of u64.
Calculates (p ^ q) mod m
. Note that this rounds like mod_floor
, not like the %
operator, which makes a difference when given a negative p
or m
.
The result will be in the interval [0, m)
for m > 0
, or in the interval (m, 0]
for m < 0
.
Traps if the q
is negative or the m
is zero.
fn bigint_sqrt(&self, x: Object) -> Object
fn bigint_sqrt(&self, x: Object) -> Object
Calculates the truncated principal square root of x
. Traps if x
is negative.
fn bigint_bits(&self, x: Object) -> u64
fn bigint_bits(&self, x: Object) -> u64
Determines the fewest bits necessary to express x
, not including the sign.
fn bigint_to_bytes_be(&self, x: Object) -> Object
fn bigint_to_bytes_be(&self, x: Object) -> Object
Outputs the BigInt’s magnitude in big-endian byte order into a binary array. The sign is dropped.
fn bigint_to_radix_be(&self, x: Object, radix: RawVal) -> Object
fn bigint_to_radix_be(&self, x: Object, radix: RawVal) -> Object
Outputs the BigInt’s magnitude in the requested base in big-endian digit order into a binary array. The sign is dropped. Radix must be in the range 2…256.
fn serialize_to_binary(&self, v: RawVal) -> Object
fn serialize_to_binary(&self, v: RawVal) -> Object
Serializes an (SC)Val into XDR opaque binary array.
fn deserialize_from_binary(&self, b: Object) -> RawVal
fn deserialize_from_binary(&self, b: Object) -> RawVal
Deserialize a binary array to get back the (SC)Val.
Copies a slice of bytes from a binary array specified at offset b_pos
with length len
into the linear memory at position lm_pos
.
Traps if either the binary array or the linear memory doesn’t have enough bytes.
Copies a segment of the linear memory specified at position lm_pos
with length len
, into a binary array at offset b_pos
. The binary array may grow in size to accommodate the new bytes.
Traps if the linear memory doesn’t have enough bytes.
fn binary_new_from_linear_memory(&self, lm_pos: RawVal, len: RawVal) -> Object
fn binary_new_from_linear_memory(&self, lm_pos: RawVal, len: RawVal) -> Object
Constructs a new binary array initialized with bytes copied from a linear memory slice specified at position lm_pos
with length len
.
fn binary_new(&self) -> Object
fn binary_new(&self) -> Object
Create an empty new binary.
Update the value at index i
in the binary. Return the new binary.
Trap if the index is out of bounds.
fn binary_get(&self, b: Object, i: RawVal) -> RawVal
fn binary_get(&self, b: Object, i: RawVal) -> RawVal
Returns the element at index i
of the binary. Traps if the index is out of bound.
fn binary_del(&self, b: Object, i: RawVal) -> Object
fn binary_del(&self, b: Object, i: RawVal) -> Object
Delete an element in a binary at index i
, shifting all elements after it to the left.
Return the new binary. Traps if the index is out of bound.
fn binary_len(&self, b: Object) -> RawVal
fn binary_len(&self, b: Object) -> RawVal
Returns length of the binary.
fn binary_push(&self, b: Object, u: RawVal) -> Object
fn binary_push(&self, b: Object, u: RawVal) -> Object
Appends an element to the back of the binary.
fn binary_pop(&self, b: Object) -> Object
fn binary_pop(&self, b: Object) -> Object
Removes the last element from the binary and returns the new binary. Traps if original binary is empty.
fn binary_front(&self, b: Object) -> RawVal
fn binary_front(&self, b: Object) -> RawVal
Return the first element in the binary. Traps if the binary is empty
fn binary_back(&self, b: Object) -> RawVal
fn binary_back(&self, b: Object) -> RawVal
Return the last element in the binary. Traps if the binary is empty
Inserts an element at index i
within the binary, shifting all elements after it to the right.
Traps if the index is out of bound
fn binary_append(&self, b1: Object, b2: Object) -> Object
fn binary_append(&self, b1: Object, b2: Object) -> Object
Clone the binary b1
, then moves all the elements of binary b2
into it.
Return the new binary. Traps if number of elements in the binary overflows a u32.
Copies the elements from start
index until end
index, exclusive, in the binary and creates a new binary from it.
Returns the new binary. Traps if the index is out of bound.
fn hash_from_binary(&self, x: Object) -> Object
fn hash_to_binary(&self, x: Object) -> Object
fn public_key_from_binary(&self, x: Object) -> Object
fn public_key_to_binary(&self, x: Object) -> Object
fn compute_hash_sha256(&self, x: Object) -> Object
fn account_get_low_threshold(&self, a: Object) -> RawVal
fn account_get_low_threshold(&self, a: Object) -> RawVal
Get the low threshold for the account with ed25519 public key a (a is binary). Traps if no such account exists.
fn account_get_medium_threshold(&self, a: Object) -> RawVal
fn account_get_medium_threshold(&self, a: Object) -> RawVal
Get the medium threshold for the account with ed25519 public key a (a is binary). Traps if no such account exists.
fn account_get_high_threshold(&self, a: Object) -> RawVal
fn account_get_high_threshold(&self, a: Object) -> RawVal
Get the high threshold for the account with ed25519 public key a (a is binary). Traps if no such account exists.
fn account_get_signer_weight(&self, a: Object, s: Object) -> RawVal
fn account_get_signer_weight(&self, a: Object, s: Object) -> RawVal
Get the signer weight for the signer with ed25519 public key s (s is binary) on the account with ed25519 public key a (a is binary). Returns the master weight if the signer is the master, and returns 0 if no such signer exists. Traps if no such account exists.