Struct bdk::wallet::Wallet[][src]

pub struct Wallet<B, D> { /* fields omitted */ }
Expand description

A Bitcoin wallet

A wallet takes descriptors, a database and a blockchain and implements the basic functions that a Bitcoin wallets needs to operate, like generating addresses, returning the balance, creating transactions, etc.

A wallet can be either “online” if the blockchain type provided implements Blockchain, or “offline” if it is the unit type (). Offline wallets only expose methods that don’t need any interaction with the blockchain to work.

Implementations

Create a new “offline” wallet

Get the Bitcoin network the wallet is using.

Return a derived address using the external descriptor, see AddressIndex for available address index selection strategies. If none of the keys in the descriptor are derivable (ie. does not end with /*) then the same address will always be returned for any AddressIndex.

Return whether or not a script is part of this wallet (either internal or external)

Return the list of unspent outputs of this wallet

Note that this methods only operate on the internal database, which first needs to be Wallet::sync manually.

Returns the UTXO owned by this wallet corresponding to outpoint if it exists in the wallet’s database.

Return the list of transactions made and received by the wallet

Optionally fill the TransactionDetails::transaction field with the raw transaction if include_raw is true.

Note that this methods only operate on the internal database, which first needs to be Wallet::sync manually.

Return the balance, meaning the sum of this wallet’s unspent outputs’ values

Note that this methods only operate on the internal database, which first needs to be Wallet::sync manually.

Add an external signer

See the signer module for an example.

Add an address validator

See the address_validator module for an example.

Start building a transaction.

This returns a blank TxBuilder from which you can specify the parameters for the transaction.

Example

let (psbt, details) = {
   let mut builder =  wallet.build_tx();
   builder
       .add_recipient(to_address.script_pubkey(), 50_000);
   builder.finish()?
};

// sign and broadcast ...

Bump the fee of a transaction previously created with this wallet.

Returns an error if the transaction is already confirmed or doesn’t explicitly signal repalce by fee (RBF). If the transaction can be fee bumped then it returns a TxBuilder pre-populated with the inputs and outputs of the original transaction.

Example

let (mut psbt, _) = {
    let mut builder = wallet.build_tx();
    builder
        .add_recipient(to_address.script_pubkey(), 50_000)
        .enable_rbf();
    builder.finish()?
};
let _ = wallet.sign(&mut psbt, SignOptions::default())?;
let tx = psbt.extract_tx();
// broadcast tx but it's taking too long to confirm so we want to bump the fee
let (mut psbt, _) =  {
    let mut builder = wallet.build_fee_bump(tx.txid())?;
    builder
        .fee_rate(FeeRate::from_sat_per_vb(5.0));
    builder.finish()?
};

let _ = wallet.sign(&mut psbt, SignOptions::default())?;
let fee_bumped_tx = psbt.extract_tx();
// broadcast fee_bumped_tx to replace original

Sign a transaction with all the wallet’s signers, in the order specified by every signer’s SignerOrdering

The SignOptions can be used to tweak the behavior of the software signers, and the way the transaction is finalized at the end. Note that it can’t be guaranteed that every signers will follow the options, but the “software signers” (WIF keys and xprv) defined in this library will.

Example

let (mut psbt, _) = {
    let mut builder = wallet.build_tx();
    builder.add_recipient(to_address.script_pubkey(), 50_000);
    builder.finish()?
};
let  finalized = wallet.sign(&mut psbt, SignOptions::default())?;
assert!(finalized, "we should have signed all the inputs");

Return the spending policies for the wallet’s descriptor

Return the “public” version of the wallet’s descriptor, meaning a new descriptor that has the same structure but with every secret key removed

This can be used to build a watch-only version of a wallet

Try to finalize a PSBT

The SignOptions can be used to tweak the behavior of the finalizer.

Return the secp256k1 context used for all signing operations

Returns the descriptor used to create adddresses for a particular keychain.

get the corresponding PSBT Input for a LocalUtxo

Create a new “online” wallet

Sync the internal database with the blockchain

Return a reference to the internal blockchain client

Broadcast a transaction to the network

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.