Wallet

Trait Wallet 

Source
pub trait Wallet {
    // Required methods
    fn get_new_address(
        &self,
    ) -> impl Future<Output = ClientResult<Address>> + Send;
    fn get_transaction(
        &self,
        txid: &Txid,
    ) -> impl Future<Output = ClientResult<GetTransaction>> + Send;
    fn get_utxos(
        &self,
    ) -> impl Future<Output = ClientResult<Vec<ListUnspent>>> + Send;
    fn list_transactions(
        &self,
        count: Option<usize>,
    ) -> impl Future<Output = ClientResult<Vec<ListTransactions>>> + Send;
    fn list_wallets(
        &self,
    ) -> impl Future<Output = ClientResult<Vec<String>>> + Send;
    fn create_raw_transaction(
        &self,
        raw_tx: CreateRawTransaction,
    ) -> impl Future<Output = ClientResult<Transaction>> + Send;
    fn wallet_create_funded_psbt(
        &self,
        inputs: &[CreateRawTransactionInput],
        outputs: &[CreateRawTransactionOutput],
        locktime: Option<u32>,
        options: Option<WalletCreateFundedPsbtOptions>,
        bip32_derivs: Option<bool>,
    ) -> impl Future<Output = ClientResult<WalletCreateFundedPsbt>> + Send;
    fn get_address_info(
        &self,
        address: &Address,
    ) -> impl Future<Output = ClientResult<GetAddressInfo>> + Send;
    fn list_unspent(
        &self,
        min_conf: Option<u32>,
        max_conf: Option<u32>,
        addresses: Option<&[Address]>,
        include_unsafe: Option<bool>,
        query_options: Option<ListUnspentQueryOptions>,
    ) -> impl Future<Output = ClientResult<Vec<ListUnspent>>> + Send;
}
Expand description

Wallet functionality that any Bitcoin client without private keys that interacts with the Bitcoin network should provide.

For signing transactions, see Signer.

§Note

This is a fully async trait. The user should be responsible for handling the async nature of the trait methods. And if implementing this trait for a specific type that is not async, the user should consider wrapping with tokio’s spawn_blocking or any other method.

Required Methods§

Source

fn get_new_address(&self) -> impl Future<Output = ClientResult<Address>> + Send

Generates new address under own control for the underlying Bitcoin client’s wallet.

Source

fn get_transaction( &self, txid: &Txid, ) -> impl Future<Output = ClientResult<GetTransaction>> + Send

Gets information related to a transaction.

§Note

This assumes that the transaction is present in the underlying Bitcoin client’s wallet.

Source

fn get_utxos( &self, ) -> impl Future<Output = ClientResult<Vec<ListUnspent>>> + Send

👎Deprecated since 0.4.0: Does not adhere with bitcoin core RPC naming. Use list_unspent instead

Gets all Unspent Transaction Outputs (UTXOs) for the underlying Bitcoin client’s wallet.

Source

fn list_transactions( &self, count: Option<usize>, ) -> impl Future<Output = ClientResult<Vec<ListTransactions>>> + Send

Lists transactions in the underlying Bitcoin client’s wallet.

§Parameters
  • count: The number of transactions to list. If None, assumes a maximum of 10 transactions.
Source

fn list_wallets(&self) -> impl Future<Output = ClientResult<Vec<String>>> + Send

Lists all wallets in the underlying Bitcoin client.

Source

fn create_raw_transaction( &self, raw_tx: CreateRawTransaction, ) -> impl Future<Output = ClientResult<Transaction>> + Send

Creates a raw transaction.

Source

fn wallet_create_funded_psbt( &self, inputs: &[CreateRawTransactionInput], outputs: &[CreateRawTransactionOutput], locktime: Option<u32>, options: Option<WalletCreateFundedPsbtOptions>, bip32_derivs: Option<bool>, ) -> impl Future<Output = ClientResult<WalletCreateFundedPsbt>> + Send

Creates and funds a PSBT with inputs and outputs from the wallet.

Uses the wallet’s UTXOs to automatically fund the specified outputs, creating a partially signed Bitcoin transaction that can be further processed or signed.

§Parameters
  • inputs: Array of specific transaction inputs to include (can be empty for automatic selection).
  • outputs: Array of transaction outputs, supporting both address-amount pairs and OP_RETURN data.
  • locktime: Optional locktime for the transaction (0 = no locktime).
  • options: Optional funding options including fee rate, change address, and confirmation targets.
  • bip32_derivs: Whether to include BIP32 derivation paths in the PSBT for signing.
§Returns

Returns a WalletCreateFundedPsbt containing the funded PSBT, calculated fee, and change output position.

§Note

The returned PSBT is not signed and requires further processing with wallet_process_psbt or finalize_psbt before it can be broadcast to the network.

Source

fn get_address_info( &self, address: &Address, ) -> impl Future<Output = ClientResult<GetAddressInfo>> + Send

Returns detailed information about the given address.

Queries the wallet for comprehensive information about a Bitcoin address, including ownership status, spending capabilities, and script details. This is useful for determining if an address belongs to the wallet and how it can be used for transactions.

§Parameters
  • address: The Bitcoin address to analyze (any valid Bitcoin address format).
§Returns

Returns a GetAddressInfo containing:

  • Address ownership status (is_mine)
  • Watch-only status (is_watchonly)
  • Spending capability (solvable)
  • The queried address for confirmation
§Note

The address doesn’t need to belong to the wallet to query information about it. However, detailed ownership and spending information will only be available for addresses that the wallet knows about.

Source

fn list_unspent( &self, min_conf: Option<u32>, max_conf: Option<u32>, addresses: Option<&[Address]>, include_unsafe: Option<bool>, query_options: Option<ListUnspentQueryOptions>, ) -> impl Future<Output = ClientResult<Vec<ListUnspent>>> + Send

Lists unspent transaction outputs with filtering options.

Queries the wallet for unspent transaction outputs (UTXOs) with comprehensive filtering capabilities. This is essential for coin selection, balance calculation, and preparing transaction inputs. Provides fine-grained control over which UTXOs are returned based on confirmations, addresses, safety, and amounts.

§Parameters
  • min_conf: Minimum number of confirmations required (default: 1). Use 0 for unconfirmed outputs.
  • max_conf: Maximum number of confirmations to include (default: 9,999,999). Limits how old UTXOs can be.
  • addresses: Optional list of specific addresses to filter by. If provided, only UTXOs from these addresses are returned.
  • include_unsafe: Whether to include outputs that are not safe to spend (default: true). Unsafe outputs include unconfirmed transactions from external keys.
  • query_options: Additional filtering options for amount ranges and result limits via ListUnspentQueryOptions.
§Returns

Returns a vector of ListUnspent containing:

  • Transaction ID and output index (txid, vout)
  • Bitcoin address and amount (address, amount)
  • Confirmation count and safety status (confirmations, safe)
  • Spendability information (spendable, solvable)
  • Script details (script_pubkey, label)
§Note

UTXOs must satisfy ALL specified criteria to be included in results. This method is commonly used for wallet balance calculation and transaction preparation. Consider using query_options for amount-based filtering to optimize coin selection strategies.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§