Struct dharitri_wasm_node::ArwenApiImpl
source · pub struct ArwenApiImpl {}Expand description
The reference to the API implementation based on Arwen hooks. It continas no data, can be embedded at no cost. Cloning it is a no-op.
Trait Implementations§
source§impl BlockchainApi for ArwenApiImpl
impl BlockchainApi for ArwenApiImpl
§type BalanceType = ArwenBigUint
type BalanceType = ArwenBigUint
The type of the token balances.
Not named
BigUint to avoid name collisions in types that implement multiple API traits.fn get_sc_address(&self) -> Address
fn get_owner_address(&self) -> Address
fn get_shard_of_address(&self, address: &Address) -> u32
fn is_smart_contract(&self, address: &Address) -> bool
fn get_caller(&self) -> Address
fn get_balance(&self, address: &Address) -> ArwenBigUint
fn get_tx_hash(&self) -> H256
fn get_gas_left(&self) -> u64
fn get_block_timestamp(&self) -> u64
fn get_block_nonce(&self) -> u64
fn get_block_round(&self) -> u64
fn get_block_epoch(&self) -> u64
fn get_block_random_seed(&self) -> Box<[u8; 48]>
fn get_prev_block_timestamp(&self) -> u64
fn get_prev_block_nonce(&self) -> u64
fn get_prev_block_round(&self) -> u64
fn get_prev_block_epoch(&self) -> u64
fn get_prev_block_random_seed(&self) -> Box<[u8; 48]>
fn get_current_dct_nft_nonce( &self, address: &Address, token: &TokenIdentifier ) -> u64
fn get_dct_balance( &self, address: &Address, token: &TokenIdentifier, nonce: u64 ) -> ArwenBigUint
fn get_dct_token_data( &self, address: &Address, token: &TokenIdentifier, nonce: u64 ) -> DctTokenData<ArwenBigUint>
fn check_caller_is_owner(&self)
fn get_sc_balance( &self, token: &TokenIdentifier, nonce: u64 ) -> Self::BalanceType
source§fn get_cumulated_validator_rewards(&self) -> Self::BalanceType
fn get_cumulated_validator_rewards(&self) -> Self::BalanceType
Retrieves validator rewards, as set by the protocol.
TODO: move to the storage API, once BigUint gets refactored
source§fn get_dct_local_roles(&self, token_id: &TokenIdentifier) -> Vec<DctLocalRole>
fn get_dct_local_roles(&self, token_id: &TokenIdentifier) -> Vec<DctLocalRole>
Retrieves local roles for the token, by reading protected storage.
source§impl CallValueApi for ArwenApiImpl
impl CallValueApi for ArwenApiImpl
§type AmountType = ArwenBigUint
type AmountType = ArwenBigUint
The type of the payment arguments.
Not named
BigUint to avoid name collisions in types that implement multiple API traits.fn check_not_payable(&self)
source§fn moax_value(&self) -> ArwenBigUint
fn moax_value(&self) -> ArwenBigUint
Retrieves the MOAX call value from the VM.
Will return 0 in case of an DCT transfer (cannot have both MOAX and DCT transfer simultaneously).
source§fn dct_value(&self) -> ArwenBigUint
fn dct_value(&self) -> ArwenBigUint
Retrieves the DCT call value from the VM.
Will return 0 in case of an MOAX transfer (cannot have both MOAX and DCT transfer simultaneously).
source§fn token(&self) -> TokenIdentifier
fn token(&self) -> TokenIdentifier
Returns the call value token identifier of the current call.
The identifier is wrapped in a TokenIdentifier object, to hide underlying logic. Read more
source§fn dct_token_nonce(&self) -> u64
fn dct_token_nonce(&self) -> u64
Returns the nonce of the received DCT token.
Will return 0 in case of MOAX or fungible DCT transfer.
source§fn dct_token_type(&self) -> DctTokenType
fn dct_token_type(&self) -> DctTokenType
Returns the DCT token type.
Will return “Fungible” for MOAX.
source§fn require_moax(&self) -> Self::AmountType
fn require_moax(&self) -> Self::AmountType
Will return the MOAX call value,
but also fail with an error if DCT is sent.
Especially used in the auto-generated call value processing.
source§fn require_dct(&self, token: &[u8]) -> Self::AmountType
fn require_dct(&self, token: &[u8]) -> Self::AmountType
Will return the DCT call value,
but also fail with an error if MOAX or the wrong DCT token is sent.
Especially used in the auto-generated call value processing.
source§fn payment_token_pair(&self) -> (Self::AmountType, TokenIdentifier)
fn payment_token_pair(&self) -> (Self::AmountType, TokenIdentifier)
Returns both the call value (either MOAX or DCT) and the token identifier.
Especially used in the `#[payable(“*”)] auto-generated snippets.
The method might seem redundant, but there is such a hook in Arwen
that might be used in this scenario in the future.
source§impl Clone for ArwenApiImpl
impl Clone for ArwenApiImpl
Should be no-op. The API implementation is zero-sized.
source§impl ContractBase for ArwenApiImpl
impl ContractBase for ArwenApiImpl
type EllipticCurve = ArwenEllipticCurve
type BigUint = ArwenBigUint
type BigInt = ArwenBigInt
§type Storage = ArwenApiImpl
type Storage = ArwenApiImpl
Abstracts the lower-level storage functionality.
§type CallValue = ArwenApiImpl
type CallValue = ArwenApiImpl
Abstracts the call value handling at the beginning of a function call.
§type SendApi = ArwenApiImpl
type SendApi = ArwenApiImpl
Abstracts the sending of MOAX & DCT transactions, as well as async calls.
type BlockchainApi = ArwenApiImpl
type CryptoApi = ArwenApiImpl
type LogApi = ArwenApiImpl
type ErrorApi = ArwenApiImpl
source§fn get_storage_raw(&self) -> Self::Storage
fn get_storage_raw(&self) -> Self::Storage
Gateway into the lower-level storage functionality.
Storage related annotations make use of this.
Using it directly is not recommended.
source§fn call_value(&self) -> Self::CallValue
fn call_value(&self) -> Self::CallValue
Gateway into the call value retrieval functionality.
The payment annotations should normally be the ones to handle this,
but the developer is also given direct access to the API.
source§fn send(&self) -> Self::SendApi
fn send(&self) -> Self::SendApi
Gateway to the functionality related to sending transactions from the current contract.
source§fn blockchain(&self) -> Self::BlockchainApi
fn blockchain(&self) -> Self::BlockchainApi
Gateway blockchain info related to the current transaction and to accounts.
source§fn log_api_raw(&self) -> Self::LogApi
fn log_api_raw(&self) -> Self::LogApi
Gateway into the lower-level event log functionality.
Gets called in auto-generated
Using it directly is not recommended.
TODO: consider moving to
ContractPrivateApi.source§fn error_api(&self) -> Self::ErrorApi
fn error_api(&self) -> Self::ErrorApi
Currently for some auto-generated code involving callbacks.
Please avoid using it directly.
TODO: find a way to hide this API.
fn proxy<P>(&self, address: Address) -> Pwhere
P: ProxyObjApi<SendApi = Self::SendApi>,
source§impl CryptoApi for ArwenApiImpl
impl CryptoApi for ArwenApiImpl
§type BigUint = ArwenBigUint
type BigUint = ArwenBigUint
Numeric type used in some of the Arwen hooks.
fn sha256(&self, data: &[u8]) -> H256
fn keccak256(&self, data: &[u8]) -> H256
fn verify_bls(&self, key: &[u8], message: &[u8], signature: &[u8]) -> bool
fn verify_ed25519(&self, key: &[u8], message: &[u8], signature: &[u8]) -> bool
source§impl EndpointArgumentApi for ArwenApiImpl
impl EndpointArgumentApi for ArwenApiImpl
Interface to only be used by code generated by the macros. The smart contract code doesn’t have access to these methods directly.
fn get_num_arguments(&self) -> i32
fn get_argument_len(&self, arg_index: i32) -> usize
fn copy_argument_to_slice(&self, arg_index: i32, slice: &mut [u8])
fn get_argument_vec_u8(&self, arg_index: i32) -> Vec<u8>
fn get_argument_boxed_bytes(&self, arg_index: i32) -> BoxedBytes
fn get_argument_big_uint_raw(&self, arg_id: i32) -> i32
fn get_argument_big_int_raw(&self, arg_id: i32) -> i32
fn get_argument_u64(&self, arg_id: i32) -> u64
fn get_argument_i64(&self, arg_id: i32) -> i64
fn check_num_arguments(&self, expected: i32)
source§impl EndpointFinishApi for ArwenApiImpl
impl EndpointFinishApi for ArwenApiImpl
Interface to only be used by code generated by the macros. The smart contract code doesn’t have access to these methods directly.
fn finish_slice_u8(&self, slice: &[u8])
fn finish_big_int_raw(&self, handle: i32)
fn finish_big_uint_raw(&self, handle: i32)
fn finish_u64(&self, value: u64)
fn finish_i64(&self, value: i64)
source§impl ErrorApi for ArwenApiImpl
impl ErrorApi for ArwenApiImpl
fn signal_error(&self, message: &[u8]) -> !
source§impl LogApi for ArwenApiImpl
impl LogApi for ArwenApiImpl
Interface to only be used by code generated by the macros. The smart contract code doesn’t have access to these methods directly.
source§impl SendApi for ArwenApiImpl
impl SendApi for ArwenApiImpl
§type AmountType = ArwenBigUint
type AmountType = ArwenBigUint
The type of the payment arguments.
Not named
BigUint to avoid name collisions in types that implement multiple API traits.§type ProxyBigInt = ArwenBigInt
type ProxyBigInt = ArwenBigInt
Not used by
SendApi, but forwarded to the proxy traits.type ProxyEllipticCurve = ArwenEllipticCurve
§type ProxyStorage = ArwenApiImpl
type ProxyStorage = ArwenApiImpl
Not used by
SendApi, but forwarded to the proxy traits.source§fn get_sc_address(&self) -> Address
fn get_sc_address(&self) -> Address
Required for DCTNFTTransfer.
Same as the implementation from BlockchainApi.
source§fn get_gas_left(&self) -> u64
fn get_gas_left(&self) -> u64
To be used internally by the SendApi implementation.
Do not use directly from contracts. It might be removed from this trait at some point or reworked.
source§fn get_dct_token_data(
&self,
address: &Address,
token: &TokenIdentifier,
nonce: u64
) -> DctTokenData<ArwenBigUint>
fn get_dct_token_data( &self, address: &Address, token: &TokenIdentifier, nonce: u64 ) -> DctTokenData<ArwenBigUint>
Used internally for sell_nft.
Do not use directly from contracts.
source§fn direct_moax(&self, to: &Address, amount: &ArwenBigUint, data: &[u8])
fn direct_moax(&self, to: &Address, amount: &ArwenBigUint, data: &[u8])
Sends MOAX to a given address, directly.
Used especially for sending MOAX to regular accounts.
source§fn direct_moax_execute(
&self,
to: &Address,
amount: &ArwenBigUint,
gas_limit: u64,
function: &[u8],
arg_buffer: &ArgBuffer
) -> Result<(), &'static [u8]>
fn direct_moax_execute( &self, to: &Address, amount: &ArwenBigUint, gas_limit: u64, function: &[u8], arg_buffer: &ArgBuffer ) -> Result<(), &'static [u8]>
Sends MOAX to an address (optionally) and executes like an async call, but without callback.
source§fn direct_dct_execute(
&self,
to: &Address,
token: &TokenIdentifier,
amount: &ArwenBigUint,
gas_limit: u64,
function: &[u8],
arg_buffer: &ArgBuffer
) -> Result<(), &'static [u8]>
fn direct_dct_execute( &self, to: &Address, token: &TokenIdentifier, amount: &ArwenBigUint, gas_limit: u64, function: &[u8], arg_buffer: &ArgBuffer ) -> Result<(), &'static [u8]>
Sends DCT to an address and executes like an async call, but without callback.
source§fn direct_dct_nft_execute(
&self,
to: &Address,
token: &TokenIdentifier,
nonce: u64,
amount: &ArwenBigUint,
gas_limit: u64,
function: &[u8],
arg_buffer: &ArgBuffer
) -> Result<(), &'static [u8]>
fn direct_dct_nft_execute( &self, to: &Address, token: &TokenIdentifier, nonce: u64, amount: &ArwenBigUint, gas_limit: u64, function: &[u8], arg_buffer: &ArgBuffer ) -> Result<(), &'static [u8]>
Sends DCT NFT to an address and executes like an async call, but without callback.
source§fn async_call_raw(&self, to: &Address, amount: &ArwenBigUint, data: &[u8]) -> !
fn async_call_raw(&self, to: &Address, amount: &ArwenBigUint, data: &[u8]) -> !
Sends an asynchronous call to another contract.
Calling this method immediately terminates tx execution.
Using it directly is generally discouraged. Read more
source§fn deploy_contract(
&self,
gas: u64,
amount: &ArwenBigUint,
code: &BoxedBytes,
code_metadata: CodeMetadata,
arg_buffer: &ArgBuffer
) -> Option<Address>
fn deploy_contract( &self, gas: u64, amount: &ArwenBigUint, code: &BoxedBytes, code_metadata: CodeMetadata, arg_buffer: &ArgBuffer ) -> Option<Address>
Deploys a new contract in the same shard.
Unlike
async_call_raw, the deployment is synchronous and tx execution continues afterwards.
Also unlike async_call_raw, it uses an argument buffer to pass arguments
If the deployment fails, Option::None is returnedsource§fn deploy_from_source_contract(
&self,
gas: u64,
amount: &ArwenBigUint,
source_contract_address: &Address,
code_metadata: CodeMetadata,
arg_buffer: &ArgBuffer
) -> Option<Address>
fn deploy_from_source_contract( &self, gas: u64, amount: &ArwenBigUint, source_contract_address: &Address, code_metadata: CodeMetadata, arg_buffer: &ArgBuffer ) -> Option<Address>
Deploys a new contract in the same shard by re-using the code of an already deployed source contract.
The deployment is done synchronously and the new contract’s address is returned.
If the deployment fails, Option::None is returned
source§fn upgrade_contract(
&self,
sc_address: &Address,
gas: u64,
amount: &ArwenBigUint,
code: &BoxedBytes,
code_metadata: CodeMetadata,
arg_buffer: &ArgBuffer
)
fn upgrade_contract( &self, sc_address: &Address, gas: u64, amount: &ArwenBigUint, code: &BoxedBytes, code_metadata: CodeMetadata, arg_buffer: &ArgBuffer )
Upgrades a child contract of the currently executing contract.
The upgrade is synchronous, and the current transaction will fail if the upgrade fails.
The child contract’s new init function will be called with the provided arguments
source§fn execute_on_dest_context_raw(
&self,
gas: u64,
address: &Address,
amount: &ArwenBigUint,
function: &[u8],
arg_buffer: &ArgBuffer
) -> Vec<BoxedBytes>
fn execute_on_dest_context_raw( &self, gas: u64, address: &Address, amount: &ArwenBigUint, function: &[u8], arg_buffer: &ArgBuffer ) -> Vec<BoxedBytes>
Same shard, in-line execution of another contract.
source§fn execute_on_dest_context_raw_custom_result_range<F>(
&self,
gas: u64,
address: &Address,
amount: &ArwenBigUint,
function: &[u8],
arg_buffer: &ArgBuffer,
range_closure: F
) -> Vec<BoxedBytes>
fn execute_on_dest_context_raw_custom_result_range<F>( &self, gas: u64, address: &Address, amount: &ArwenBigUint, function: &[u8], arg_buffer: &ArgBuffer, range_closure: F ) -> Vec<BoxedBytes>
Same shard, in-line execution of another contract.
Allows the contract to specify which result range to extract as sync call result.
This is a workaround to handle nested sync calls.
Please do not use this method unless there is absolutely no other option.
Will be eliminated after some future Arwen hook redesign.
range_closure takes the number of results before, the number of results after,
and is expected to return the start index (inclusive) and end index (exclusive).fn execute_on_dest_context_by_caller_raw( &self, gas: u64, address: &Address, amount: &ArwenBigUint, function: &[u8], arg_buffer: &ArgBuffer ) -> Vec<BoxedBytes>
fn execute_on_same_context_raw( &self, gas: u64, address: &Address, amount: &ArwenBigUint, function: &[u8], arg_buffer: &ArgBuffer )
source§fn storage_store_tx_hash_key(&self, data: &[u8])
fn storage_store_tx_hash_key(&self, data: &[u8])
Used to store data between async call and callback.
source§fn storage_load_tx_hash_key(&self) -> BoxedBytes
fn storage_load_tx_hash_key(&self) -> BoxedBytes
Used to store data between async call and callback.
source§fn call_local_dct_built_in_function(
&self,
gas: u64,
function: &[u8],
arg_buffer: &ArgBuffer
) -> Vec<BoxedBytes>
fn call_local_dct_built_in_function( &self, gas: u64, function: &[u8], arg_buffer: &ArgBuffer ) -> Vec<BoxedBytes>
Allows synchronously calling a local function by name. Execution is resumed afterwards.
You should never have to call this function directly.
Use the other specific methods instead.
source§fn direct(
&self,
to: &Address,
token: &TokenIdentifier,
nonce: u64,
amount: &Self::AmountType,
data: &[u8]
)
fn direct( &self, to: &Address, token: &TokenIdentifier, nonce: u64, amount: &Self::AmountType, data: &[u8] )
Sends either MOAX, DCT or NFT to the target address,
depending on the token identifier and nonce
source§fn async_call(&self, async_call: AsyncCall<Self>) -> !
fn async_call(&self, async_call: AsyncCall<Self>) -> !
Sends an asynchronous call to another contract, with either MOAX or DCT value.
The
token argument decides which one it will be.
Calling this method immediately terminates tx execution.source§fn transfer_dct_via_async_call(
&self,
to: &Address,
token: &TokenIdentifier,
nonce: u64,
amount: &Self::AmountType,
data: &[u8]
) -> !
fn transfer_dct_via_async_call( &self, to: &Address, token: &TokenIdentifier, nonce: u64, amount: &Self::AmountType, data: &[u8] ) -> !
Performs a simple DCT/NFT transfer, but via async call.
As with any async call, this immediately terminates the execution of the current call.
So only use as the last call in your endpoint.
If you want to perform multiple transfers, use
Note that MOAX can NOT be transfered with this function.
As with any async call, this immediately terminates the execution of the current call.
So only use as the last call in your endpoint.
If you want to perform multiple transfers, use
self.send().direct() instead.Note that MOAX can NOT be transfered with this function.
fn change_owner_address(&self, child_sc_address: &Address, new_owner: &Address)
source§fn dct_local_mint(
&self,
token: &TokenIdentifier,
nonce: u64,
amount: &Self::AmountType
)
fn dct_local_mint( &self, token: &TokenIdentifier, nonce: u64, amount: &Self::AmountType )
Allows synchronous minting of DCT/SFT (depending on nonce). Execution is resumed afterwards.
Note that the SC must have the DCTLocalMint or DCTNftAddQuantity roles set,
or this will fail with “action is not allowed”
For SFTs, you must use
self.send().dct_nft_create() before adding additional quantity.
This function cannot be used for NFTs.source§fn dct_local_burn(
&self,
token: &TokenIdentifier,
nonce: u64,
amount: &Self::AmountType
)
fn dct_local_burn( &self, token: &TokenIdentifier, nonce: u64, amount: &Self::AmountType )
Allows synchronous burning of DCT/SFT/NFT (depending on nonce). Execution is resumed afterwards.
Note that the SC must have the DCTLocalBurn or DCTNftBurn roles set,
or this will fail with “action is not allowed”
source§fn dct_nft_create<T>(
&self,
token: &TokenIdentifier,
amount: &Self::AmountType,
name: &BoxedBytes,
royalties: &Self::AmountType,
hash: &BoxedBytes,
attributes: &T,
uris: &[BoxedBytes]
) -> u64where
T: TopEncode,
fn dct_nft_create<T>(
&self,
token: &TokenIdentifier,
amount: &Self::AmountType,
name: &BoxedBytes,
royalties: &Self::AmountType,
hash: &BoxedBytes,
attributes: &T,
uris: &[BoxedBytes]
) -> u64where
T: TopEncode,
Creates a new NFT token of a certain type (determined by
This is a built-in function, so the smart contract execution is resumed after. Must have DCTNftCreate role set, or this will fail with “action is not allowed”. Returns the nonce of the newly created NFT.
token_identifier).attributes can be any serializable custom struct.This is a built-in function, so the smart contract execution is resumed after. Must have DCTNftCreate role set, or this will fail with “action is not allowed”. Returns the nonce of the newly created NFT.
source§fn sell_nft(
&self,
nft_id: &TokenIdentifier,
nft_nonce: u64,
nft_amount: &Self::AmountType,
buyer: &Address,
payment_token: &TokenIdentifier,
payment_nonce: u64,
payment_amount: &Self::AmountType
) -> Self::AmountType
fn sell_nft( &self, nft_id: &TokenIdentifier, nft_nonce: u64, nft_amount: &Self::AmountType, buyer: &Address, payment_token: &TokenIdentifier, payment_nonce: u64, payment_amount: &Self::AmountType ) -> Self::AmountType
Sends thr NFTs to the buyer address and calculates and sends the required royalties to the NFT creator.
Returns the payment amount left after sending royalties.
source§impl StorageReadApi for ArwenApiImpl
impl StorageReadApi for ArwenApiImpl
fn storage_load_len(&self, key: &[u8]) -> usize
fn storage_load_vec_u8(&self, key: &[u8]) -> Vec<u8>
fn storage_load_boxed_bytes(&self, key: &[u8]) -> BoxedBytes
fn storage_load_big_uint_raw(&self, key: &[u8]) -> i32
fn storage_load_u64(&self, key: &[u8]) -> u64
fn storage_load_i64(&self, key: &[u8]) -> i64
source§impl StorageWriteApi for ArwenApiImpl
impl StorageWriteApi for ArwenApiImpl
fn storage_store_slice_u8(&self, key: &[u8], value: &[u8])
fn storage_store_big_uint_raw(&self, key: &[u8], handle: i32)
fn storage_store_u64(&self, key: &[u8], value: u64)
fn storage_store_i64(&self, key: &[u8], value: i64)
Auto Trait Implementations§
impl RefUnwindSafe for ArwenApiImpl
impl Send for ArwenApiImpl
impl Sync for ArwenApiImpl
impl Unpin for ArwenApiImpl
impl UnwindSafe for ArwenApiImpl
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more