ChainClient

Struct ChainClient 

Source
pub struct ChainClient<Env: Environment> { /* private fields */ }
Expand description

Client to operate a chain by interacting with validators and the given local storage implementation.

  • The chain being operated is called the “local chain” or just the “chain”.
  • As a rule, operations are considered successful (and communication may stop) when they succeeded in gathering a quorum of responses.

Implementations§

Source§

impl<Env: Environment> ChainClient<Env>

Source

pub fn pending_proposal(&self) -> Option<PendingProposal>

Gets the next pending block.

Source

pub fn signer(&self) -> &impl Signer

Gets a reference to the client’s signer instance.

Source

pub fn options_mut(&mut self) -> &mut ChainClientOptions

Gets a mutable reference to the per-ChainClient options.

Source

pub fn options(&self) -> &ChainClientOptions

Gets a reference to the per-ChainClient options.

Source

pub fn chain_id(&self) -> ChainId

Gets the ID of the associated chain.

Source

pub fn timing_sender(&self) -> Option<UnboundedSender<(u64, TimingType)>>

Gets a clone of the timing sender for benchmarking.

Source

pub fn admin_id(&self) -> ChainId

Gets the ID of the admin chain.

Source

pub fn preferred_owner(&self) -> Option<AccountOwner>

Gets the currently preferred owner for signing the blocks.

Source

pub fn set_preferred_owner(&mut self, preferred_owner: AccountOwner)

Sets the new, preferred owner for signing the blocks.

Source

pub fn unset_preferred_owner(&mut self)

Unsets the preferred owner for signing the blocks.

Source

pub async fn chain_state_view( &self, ) -> Result<OwnedRwLockReadGuard<ChainStateView<Env::StorageContext>>, LocalNodeError>

Obtains a ChainStateView for this client’s chain.

Source

pub async fn event_stream_publishers( &self, ) -> Result<BTreeSet<ChainId>, LocalNodeError>

Returns chain IDs that this chain subscribes to.

Source

pub fn subscribe(&self) -> Result<NotificationStream, LocalNodeError>

Subscribes to notifications from this client’s chain.

Source

pub fn subscribe_to( &self, chain_id: ChainId, ) -> Result<NotificationStream, LocalNodeError>

Subscribes to notifications from the specified chain.

Source

pub fn storage_client(&self) -> &Env::Storage

Returns the storage client used by this client’s local node.

Source

pub async fn chain_info(&self) -> Result<Box<ChainInfo>, LocalNodeError>

Obtains the basic ChainInfo data for the local chain.

Source

pub async fn get_chain_description( &self, ) -> Result<ChainDescription, ChainClientError>

Returns the chain’s description. Fetches it from the validators if necessary.

Source

pub async fn local_committee(&self) -> Result<Committee, ChainClientError>

Obtains the committee for the current epoch of the local chain.

Source

pub async fn admin_committee( &self, ) -> Result<(Epoch, Committee), LocalNodeError>

Obtains the committee for the latest epoch on the admin chain.

Source

pub async fn identity(&self) -> Result<AccountOwner, ChainClientError>

Obtains the identity of the current owner of the chain.

Returns an error if we don’t have the private key for the identity.

Source

pub async fn prepare_chain(&self) -> Result<Box<ChainInfo>, ChainClientError>

Prepares the chain for the next operation, i.e. makes sure we have synchronized it up to its current height and are not missing any received messages from the inbox.

Source

pub async fn submit_fast_block_proposal( &self, committee: &Committee, operations: &[Operation], incoming_bundles: &[IncomingBundle], super_owner: AccountOwner, ) -> Result<(u64, u64, u64, u64), ChainClientError>

Submits a fast block proposal to the validators.

This must only be used with valid epoch and super owner.

Source

pub async fn update_validators( &self, old_committee: Option<&Committee>, ) -> Result<(), ChainClientError>

Attempts to update all validators about the local chain.

Source

pub async fn communicate_chain_updates( &self, committee: &Committee, ) -> Result<(), ChainClientError>

Broadcasts certified blocks to validators.

Source

