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
impl PersistentWallet
Sourcepub async fn new(
inner: Arc<InMemoryWallet>,
store: Arc<dyn WalletStore>,
) -> Result<Self, Box<dyn Error + Send + Sync>>
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.
Sourcepub async fn save(&self) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn save(&self) -> Result<(), Box<dyn Error + Send + Sync>>
Save the current wallet state to the store.
Sourcepub async fn add_utxo(
&self,
utxo: UnspentOutput,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn add_utxo( &self, utxo: UnspentOutput, ) -> Result<(), Box<dyn Error + Send + Sync>>
Add a UTXO and persist.
Sourcepub async fn remove_utxos(
&self,
spent: &[OutPoint],
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn remove_utxos( &self, spent: &[OutPoint], ) -> Result<(), Box<dyn Error + Send + Sync>>
Remove spent UTXOs and persist.
Sourcepub fn inner(&self) -> &InMemoryWallet
pub fn inner(&self) -> &InMemoryWallet
Get a reference to the inner InMemoryWallet.