pub trait ContractContext {
Show 28 methods
// Required methods
fn get_value(&self, key: &[u8]) -> Option<Bytes>;
fn set_value(&self, key: &[u8], value: Bytes);
fn get_named_value(&self, name: &str) -> Option<Bytes>;
fn set_named_value(&self, name: &str, value: CLValue);
fn get_dictionary_value(
&self,
dictionary_name: &str,
key: &[u8],
) -> Option<Bytes>;
fn set_dictionary_value(
&self,
dictionary_name: &str,
key: &[u8],
value: CLValue,
);
fn remove_dictionary(&self, dictionary_name: &str);
fn init_dictionary(&self, dictionary_name: &str);
fn caller(&self) -> Address;
fn self_address(&self) -> Address;
fn call_contract(&self, address: Address, call_def: CallDef) -> Bytes;
fn get_block_time(&self) -> u64;
fn attached_value(&self) -> U512;
fn self_balance(&self) -> U512;
fn emit_event(&self, event: &Bytes);
fn emit_native_event(&self, event: &Bytes);
fn transfer_tokens(&self, to: &Address, amount: &U512);
fn revert(&self, error: OdraError) -> !;
fn get_named_arg_bytes(&self, name: &str) -> OdraResult<Bytes>;
fn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>;
fn handle_attached_value(&self);
fn clear_attached_value(&self);
fn hash(&self, bytes: &[u8]) -> [u8; 32];
fn delegate(&self, validator: PublicKey, amount: U512);
fn undelegate(&self, validator: PublicKey, amount: U512);
fn delegated_amount(&self, validator: PublicKey) -> U512;
fn get_validator_info(&self, validator: PublicKey) -> Option<ValidatorInfo>;
fn pseudorandom_bytes(&self) -> [u8; 32];
}Expand description
Trait representing the context of a smart contract.
Required Methods§
Sourcefn set_value(&self, key: &[u8], value: Bytes)
fn set_value(&self, key: &[u8], value: Bytes)
Writes to the storage the value associated with the given key.
§Arguments
key- The key to set the value for.value- The value to be set.
Sourcefn get_named_value(&self, name: &str) -> Option<Bytes>
fn get_named_value(&self, name: &str) -> Option<Bytes>
Sourcefn set_named_value(&self, name: &str, value: CLValue)
fn set_named_value(&self, name: &str, value: CLValue)
Sourcefn get_dictionary_value(
&self,
dictionary_name: &str,
key: &[u8],
) -> Option<Bytes>
fn get_dictionary_value( &self, dictionary_name: &str, key: &[u8], ) -> Option<Bytes>
Retrieves the key value behind a named dictionary.
§Arguments
dictionary_name- The name of the dictionary.key- The key to retrieve the value for.
Sourcefn set_dictionary_value(
&self,
dictionary_name: &str,
key: &[u8],
value: CLValue,
)
fn set_dictionary_value( &self, dictionary_name: &str, key: &[u8], value: CLValue, )
Sets the key value behind a named dictionary.
§Arguments
dictionary_name- The name of the dictionary.key- The key to set the value for.value- The value to set.
Sourcefn remove_dictionary(&self, dictionary_name: &str)
fn remove_dictionary(&self, dictionary_name: &str)
Sourcefn init_dictionary(&self, dictionary_name: &str)
fn init_dictionary(&self, dictionary_name: &str)
Initializes the empty dictionary with the given name.
§Arguments
dictionary_name- The name of the dictionary to initialize.
Sourcefn self_address(&self) -> Address
fn self_address(&self) -> Address
Retrieves the address of the current contract.
Sourcefn call_contract(&self, address: Address, call_def: CallDef) -> Bytes
fn call_contract(&self, address: Address, call_def: CallDef) -> Bytes
Sourcefn get_block_time(&self) -> u64
fn get_block_time(&self) -> u64
Sourcefn attached_value(&self) -> U512
fn attached_value(&self) -> U512
Sourcefn self_balance(&self) -> U512
fn self_balance(&self) -> U512
Sourcefn emit_event(&self, event: &Bytes)
fn emit_event(&self, event: &Bytes)
Sourcefn emit_native_event(&self, event: &Bytes)
fn emit_native_event(&self, event: &Bytes)
Emits an event with the specified event data using native mechanism.
§Arguments
event- The event data to emit.
Sourcefn transfer_tokens(&self, to: &Address, amount: &U512)
fn transfer_tokens(&self, to: &Address, amount: &U512)
Transfers tokens to the specified address.
§Arguments
to- The address to transfer the tokens to.amount- The amount of tokens to transfer.
Sourcefn get_named_arg_bytes(&self, name: &str) -> OdraResult<Bytes>
fn get_named_arg_bytes(&self, name: &str) -> OdraResult<Bytes>
Sourcefn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>
fn get_opt_named_arg_bytes(&self, name: &str) -> Option<Bytes>
Similar to get_named_arg_bytes, but returns None if the named argument is not present.
Sourcefn handle_attached_value(&self)
fn handle_attached_value(&self)
Handles the value attached to the call. Sets the value in the contract context.
Sourcefn clear_attached_value(&self)
fn clear_attached_value(&self)
Clears the value attached to the call.
Sourcefn delegate(&self, validator: PublicKey, amount: U512)
fn delegate(&self, validator: PublicKey, amount: U512)
Delegate the amount of tokens to the validator
§Arguments
validator- The validator to delegate the tokens to.amount- The amount of tokens to delegate.
Sourcefn undelegate(&self, validator: PublicKey, amount: U512)
fn undelegate(&self, validator: PublicKey, amount: U512)
Undelegate the amount of tokens from the validator
§Arguments
validator- The validator to undelegate the tokens from.amount- The amount of tokens to undelegate.
Sourcefn delegated_amount(&self, validator: PublicKey) -> U512
fn delegated_amount(&self, validator: PublicKey) -> U512
Sourcefn get_validator_info(&self, validator: PublicKey) -> Option<ValidatorInfo>
fn get_validator_info(&self, validator: PublicKey) -> Option<ValidatorInfo>
Sourcefn pseudorandom_bytes(&self) -> [u8; 32]
fn pseudorandom_bytes(&self) -> [u8; 32]
Returns a vector of pseudorandom bytes of the specified size. There is no guarantee that the returned bytes are in any way cryptographically secure.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".