pub struct InMemoryWallet { /* private fields */ }Expand description
In-memory wallet implementation
Tracks private keys and unspent outputs. Keys are stored in memory (NOT suitable for production use — keys should be encrypted/in HSM).
Implementations§
Source§impl InMemoryWallet
impl InMemoryWallet
Sourcepub fn new(mainnet: bool, address_type: AddressType) -> Self
pub fn new(mainnet: bool, address_type: AddressType) -> Self
Create a new in-memory wallet.
Sourcepub fn default_mainnet() -> Self
pub fn default_mainnet() -> Self
Create a default mainnet P2WPKH wallet.
Sourcepub fn default_testnet() -> Self
pub fn default_testnet() -> Self
Create a default testnet P2WPKH wallet.
Sourcepub async fn add_utxo(&self, utxo: UnspentOutput)
pub async fn add_utxo(&self, utxo: UnspentOutput)
Add a UTXO to the wallet.
Sourcepub async fn remove_utxos(&self, spent_outpoints: &[OutPoint])
pub async fn remove_utxos(&self, spent_outpoints: &[OutPoint])
Remove spent UTXOs (by outpoints).
Sourcepub fn is_mainnet(&self) -> bool
pub fn is_mainnet(&self) -> bool
Whether this wallet uses mainnet addresses.
Sourcepub fn address_type_str(&self) -> &str
pub fn address_type_str(&self) -> &str
Get the preferred address type as a string.
Sourcepub fn parse_address_type(s: &str) -> Option<AddressType>
pub fn parse_address_type(s: &str) -> Option<AddressType>
Parse an address type string back into an AddressType variant.
Sourcepub async fn snapshot(&self) -> WalletSnapshot
pub async fn snapshot(&self) -> WalletSnapshot
Create a snapshot of the current wallet state for persistence.
Serializes keys (as WIF), UTXOs (as hex), and metadata into a plain data container that can be saved to disk.
Sourcepub async fn restore_from_snapshot(
&self,
snapshot: &WalletSnapshot,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn restore_from_snapshot( &self, snapshot: &WalletSnapshot, ) -> Result<(), Box<dyn Error + Send + Sync>>
Restore wallet state from a previously saved snapshot.
Parses WIF keys, reconstructs addresses, rebuilds UTXOs, and restores the key counter. Existing state is replaced.