pub struct ContractRuntime<Application>where
Application: Contract,{ /* private fields */ }
Expand description
The common runtime to interface with the host executing the contract.
It automatically caches read-only values received from the host.
Implementations§
Source§impl<Application> ContractRuntime<Application>where
Application: Contract,
impl<Application> ContractRuntime<Application>where
Application: Contract,
Sourcepub fn key_value_store(&self) -> KeyValueStore
pub fn key_value_store(&self) -> KeyValueStore
Returns the key-value store to interface with storage.
Sourcepub fn root_view_storage_context(&self) -> ViewStorageContext
pub fn root_view_storage_context(&self) -> ViewStorageContext
Returns a storage context suitable for a root view.
Source§impl<Application> ContractRuntime<Application>where
Application: Contract,
impl<Application> ContractRuntime<Application>where
Application: Contract,
Sourcepub fn application_parameters(&mut self) -> Application::Parameters
pub fn application_parameters(&mut self) -> Application::Parameters
Returns the application parameters provided when the application was created.
Sourcepub fn application_id(&mut self) -> ApplicationId<Application::Abi>
pub fn application_id(&mut self) -> ApplicationId<Application::Abi>
Returns the ID of the current application.
Sourcepub fn application_creator_chain_id(&mut self) -> ChainId
pub fn application_creator_chain_id(&mut self) -> ChainId
Returns the chain ID of the current application creator.
Sourcepub fn block_height(&mut self) -> BlockHeight
pub fn block_height(&mut self) -> BlockHeight
Returns the height of the current block that is executing.
Sourcepub fn system_time(&mut self) -> Timestamp
pub fn system_time(&mut self) -> Timestamp
Retrieves the current system time, i.e. the timestamp of the block in which this is called.
Sourcepub fn chain_balance(&mut self) -> Amount
pub fn chain_balance(&mut self) -> Amount
Returns the current chain balance.
Sourcepub fn owner_balance(&mut self, owner: AccountOwner) -> Amount
pub fn owner_balance(&mut self, owner: AccountOwner) -> Amount
Returns the balance of one of the accounts on this chain.
Sourcepub fn chain_ownership(&mut self) -> ChainOwnership
pub fn chain_ownership(&mut self) -> ChainOwnership
Retrieves the owner configuration for the current chain.
Sourcepub fn http_request(&mut self, request: Request) -> Response
pub fn http_request(&mut self, request: Request) -> Response
Makes an HTTP request
as an oracle and returns the HTTP response.
Should only be used with queries where it is very likely that all validators will receive the same response, otherwise most block proposals will fail.
Cannot be used in fast blocks: A block using this call should be proposed by a regular owner, not a super owner.
Sourcepub fn assert_before(&mut self, timestamp: Timestamp)
pub fn assert_before(&mut self, timestamp: Timestamp)
Panics if the current time at block validation is >= timestamp
. Note that block
validation happens at or after the block timestamp, but isn’t necessarily the same.
Cannot be used in fast blocks: A block using this call should be proposed by a regular owner, not a super owner.
Sourcepub fn read_data_blob(&mut self, hash: DataBlobHash) -> Vec<u8> ⓘ
pub fn read_data_blob(&mut self, hash: DataBlobHash) -> Vec<u8> ⓘ
Reads a data blob with the given hash from storage.
Sourcepub fn assert_data_blob_exists(&mut self, hash: DataBlobHash)
pub fn assert_data_blob_exists(&mut self, hash: DataBlobHash)
Asserts that a data blob with the given hash exists in storage.
Source§impl<Application> ContractRuntime<Application>where
Application: Contract,
impl<Application> ContractRuntime<Application>where
Application: Contract,
Sourcepub fn authenticated_signer(&mut self) -> Option<AccountOwner>
pub fn authenticated_signer(&mut self) -> Option<AccountOwner>
Returns the authenticated signer for this execution, if there is one.
Sourcepub fn message_is_bouncing(&mut self) -> Option<bool>
pub fn message_is_bouncing(&mut self) -> Option<bool>
Sourcepub fn message_origin_chain_id(&mut self) -> Option<ChainId>
pub fn message_origin_chain_id(&mut self) -> Option<ChainId>
Returns the chain ID where the incoming message originated from, or None
if not executing
an incoming message.
Sourcepub fn authenticated_caller_id(&mut self) -> Option<ApplicationId>
pub fn authenticated_caller_id(&mut self) -> Option<ApplicationId>
Returns the authenticated caller ID, if the caller configured it and if the current context is executing a cross-application call.
Sourcepub fn check_account_permission(
&mut self,
owner: AccountOwner,
) -> Result<(), AccountPermissionError>
pub fn check_account_permission( &mut self, owner: AccountOwner, ) -> Result<(), AccountPermissionError>
Verifies that the current execution context authorizes operations on a given account.
Sourcepub fn send_message(
&mut self,
destination: ChainId,
message: Application::Message,
)
pub fn send_message( &mut self, destination: ChainId, message: Application::Message, )
Schedules a message to be sent to this application on another chain.
Sourcepub fn prepare_message(
&mut self,
message: Application::Message,
) -> MessageBuilder<Application::Message>
pub fn prepare_message( &mut self, message: Application::Message, ) -> MessageBuilder<Application::Message>
Returns a MessageBuilder
to prepare a message to be sent.
Sourcepub fn transfer(
&mut self,
source: AccountOwner,
destination: Account,
amount: Amount,
)
pub fn transfer( &mut self, source: AccountOwner, destination: Account, amount: Amount, )
Transfers an amount
of native tokens from source
owner account (or the current chain’s
balance) to destination
.
Sourcepub fn claim(&mut self, source: Account, destination: Account, amount: Amount)
pub fn claim(&mut self, source: Account, destination: Account, amount: Amount)
Claims an amount
of native tokens from a source
account to a destination
account.
Sourcepub fn call_application<A: ContractAbi + Send>(
&mut self,
authenticated: bool,
application: ApplicationId<A>,
call: &A::Operation,
) -> A::Response
pub fn call_application<A: ContractAbi + Send>( &mut self, authenticated: bool, application: ApplicationId<A>, call: &A::Operation, ) -> A::Response
Calls another application.
Sourcepub fn emit(&mut self, name: StreamName, value: &Application::EventValue) -> u32
pub fn emit(&mut self, name: StreamName, value: &Application::EventValue) -> u32
Adds a new item to an event stream. Returns the new event’s index in the stream.
Sourcepub fn read_event(
&mut self,
chain_id: ChainId,
name: StreamName,
index: u32,
) -> Application::EventValue
pub fn read_event( &mut self, chain_id: ChainId, name: StreamName, index: u32, ) -> Application::EventValue
Reads an event from a stream. Returns the event’s value.
Fails the block if the event doesn’t exist.
Sourcepub fn subscribe_to_events(
&mut self,
chain_id: ChainId,
application_id: ApplicationId,
name: StreamName,
)
pub fn subscribe_to_events( &mut self, chain_id: ChainId, application_id: ApplicationId, name: StreamName, )
Subscribes this application to an event stream.
Sourcepub fn unsubscribe_from_events(
&mut self,
chain_id: ChainId,
application_id: ApplicationId,
name: StreamName,
)
pub fn unsubscribe_from_events( &mut self, chain_id: ChainId, application_id: ApplicationId, name: StreamName, )
Unsubscribes this application from an event stream.
Sourcepub fn query_service<A: ServiceAbi + Send>(
&mut self,
application_id: ApplicationId<A>,
query: A::Query,
) -> A::QueryResponse
pub fn query_service<A: ServiceAbi + Send>( &mut self, application_id: ApplicationId<A>, query: A::Query, ) -> A::QueryResponse
Queries an application service as an oracle and returns the response.
Should only be used with queries where it is very likely that all validators will compute the same result, otherwise most block proposals will fail.
Cannot be used in fast blocks: A block using this call should be proposed by a regular owner, not a super owner.
Sourcepub fn open_chain(
&mut self,
chain_ownership: ChainOwnership,
application_permissions: ApplicationPermissions,
balance: Amount,
) -> ChainId
pub fn open_chain( &mut self, chain_ownership: ChainOwnership, application_permissions: ApplicationPermissions, balance: Amount, ) -> ChainId
Opens a new chain, configuring it with the provided chain_ownership
,
application_permissions
and initial balance
(debited from the current chain).
Sourcepub fn close_chain(&mut self) -> Result<(), CloseChainError>
pub fn close_chain(&mut self) -> Result<(), CloseChainError>
Closes the current chain. Returns an error if the application doesn’t have permission to do so.
Sourcepub fn change_application_permissions(
&mut self,
application_permissions: ApplicationPermissions,
) -> Result<(), ChangeApplicationPermissionsError>
pub fn change_application_permissions( &mut self, application_permissions: ApplicationPermissions, ) -> Result<(), ChangeApplicationPermissionsError>
Changes the application permissions for the current chain.
Sourcepub fn create_application<Abi, Parameters, InstantiationArgument>(
&mut self,
module_id: ModuleId,
parameters: &Parameters,
argument: &InstantiationArgument,
required_application_ids: Vec<ApplicationId>,
) -> ApplicationId<Abi>
pub fn create_application<Abi, Parameters, InstantiationArgument>( &mut self, module_id: ModuleId, parameters: &Parameters, argument: &InstantiationArgument, required_application_ids: Vec<ApplicationId>, ) -> ApplicationId<Abi>
Creates a new on-chain application, based on the supplied module and parameters.
Sourcepub fn create_data_blob(&mut self, bytes: Vec<u8>) -> DataBlobHash
pub fn create_data_blob(&mut self, bytes: Vec<u8>) -> DataBlobHash
Creates a new data blob and returns its hash.
Sourcepub fn publish_module(
&mut self,
contract: Bytecode,
service: Bytecode,
vm_runtime: VmRuntime,
) -> ModuleId
pub fn publish_module( &mut self, contract: Bytecode, service: Bytecode, vm_runtime: VmRuntime, ) -> ModuleId
Publishes a module with contract and service bytecode and returns the module ID.
Sourcepub fn validation_round(&mut self) -> Option<u32>
pub fn validation_round(&mut self) -> Option<u32>
Returns the round in which this block was validated.
Trait Implementations§
Auto Trait Implementations§
impl<Application> Freeze for ContractRuntime<Application>
impl<Application> RefUnwindSafe for ContractRuntime<Application>where
<Application as Contract>::Parameters: RefUnwindSafe,
<Application as WithContractAbi>::Abi: RefUnwindSafe,
impl<Application> Send for ContractRuntime<Application>
impl<Application> Sync for ContractRuntime<Application>
impl<Application> Unpin for ContractRuntime<Application>
impl<Application> UnwindSafe for ContractRuntime<Application>where
<Application as Contract>::Parameters: UnwindSafe,
<Application as WithContractAbi>::Abi: UnwindSafe,
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
Source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
Source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length
bytes from memory from the provided location
.
Source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes
to memory at the provided location
.