Skip to main content

Wallet

Trait Wallet 

Source
pub trait Wallet: Send {
    type Error: Error + Send + Sync;

    // Required methods
    fn get(
        &self,
        id: ChainId,
    ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send;
    fn remove(
        &self,
        id: ChainId,
    ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send;
    fn items(
        &self,
    ) -> impl Stream<Item = Result<(ChainId, Chain), Self::Error>> + Send;
    fn insert(
        &self,
        id: ChainId,
        chain: Chain,
    ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send;
    fn try_insert(
        &self,
        id: ChainId,
        chain: Chain,
    ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send;
    fn modify(
        &self,
        id: ChainId,
        f: impl Fn(&mut Chain) + Send,
    ) -> impl Future<Output = Result<Option<()>, Self::Error>> + Send;

    // Provided methods
    fn chain_ids(
        &self,
    ) -> impl Stream<Item = Result<ChainId, Self::Error>> + Send { ... }
    fn owned_chain_ids(
        &self,
    ) -> impl Stream<Item = Result<ChainId, Self::Error>> + Send { ... }
}
Expand description

A trait for the wallet (i.e. set of chain states) tracked by the client.

Required Associated Types§

Source

type Error: Error + Send + Sync

The error type returned by the wallet’s operations.

Required Methods§

Source

fn get( &self, id: ChainId, ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send

Returns the state of the chain with the given ID, if it is tracked.

Source

fn remove( &self, id: ChainId, ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send

Removes the chain with the given ID, returning its previous state if any.

Source

fn items( &self, ) -> impl Stream<Item = Result<(ChainId, Chain), Self::Error>> + Send

Returns a stream over all tracked chains and their states.

Source

fn insert( &self, id: ChainId, chain: Chain, ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send

Inserts or replaces the state of the given chain, returning the previous state if any.

Source

fn try_insert( &self, id: ChainId, chain: Chain, ) -> impl Future<Output = Result<Option<Chain>, Self::Error>> + Send

Inserts the given chain only if it is not already tracked, returning the existing state otherwise.

Source

fn modify( &self, id: ChainId, f: impl Fn(&mut Chain) + Send, ) -> impl Future<Output = Result<Option<()>, Self::Error>> + Send

Modifies a chain in the wallet. Returns Ok(None) if the chain doesn’t exist.

The closure may be called more than once (e.g. on CAS contention), so it must be idempotent. Fn (not FnMut) is required to discourage reliance on mutable captured state.

Provided Methods§

Source

fn chain_ids(&self) -> impl Stream<Item = Result<ChainId, Self::Error>> + Send

Returns a stream over the IDs of all tracked chains.

Source

fn owned_chain_ids( &self, ) -> impl Stream<Item = Result<ChainId, Self::Error>> + Send

Returns a stream over the IDs of the tracked chains that have an owner.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§