ContractRuntime

Struct ContractRuntime 

Source
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,

Source

pub fn key_value_store(&self) -> KeyValueStore

Returns the key-value store to interface with storage.

Source

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,

Source

pub fn application_parameters(&mut self) -> Application::Parameters

Returns the application parameters provided when the application was created.

Source

pub fn application_id(&mut self) -> ApplicationId<Application::Abi>

Returns the ID of the current application.

Source

pub fn application_creator_chain_id(&mut self) -> ChainId

Returns the chain ID of the current application creator.

Source

pub fn chain_id(&mut self) -> ChainId

Returns the ID of the current chain.

Source

pub fn block_height(&mut self) -> BlockHeight

Returns the height of the current block that is executing.

Source

pub fn system_time(&mut self) -> Timestamp

Retrieves the current system time, i.e. the timestamp of the block in which this is called.

Source

pub fn chain_balance(&mut self) -> Amount

Returns the current chain balance.

Source

pub fn owner_balance(&mut self, owner: AccountOwner) -> Amount

Returns the balance of one of the accounts on this chain.

Source

pub fn chain_ownership(&mut self) -> ChainOwnership

Retrieves the owner configuration for the current chain.

Source

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.

Source

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.

Source

pub fn read_data_blob(&mut self, hash: DataBlobHash) -> Vec<u8>

Reads a data blob with the given hash from storage.

Source

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,

Source

pub fn authenticated_signer(&mut self) -> Option<AccountOwner>

Returns the authenticated signer for this execution, if there is one.

Source

pub fn message_is_bouncing(&mut self) -> Option<bool>

Returns true if the incoming message was rejected from the original destination and is now bouncing back, or None if not executing an incoming message.

Source

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.

Source

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.

Source

pub fn check_account_permission( &mut self, owner: AccountOwner, ) -> Result<(), AccountPermissionError>

Verifies that the current execution context authorizes operations on a given account.

Source

pub fn send_message( &mut self, destination: ChainId, message: Application::Message, )

Schedules a message to be sent to this application on another chain.

Source

pub fn prepare_message( &mut self, message: Application::Message, ) -> MessageBuilder<Application::Message>

Returns a MessageBuilder to prepare a message to be sent.

Source

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.

Source

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.

Source

pub fn call_application<A: ContractAbi + Send>( &mut self, authenticated: bool, application: ApplicationId<A>, call: &A::Operation, ) -> A::Response

Calls another application.

Source

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.

Source

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.

Source

pub fn subscribe_to_events( &mut self, chain_id: ChainId, application_id: ApplicationId, name: StreamName, )

Subscribes this application to an event stream.

Source

pub fn unsubscribe_from_events( &mut self, chain_id: ChainId, application_id: ApplicationId, name: StreamName, )

Unsubscribes this application from an event stream.

Source

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.

Source

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).

Source

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.

Source

pub fn change_application_permissions( &mut self, application_permissions: ApplicationPermissions, ) -> Result<(), ChangeApplicationPermissionsError>

Changes the application permissions for the current chain.

Source

pub fn create_application<Abi, Parameters, InstantiationArgument>( &mut self, module_id: ModuleId, parameters: &Parameters, argument: &InstantiationArgument, required_application_ids: Vec<ApplicationId>, ) -> ApplicationId<Abi>
where Abi: ContractAbi, Parameters: Serialize, InstantiationArgument: Serialize,

Creates a new on-chain application, based on the supplied module and parameters.

Source

pub fn create_data_blob(&mut self, bytes: Vec<u8>) -> DataBlobHash

Creates a new data blob and returns its hash.

Source

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.

Source

pub fn validation_round(&mut self) -> Option<u32>

Returns the round in which this block was validated.

Trait Implementations§

Source§

impl<Application> Debug for ContractRuntime<Application>
where Application: Contract + Debug, Application::Parameters: Debug, Application::Abi: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Application> Freeze for ContractRuntime<Application>
where <Application as Contract>::Parameters: Freeze,

§

impl<Application> RefUnwindSafe for ContractRuntime<Application>
where <Application as Contract>::Parameters: RefUnwindSafe, <Application as WithContractAbi>::Abi: RefUnwindSafe,

§

impl<Application> Send for ContractRuntime<Application>
where <Application as Contract>::Parameters: Send, <Application as WithContractAbi>::Abi: Send,

§

impl<Application> Sync for ContractRuntime<Application>
where <Application as Contract>::Parameters: Sync, <Application as WithContractAbi>::Abi: Sync,

§

impl<Application> Unpin for ContractRuntime<Application>
where <Application as Contract>::Parameters: Unpin, <Application as WithContractAbi>::Abi: Unpin,

§

impl<Application> UnwindSafe for ContractRuntime<Application>
where <Application as Contract>::Parameters: UnwindSafe, <Application as WithContractAbi>::Abi: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more
Source§

impl<To, From> DynInto<To> for From
where From: Into<To>,

Source§

fn into_box(self: Box<From>) -> To

Converts a boxed object into the target type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<M, I> RuntimeMemory<&mut I> for M
where M: RuntimeMemory<I>,

Source§

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>

Writes the bytes to memory at the provided location.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
Source§

impl<AnyTail> Split<HNil> for AnyTail

Source§

type Remainder = AnyTail

The tail of remaining elements after splitting up the list.
Source§

fn split(self) -> (HNil, <AnyTail as Split<HNil>>::Remainder)

Splits the current heterogeneous list in two.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more