pub async fn transfer( &self, owner: AccountOwner, amount: Amount, recipient: Account, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Sends money.

Source

pub async fn read_data_blob( &self, hash: CryptoHash, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Verify if a data blob is readable from storage.

Source

pub async fn claim( &self, owner: AccountOwner, target_id: ChainId, recipient: Account, amount: Amount, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Claims money in a remote chain.

Source

pub async fn request_leader_timeout( &self, ) -> Result<TimeoutCertificate, ChainClientError>

Requests a leader timeout vote from all validators. If a quorum signs it, creates a certificate and sends it to all validators, to make them enter the next round.

Source

pub async fn synchronize_chain_state( &self, chain_id: ChainId, ) -> Result<Box<ChainInfo>, ChainClientError>

Downloads and processes any certificates we are missing for the given chain.

Source

pub async fn synchronize_chain_state_from_committee( &self, committee: Committee, ) -> Result<Box<ChainInfo>, ChainClientError>

Downloads and processes any certificates we are missing for this chain, from the given committee.

Source

pub async fn execute_operations( &self, operations: Vec<Operation>, blobs: Vec<Blob>, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Executes a list of operations.

Source

pub async fn execute_operation( &self, operation: impl Into<Operation>, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Executes an operation.

Source

pub async fn query_application( &self, query: Query, ) -> Result<QueryOutcome, ChainClientError>

Queries an application.

Source

pub async fn query_system_application( &self, query: SystemQuery, ) -> Result<QueryOutcome<SystemResponse>, ChainClientError>

Queries a system application.

Source

pub async fn query_user_application<A: Abi>( &self, application_id: ApplicationId<A>, query: &A::Query, ) -> Result<QueryOutcome<A::QueryResponse>, ChainClientError>

Queries a user application.

Source

pub async fn query_balance(&self) -> Result<Amount, ChainClientError>

Obtains the local balance of the chain account after staging the execution of incoming messages in a new block.

Does not attempt to synchronize with validators. The result will reflect up to max_pending_message_bundles incoming message bundles and the execution fees for a single block.

Source

pub async fn query_owner_balance( &self, owner: AccountOwner, ) -> Result<Amount, ChainClientError>

Obtains the local balance of an account after staging the execution of incoming messages in a new block.

Does not attempt to synchronize with validators. The result will reflect up to max_pending_message_bundles incoming message bundles and the execution fees for a single block.

Source

pub async fn local_balance(&self) -> Result<Amount, ChainClientError>

Reads the local balance of the chain account.

Does not process the inbox or attempt to synchronize with validators.

Source

pub async fn local_owner_balance( &self, owner: AccountOwner, ) -> Result<Amount, ChainClientError>

Reads the local balance of a user account.

Does not process the inbox or attempt to synchronize with validators.

Source

pub async fn transfer_to_account( &self, from: AccountOwner, amount: Amount, account: Account, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Sends tokens to a chain.

Source

pub async fn fetch_chain_info(&self) -> Result<Box<ChainInfo>, ChainClientError>

Source

pub async fn synchronize_from_validators( &self, ) -> Result<Box<ChainInfo>, ChainClientError>

Attempts to synchronize chains that have sent us messages and populate our local inbox.

To create a block that actually executes the messages in the inbox, process_inbox must be called separately.

Source

pub async fn process_pending_block( &self, ) -> Result<ClientOutcome<Option<ConfirmedBlockCertificate>>, ChainClientError>

Processes the last pending block

Source

pub async fn receive_certificate_and_update_validators( &self, certificate: ConfirmedBlockCertificate, ) -> Result<(), ChainClientError>

Processes a confirmed block for which this chain is a recipient and updates validators.

Source

pub async fn rotate_key_pair( &self, public_key: AccountPublicKey, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Rotates the key of the chain.

Replaces current owners of the chain with the new key pair.

Source

pub async fn transfer_ownership( &self, new_owner: AccountOwner, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Transfers ownership of the chain to a single super owner.

Source

pub async fn share_ownership( &self, new_owner: AccountOwner, new_weight: u64, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Adds another owner to the chain, and turns existing super owners into regular owners.

Source

pub async fn change_ownership( &self, ownership: ChainOwnership, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Changes the ownership of this chain. Fails if it would remove existing owners, unless remove_owners is true.

Source

pub async fn change_application_permissions( &self, application_permissions: ApplicationPermissions, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Changes the application permissions configuration on this chain.

Source

pub async fn open_chain( &self, ownership: ChainOwnership, application_permissions: ApplicationPermissions, balance: Amount, ) -> Result<ClientOutcome<(ChainDescription, ConfirmedBlockCertificate)>, ChainClientError>

Opens a new chain with a derived UID.

Source

pub async fn close_chain( &self, ) -> Result<ClientOutcome<Option<ConfirmedBlockCertificate>>, ChainClientError>

Closes the chain (and loses everything in it!!). Returns None if the chain was already closed.

Source

pub async fn publish_module( &self, contract: Bytecode, service: Bytecode, vm_runtime: VmRuntime, ) -> Result<ClientOutcome<(ModuleId, ConfirmedBlockCertificate)>, ChainClientError>

Publishes some module.

Source

pub async fn publish_module_blobs( &self, blobs: Vec<Blob>, module_id: ModuleId, ) -> Result<ClientOutcome<(ModuleId, ConfirmedBlockCertificate)>, ChainClientError>

Publishes some module.

Source

pub async fn publish_data_blobs( &self, bytes: Vec<Vec<u8>>, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Publishes some data blobs.

Source

pub async fn publish_data_blob( &self, bytes: Vec<u8>, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Publishes some data blob.

Source

pub async fn create_application<A: Abi, Parameters: Serialize, InstantiationArgument: Serialize>( &self, module_id: ModuleId<A, Parameters, InstantiationArgument>, parameters: &Parameters, instantiation_argument: &InstantiationArgument, required_application_ids: Vec<ApplicationId>, ) -> Result<ClientOutcome<(ApplicationId<A>, ConfirmedBlockCertificate)>, ChainClientError>

Creates an application by instantiating some bytecode.

Source

pub async fn create_application_untyped( &self, module_id: ModuleId, parameters: Vec<u8>, instantiation_argument: Vec<u8>, required_application_ids: Vec<ApplicationId>, ) -> Result<ClientOutcome<(ApplicationId, ConfirmedBlockCertificate)>, ChainClientError>

Creates an application by instantiating some bytecode.

Source

pub async fn stage_new_committee( &self, committee: Committee, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Creates a new committee and starts using it (admin chains only).

Source

pub async fn process_inbox( &self, ) -> Result<(Vec<ConfirmedBlockCertificate>, Option<RoundTimeout>), ChainClientError>

Synchronizes the chain with the validators and creates blocks without any operations to process all incoming messages. This may require several blocks.

If not all certificates could be processed due to a timeout, the timestamp for when to retry is returned, too.

Source

pub async fn process_inbox_without_prepare( &self, ) -> Result<(Vec<ConfirmedBlockCertificate>, Option<RoundTimeout>), ChainClientError>

Creates blocks without any operations to process all incoming messages. This may require several blocks.

If not all certificates could be processed due to a timeout, the timestamp for when to retry is returned, too.

Source

pub async fn events_from_index( &self, stream_id: StreamId, start_index: u32, ) -> Result<Vec<IndexAndEvent>, ChainClientError>

Returns the indices and events from the storage

Source

pub async fn revoke_epochs( &self, revoked_epoch: Epoch, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Deprecates all the configurations of voting rights up to the given one (admin chains only). Currently, each individual chain is still entitled to wait before accepting this command. However, it is expected that deprecated validators stop functioning shortly after such command is issued.

Source

pub async fn transfer_to_account_unsafe_unconfirmed( &self, owner: AccountOwner, amount: Amount, recipient: Account, ) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError>

Sends money to a chain. Do not check balance. (This may block the client) Do not confirm the transaction.

Source

pub async fn read_confirmed_block( &self, hash: CryptoHash, ) -> Result<ConfirmedBlock, ChainClientError>

Source

pub async fn retry_pending_outgoing_messages( &self, ) -> Result<(), ChainClientError>

Handles any cross-chain requests for any pending outgoing messages.

Source

pub fn is_tracked(&self) -> bool

Returns whether this chain is tracked by the client, i.e. we are updating its inbox.

Source

pub async fn listen( &self, ) -> Result<(impl Future<Output = ()>, AbortOnDrop, NotificationStream), ChainClientError>

Spawns a task that listens to notifications about the current chain from all validators, and synchronizes the local state accordingly.

Source

pub async fn sync_validator( &self, remote_node: Env::ValidatorNode, ) -> Result<(), ChainClientError>

Attempts to update a validator with the local information.

Trait Implementations§

Source§

impl<Env: Environment> Clone for ChainClient<Env>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Env: Environment> Debug for ChainClient<Env>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Env> Freeze for ChainClient<Env>

§

impl<Env> RefUnwindSafe for ChainClient<Env>

§

impl<Env> Send for ChainClient<Env>

§

impl<Env> Sync for ChainClient<Env>

§

impl<Env> Unpin for ChainClient<Env>

§

impl<Env> UnwindSafe for ChainClient<Env>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<_INNER> AutoTraits for _INNER
where _INNER: Send + Sync + 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Post for T
where T: Send + Sync,