pub trait External {
Show 22 methods
// Required methods
fn storage_set(
&mut self,
key: &[u8],
value: &[u8],
) -> Result<(), VMLogicError>;
fn storage_get<'a>(
&'a self,
key: &[u8],
mode: StorageGetMode,
) -> Result<Option<Box<dyn ValuePtr + 'a>>, VMLogicError>;
fn storage_remove(&mut self, key: &[u8]) -> Result<(), VMLogicError>;
fn storage_remove_subtree(
&mut self,
prefix: &[u8],
) -> Result<(), VMLogicError>;
fn storage_has_key(
&mut self,
key: &[u8],
mode: StorageGetMode,
) -> Result<bool, VMLogicError>;
fn generate_data_id(&mut self) -> CryptoHash;
fn get_trie_nodes_count(&self) -> TrieNodesCount;
fn validator_stake(
&self,
account_id: &AccountId,
) -> Result<Option<Balance>, VMLogicError>;
fn validator_power(
&self,
account_id: &AccountId,
) -> Result<Option<Power>, VMLogicError>;
fn validator_total_stake(&self) -> Result<Balance, VMLogicError>;
fn validator_total_power(&self) -> Result<Power, VMLogicError>;
fn create_receipt(
&mut self,
receipt_indices: Vec<ReceiptIndex>,
receiver_id: AccountId,
) -> Result<ReceiptIndex, VMLogicError>;
fn append_action_create_account(
&mut self,
receipt_index: ReceiptIndex,
) -> Result<(), VMLogicError>;
fn append_action_deploy_contract(
&mut self,
receipt_index: ReceiptIndex,
code: Vec<u8>,
) -> Result<(), VMLogicError>;
fn append_action_function_call_weight(
&mut self,
receipt_index: ReceiptIndex,
method_name: Vec<u8>,
args: Vec<u8>,
attached_deposit: Balance,
prepaid_gas: Gas,
gas_weight: GasWeight,
) -> Result<(), VMLogicError>;
fn append_action_transfer(
&mut self,
receipt_index: ReceiptIndex,
deposit: Balance,
) -> Result<(), VMLogicError>;
fn append_action_pledge(
&mut self,
receipt_index: ReceiptIndex,
stake: Balance,
public_key: PublicKey,
);
fn append_action_add_key_with_full_access(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
nonce: Nonce,
);
fn append_action_add_key_with_function_call(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
nonce: Nonce,
allowance: Option<Balance>,
receiver_id: AccountId,
method_names: Vec<Vec<u8>>,
) -> Result<(), VMLogicError>;
fn append_action_delete_key(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
);
fn append_action_delete_account(
&mut self,
receipt_index: ReceiptIndex,
beneficiary_id: AccountId,
) -> Result<(), VMLogicError>;
fn get_receipt_receiver(&self, receipt_index: ReceiptIndex) -> &AccountId;
}
Expand description
An external blockchain interface for the Runtime logic
Required Methods§
Sourcefn storage_set(&mut self, key: &[u8], value: &[u8]) -> Result<(), VMLogicError>
fn storage_set(&mut self, key: &[u8], value: &[u8]) -> Result<(), VMLogicError>
Write value
to the key
of the storage trie associated with the current account.
§Example
assert_eq!(external.storage_set(b"key42", b"value1337"), Ok(()));
// Should return an old value if the key exists
assert_eq!(external.storage_set(b"key42", b"new_value"), Ok(()));
Sourcefn storage_get<'a>(
&'a self,
key: &[u8],
mode: StorageGetMode,
) -> Result<Option<Box<dyn ValuePtr + 'a>>, VMLogicError>
fn storage_get<'a>( &'a self, key: &[u8], mode: StorageGetMode, ) -> Result<Option<Box<dyn ValuePtr + 'a>>, VMLogicError>
Read key
from the storage trie associated with the current account.
§Arguments
-
key
- the key to read -
mode
- whether the lookup will be performed through flat storage or trie
§Errors
This function could return [unc_vm_runner::logic::VMRunnerError::ExternalError
].
§Example
external.storage_set(b"key42", b"value1337").unwrap();
assert_eq!(external.storage_get(b"key42", StorageGetMode::Trie).unwrap().map(|ptr| ptr.deref().unwrap()), Some(b"value1337".to_vec()));
// Returns Ok(None) if there is no value for a key
assert_eq!(external.storage_get(b"no_key", StorageGetMode::Trie).unwrap().map(|ptr| ptr.deref().unwrap()), None);
Sourcefn storage_remove(&mut self, key: &[u8]) -> Result<(), VMLogicError>
fn storage_remove(&mut self, key: &[u8]) -> Result<(), VMLogicError>
Removes the key
from the storage trie associated with the current account.
The operation will succeed even if the key
does not exist.
§Arguments
key
- the key to remove
§Example
external.storage_set(b"key42", b"value1337").unwrap();
// Returns Ok if exists
assert_eq!(external.storage_remove(b"key42"), Ok(()));
// Returns Ok if there was no value
assert_eq!(external.storage_remove(b"no_value_key"), Ok(()));
Sourcefn storage_remove_subtree(&mut self, prefix: &[u8]) -> Result<(), VMLogicError>
fn storage_remove_subtree(&mut self, prefix: &[u8]) -> Result<(), VMLogicError>
Note: The method is currently unused and untested.
Removes all keys with a given prefix
from the storage trie associated with current
account.
§Arguments
prefix
- a prefix for all keys to remove
§Errors
This function could return [unc_vm_runner::logic::VMError
].
§Example
external.storage_set(b"key1", b"value1337").unwrap();
external.storage_set(b"key2", b"value1337").unwrap();
assert_eq!(external.storage_remove_subtree(b"key"), Ok(()));
assert!(!external.storage_has_key(b"key1", StorageGetMode::Trie).unwrap());
assert!(!external.storage_has_key(b"key2", StorageGetMode::Trie).unwrap());
Sourcefn storage_has_key(
&mut self,
key: &[u8],
mode: StorageGetMode,
) -> Result<bool, VMLogicError>
fn storage_has_key( &mut self, key: &[u8], mode: StorageGetMode, ) -> Result<bool, VMLogicError>
Check whether the key
is present in the storage trie associated with the current account.
Returns Ok(true)
if key is present, Ok(false)
if the key is not present.
§Arguments
key
- a key to checkmode
- whether the lookup will be performed through flat storage or trie
§Errors
This function could return [unc_vm_runner::logic::VMError
].
§Example
external.storage_set(b"key42", b"value1337").unwrap();
// Returns value if exists
assert_eq!(external.storage_has_key(b"key42", StorageGetMode::Trie), Ok(true));
// Returns None if there was no value
assert_eq!(external.storage_has_key(b"no_value_key", StorageGetMode::Trie), Ok(false));
fn generate_data_id(&mut self) -> CryptoHash
Sourcefn get_trie_nodes_count(&self) -> TrieNodesCount
fn get_trie_nodes_count(&self) -> TrieNodesCount
Returns amount of touched trie nodes by storage operations
Sourcefn validator_stake(
&self,
account_id: &AccountId,
) -> Result<Option<Balance>, VMLogicError>
fn validator_stake( &self, account_id: &AccountId, ) -> Result<Option<Balance>, VMLogicError>
Returns the validator stake for given account in the current epoch.
If the account is not a validator, returns None
.
fn validator_power( &self, account_id: &AccountId, ) -> Result<Option<Power>, VMLogicError>
Sourcefn validator_total_stake(&self) -> Result<Balance, VMLogicError>
fn validator_total_stake(&self) -> Result<Balance, VMLogicError>
Returns total stake of validators in the current epoch.
fn validator_total_power(&self) -> Result<Power, VMLogicError>
Sourcefn create_receipt(
&mut self,
receipt_indices: Vec<ReceiptIndex>,
receiver_id: AccountId,
) -> Result<ReceiptIndex, VMLogicError>
fn create_receipt( &mut self, receipt_indices: Vec<ReceiptIndex>, receiver_id: AccountId, ) -> Result<ReceiptIndex, VMLogicError>
Create a receipt which will be executed after all the receipts identified by
receipt_indices
are complete.
If any of the ReceiptIndex
es do not refer to a known receipt, this function will fail
with an error.
§Arguments
generate_data_id
- function to generate a data id to connect receipt output toreceipt_indices
- a list of receipt indices the new receipt is depend onreceiver_id
- account id of the receiver of the receipt created
Sourcefn append_action_create_account(
&mut self,
receipt_index: ReceiptIndex,
) -> Result<(), VMLogicError>
fn append_action_create_account( &mut self, receipt_index: ReceiptIndex, ) -> Result<(), VMLogicError>
Sourcefn append_action_deploy_contract(
&mut self,
receipt_index: ReceiptIndex,
code: Vec<u8>,
) -> Result<(), VMLogicError>
fn append_action_deploy_contract( &mut self, receipt_index: ReceiptIndex, code: Vec<u8>, ) -> Result<(), VMLogicError>
Sourcefn append_action_function_call_weight(
&mut self,
receipt_index: ReceiptIndex,
method_name: Vec<u8>,
args: Vec<u8>,
attached_deposit: Balance,
prepaid_gas: Gas,
gas_weight: GasWeight,
) -> Result<(), VMLogicError>
fn append_action_function_call_weight( &mut self, receipt_index: ReceiptIndex, method_name: Vec<u8>, args: Vec<u8>, attached_deposit: Balance, prepaid_gas: Gas, gas_weight: GasWeight, ) -> Result<(), VMLogicError>
Attach the [FunctionCallAction
] action to an existing receipt.
prepaid_gas
and gas_weight
can either be specified or both. If a gas_weight
is
specified, the action should be allocated gas in
distribute_unused_gas
.
For more information, see super::VMLogic::promise_batch_action_function_call_weight.
§Arguments
receipt_index
- an index of Receipt to append an actionmethod_name
- a name of the contract method to callarguments
- a Wasm code to attachattached_deposit
- amount of tokens to transfer with the callprepaid_gas
- amount of prepaid gas to attach to the callgas_weight
- relative weight of unused gas to distribute to the function call action
§Panics
Panics if the receipt_index
does not refer to a known receipt.
Sourcefn append_action_transfer(
&mut self,
receipt_index: ReceiptIndex,
deposit: Balance,
) -> Result<(), VMLogicError>
fn append_action_transfer( &mut self, receipt_index: ReceiptIndex, deposit: Balance, ) -> Result<(), VMLogicError>
Sourcefn append_action_pledge(
&mut self,
receipt_index: ReceiptIndex,
stake: Balance,
public_key: PublicKey,
)
fn append_action_pledge( &mut self, receipt_index: ReceiptIndex, stake: Balance, public_key: PublicKey, )
Sourcefn append_action_add_key_with_full_access(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
nonce: Nonce,
)
fn append_action_add_key_with_full_access( &mut self, receipt_index: ReceiptIndex, public_key: PublicKey, nonce: Nonce, )
Sourcefn append_action_add_key_with_function_call(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
nonce: Nonce,
allowance: Option<Balance>,
receiver_id: AccountId,
method_names: Vec<Vec<u8>>,
) -> Result<(), VMLogicError>
fn append_action_add_key_with_function_call( &mut self, receipt_index: ReceiptIndex, public_key: PublicKey, nonce: Nonce, allowance: Option<Balance>, receiver_id: AccountId, method_names: Vec<Vec<u8>>, ) -> Result<(), VMLogicError>
Attach the [AddKeyAction
] action an existing receipt.
The access key associated with the action will have the
[AccessKeyPermission::FunctionCall
] permission scope.
§Arguments
receipt_index
- an index of Receipt to append an actionpublic_key
- a public key for an access keynonce
- a nonceallowance
- amount of tokens allowed to spend by this access keyreceiver_id
- a contract witch will be allowed to call with this access keymethod_names
- a list of method names is allowed to call with this access key (empty = any method)
§Panics
Panics if the receipt_index
does not refer to a known receipt.
Sourcefn append_action_delete_key(
&mut self,
receipt_index: ReceiptIndex,
public_key: PublicKey,
)
fn append_action_delete_key( &mut self, receipt_index: ReceiptIndex, public_key: PublicKey, )
Sourcefn append_action_delete_account(
&mut self,
receipt_index: ReceiptIndex,
beneficiary_id: AccountId,
) -> Result<(), VMLogicError>
fn append_action_delete_account( &mut self, receipt_index: ReceiptIndex, beneficiary_id: AccountId, ) -> Result<(), VMLogicError>
Attach the [DeleteAccountAction
] action to an existing receipt
§Arguments
receipt_index
- an index of Receipt to append an actionbeneficiary_id
- an account id to which the rest of the funds of the removed account will be transferred
§Panics
Panics if the receipt_index
does not refer to a known receipt.
Sourcefn get_receipt_receiver(&self, receipt_index: ReceiptIndex) -> &AccountId
fn get_receipt_receiver(&self, receipt_index: ReceiptIndex) -> &AccountId
§Panic
Panics if ReceiptIndex
is invalid.