Skip to main content

PersistentWallet

Struct PersistentWallet 

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

A wallet that automatically persists state to a WalletStore after mutations.

Wraps an InMemoryWallet and a WalletStore implementation. All read operations delegate directly to the inner wallet. Write operations (key generation, key import, transaction broadcast) trigger an automatic save after the operation completes.

§Construction

Use PersistentWallet::new() to create a persistent wallet. If the store contains previously saved state, it will be loaded into the inner wallet.

Implementations§

Source§

impl PersistentWallet

Source

pub async fn new( inner: Arc<InMemoryWallet>, store: Arc<dyn WalletStore>, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Create a persistent wallet, loading any existing state from the store.

If the store contains a saved snapshot, it is restored into the inner wallet. If the store is empty (first run), the wallet starts fresh.

Source

pub async fn save(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Save the current wallet state to the store.

Source

pub async fn add_utxo( &self, utxo: UnspentOutput, ) -> Result<(), Box<dyn Error + Send + Sync>>

Add a UTXO and persist.

Source

pub async fn remove_utxos( &self, spent: &[OutPoint], ) -> Result<(), Box<dyn Error + Send + Sync>>

Remove spent UTXOs and persist.

Source

pub async fn key_count(&self) -> usize

Get the number of keys in the wallet.

Source

pub fn inner(&self) -> &InMemoryWallet

Get a reference to the inner InMemoryWallet.

Trait Implementations§

Source§

impl WalletPort for PersistentWallet

Source§

fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Balance, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets the wallet’s current balance. Read more
Source§

fn list_unspent<'life0, 'async_trait>( &'life0 self, min_confirmations: u32, max_amount: Option<Amount>, ) -> Pin<Box<dyn Future<Output = Result<Vec<UnspentOutput>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists all unspent outputs (UTXOs) controlled by the wallet. Read more
Source§

fn create_transaction<'life0, 'async_trait>( &'life0 self, to: Vec<(String, Amount)>, fee_rate: Option<f64>, ) -> Pin<Box<dyn Future<Output = Result<Transaction, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Creates a transaction sending to specified addresses. Read more
Source§

fn sign_transaction<'life0, 'life1, 'async_trait>( &'life0 self, tx: &'life1 Transaction, ) -> Pin<Box<dyn Future<Output = Result<Transaction, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Signs a transaction with wallet keys. Read more
Source§

fn send_transaction<'life0, 'life1, 'async_trait>( &'life0 self, tx: &'life1 Transaction, ) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Broadcasts a signed transaction to the network. Read more
Source§

fn get_new_address<'life0, 'life1, 'async_trait>( &'life0 self, label: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generates a new address for receiving funds. Read more
Source§

fn import_key<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, privkey_wif: &'life1 str, label: Option<&'life2 str>, rescan: bool, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Imports a private key into the wallet. Read more
Source§

fn get_transaction_history<'life0, 'async_trait>( &'life0 self, count: u32, skip: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<Transaction>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets transaction history for the wallet. 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> 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> Same for T

Source§

type Output = T

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