pub struct Memory(/* private fields */);Expand description
A basic implementation of Wallet that doesn’t persist anything and merely tracks the
chains in memory.
This can be used as-is as an ephemeral wallet for testing or ephemeral clients, or as a building block for more complex wallets that layer persistence on top of it.
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn get(&self, id: ChainId) -> Option<Chain>
pub fn get(&self, id: ChainId) -> Option<Chain>
Returns the state of the chain with the given ID, if it is tracked.
Sourcepub fn insert(&self, id: ChainId, chain: Chain) -> Option<Chain>
pub fn insert(&self, id: ChainId, chain: Chain) -> Option<Chain>
Inserts or replaces the state of the given chain, returning the previous state if any.
Sourcepub fn try_insert(&self, id: ChainId, chain: Chain) -> Option<Chain>
pub fn try_insert(&self, id: ChainId, chain: Chain) -> Option<Chain>
Inserts the given chain only if it is not already tracked, returning the existing state otherwise.
Sourcepub fn remove(&self, id: ChainId) -> Option<Chain>
pub fn remove(&self, id: ChainId) -> Option<Chain>
Removes the chain with the given ID, returning its previous state if any.
Sourcepub fn owned_chain_ids(&self) -> Vec<ChainId>
pub fn owned_chain_ids(&self) -> Vec<ChainId>
Returns the IDs of the tracked chains that have an owner configured.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Memory
impl<'de> Deserialize<'de> for Memory
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Extend<(ChainId, Chain)> for Memory
impl Extend<(ChainId, Chain)> for Memory
Source§fn extend<It: IntoIterator<Item = (ChainId, Chain)>>(&mut self, chains: It)
fn extend<It: IntoIterator<Item = (ChainId, Chain)>>(&mut self, chains: It)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Serialize for Memory
Custom Serialize implementation that ensures stable ordering by sorting entries by ChainId.
impl Serialize for Memory
Custom Serialize implementation that ensures stable ordering by sorting entries by ChainId.
Source§impl Wallet for Memory
impl Wallet for Memory
Source§type Error = Infallible
type Error = Infallible
Source§async fn get(&self, id: ChainId) -> Result<Option<Chain>, Self::Error>
async fn get(&self, id: ChainId) -> Result<Option<Chain>, Self::Error>
Source§async fn insert(
&self,
id: ChainId,
chain: Chain,
) -> Result<Option<Chain>, Self::Error>
async fn insert( &self, id: ChainId, chain: Chain, ) -> Result<Option<Chain>, Self::Error>
Source§async fn try_insert(
&self,
id: ChainId,
chain: Chain,
) -> Result<Option<Chain>, Self::Error>
async fn try_insert( &self, id: ChainId, chain: Chain, ) -> Result<Option<Chain>, Self::Error>
Source§async fn remove(&self, id: ChainId) -> Result<Option<Chain>, Self::Error>
async fn remove(&self, id: ChainId) -> Result<Option<Chain>, Self::Error>
Source§fn items(&self) -> impl Stream<Item = Result<(ChainId, Chain), Self::Error>>
fn items(&self) -> impl Stream<Item = Result<(ChainId, Chain), Self::Error>>
Source§async fn modify(
&self,
id: ChainId,
f: impl Fn(&mut Chain) + Send,
) -> Result<Option<()>, Self::Error>
async fn modify( &self, id: ChainId, f: impl Fn(&mut Chain) + Send, ) -> Result<Option<()>, Self::Error>
Ok(None) if the chain doesn’t exist. Read moreAuto Trait Implementations§
impl !Freeze for Memory
impl !UnwindSafe for Memory
impl RefUnwindSafe for Memory
impl Send for Memory
impl Sync for Memory
impl Unpin for Memory
impl UnsafeUnpin for Memory
Blanket Implementations§
impl<_INNER> AutoTraits for _INNER
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Requestimpl<T> MaybeSend for Twhere
T: Send,
impl<T> MaybeSync for Twhere
T: Sync,
impl<T> Post for Twhere
T: Send + 'static,
Source§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.