Skip to main content

InMemoryWallet

Struct InMemoryWallet 

Source
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

Source

pub fn new(mainnet: bool, address_type: AddressType) -> Self

Create a new in-memory wallet.

Source

pub fn default_mainnet() -> Self

Create a default mainnet P2WPKH wallet.

Source

pub fn default_testnet() -> Self

Create a default testnet P2WPKH wallet.

Source

pub async fn add_utxo(&self, utxo: UnspentOutput)

Add a UTXO to the wallet.

Source

pub async fn remove_utxos(&self, spent_outpoints: &[OutPoint])

Remove spent UTXOs (by outpoints).

Source

pub async fn key_count(&self) -> usize

Get the number of keys in the wallet.

Source

pub fn is_mainnet(&self) -> bool

Whether this wallet uses mainnet addresses.

Source

pub fn address_type_str(&self) -> &str

Get the preferred address type as a string.

Source

pub fn parse_address_type(s: &str) -> Option<AddressType>

Parse an address type string back into an AddressType variant.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for InMemoryWallet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl WalletPort for InMemoryWallet

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