DomainClient

Struct DomainClient 

Source
pub struct DomainClient { /* private fields */ }
Expand description

Client to perform actions on a running domain.

The client is cloneable and can be shared across tasks. It provides methods to apply verifiable messages, submit state diffs to the base layer, and generate and submit proofs.

Without running the domain first, actions performed by the client cannot be executed.

Implementations§

Source§

impl DomainClient

Source

pub async fn apply( &self, messages: Vec<VerifiableWithDiffs>, ) -> Result<(), Error>

Apply state diffs to the vaults

Changes to the vaults are visible immediately locally. The resulting state diff is buffered until a call to Self::submit.

§Parameters
  • messages - The verifiable messages with diffs to be applied
§Returns

Ok(()) if application succeeded, or an Error if it failed

Source

pub async fn submit(&self) -> Result<Option<SdlId>, Error>

Submit all diffs that were applied since the last call to the base layer and return the hash of the resulting SDL.

§Returns
  • Ok(Some(sdl_id)) - If diffs were successfully submitted, returns the SDL id
  • Ok(None) - If there were no pending diffs to submit
  • Err(error) - If the submission failed
Source

pub async fn prove(&self, sdl_id: SdlId) -> Result<(), Error>

Prove the SDL specified by the hash.

Generates a proof for the SDL with the given hash and only returns once the proof is finished (or fails).

Use Self::prove_with_local_laws_input if you need to provide additional inputs for the local laws.

§Parameters
  • sdl_id - The id of the SDL to generate a proof for
§Returns

Ok(()) if proving succeeded, Error otherwise

Source

pub async fn prove_with_local_laws_input( &self, sdl_id: SdlId, local_laws_input: Box<dyn Serialize + Send + Sync>, ) -> Result<(), Error>

Prove the SDL specified by the hash with additional inputs.

Generates a proof for the SDL with the given hash and only returns once the proof is finished (or fails).

§Parameters
  • sdl_id - The id of the SDL to generate a proof for
  • local_laws_input - Additional inputs to the configured local laws
§Returns

Ok(()) if proving succeeded, Error otherwise

Source

pub async fn submit_proof(&self, sdl_id: SdlId) -> Result<(), Error>

Submit the proof of the SDL specified by the hash to the base layer.

§Parameters
  • sdl_id - The id of the SDL whose proof should be submitted
§Returns

Ok(()) if the proof was successfully submitted, or an Error if it failed

Source

pub fn updates(&self) -> Receiver<Update>

Subscribes to a stream of events from the running domain.

Source

pub async fn apply_prove_submit( &self, messages: Vec<VerifiableWithDiffs>, ) -> Result<Option<SdlId>, Error>

Shorthand to apply verifiables, submit an SDL, generate and submit a proof

This method combines the following:

  1. apply to apply verifiables to the vaults
  2. submit to batch the changes in an SDL and submit it to the base layer
  3. proving to start proving the SDL
  4. submit_proof to submit the proof to the base layer

This method does not allow setting additional inputs for the local laws.

§Parameters
  • messages - The verifiable messages to be applied
§Returns
  • Ok(Some(sdl_id)) - Success, an SDL with this id was created & proven
  • Ok(None) - Success but there were no state changes to submit
  • Err(error) - Any step in the process failed.
Source

pub async fn submit_domain_agreement( &self, new_shard_fee: Planck, ) -> Result<(), Error>

Submit a Domain Agreement for this domain.

Having an active domain agreement is a prerequisite to submit transactions to the base layer. You can check whether a domain agreement is already active with Self::check_valid_domain_agreement.

Note that after submitting the domain agreement, it still has to be applied on the base layer, before the domain is allowed to send transactions.

§Parameters
  • new_shard_fee - amount of native token that will be charged to the domain operator keys’s base layer vault for creation of the new shard
§Returns
Source

pub async fn check_valid_domain_agreement(&self) -> Result<(), Error>

Check that there is an active Domain Agreement for this domain.

This method can typically be used as a safe-guard before calling Self::submit or other methods that require an active domain agreement for transactions to be accepted.

§Returns
Source

pub async fn ensure_domain_agreement( &self, new_shard_fee: Planck, ) -> Result<(), Error>

Ensure that the domain has a valid Domain Agreement.

If no valid Domain Agreement is found, a new one will be submitted and awaited up to timeout.

§Parameters
  • new_shard_fee - amount of native token that will be charged to the domain operator keys’s base layer vault for creation of the new shard
  • interval - duration between polling for the the domain agreement
  • timeout - maximal duration to await the new domain agreement

Trait Implementations§

Source§

impl Clone for DomainClient

Source§

fn clone(&self) -> DomainClient

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 Debug for DomainClient

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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