Wallet

A Bitcoin wallet.

The Wallet acts as a way of coherently interfacing with output descriptors and related transactions. Its main components are:

  1. output descriptors from which it can derive addresses.

  2. signers that can contribute signatures to addresses instantiated from the descriptors.

The user is responsible for loading and writing wallet changes which are represented as ChangeSets (see take_staged). Also see individual functions and example for instructions on when Wallet state needs to be persisted.

The Wallet descriptor (external) and change descriptor (internal) must not derive the same script pubkeys. See KeychainTxOutIndex::insert_descriptor() for more details.

Constructors

Link copied to clipboard
constructor(pointer: Pointer)
constructor(noPointer: NoPointer)

This constructor can be used to instantiate a fake object. Only used for tests. Any attempt to actually use an object constructed this way will fail as there is no connected Rust object.

constructor(descriptor: Descriptor, changeDescriptor: Descriptor, network: Network, connection: Connection)

Build a new Wallet.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun applyUnconfirmedTxs(unconfirmedTxs: List<UnconfirmedTx>)

Apply relevant unconfirmed transactions to the wallet. Transactions that are not relevant are filtered out.

Link copied to clipboard
open override fun applyUpdate(update: Update)

Applies an update to the wallet and stages the changes (but does not persist them).

Link copied to clipboard
open override fun balance(): Balance

Return the balance, separated into available, trusted-pending, untrusted-pending and immature values.

Link copied to clipboard
open override fun calculateFee(tx: Transaction): Amount

Calculates the fee of a given transaction. Returns `Amount::ZERO` if tx is a coinbase transaction.

Link copied to clipboard
open override fun calculateFeeRate(tx: Transaction): FeeRate

Calculate the `FeeRate` for a given transaction.

Link copied to clipboard
open override fun cancelTx(tx: Transaction)

Informs the wallet that you no longer intend to broadcast a tx that was built from it.

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun derivationIndex(keychain: KeychainKind): UInt?

The derivation index of this wallet. It will return None if it has not derived any addresses. Otherwise, it will return the index of the highest address it has derived.

Link copied to clipboard
open override fun derivationOfSpk(spk: Script): KeychainAndIndex?

Finds how the wallet derived the script pubkey spk.

Link copied to clipboard
open override fun descriptorChecksum(keychain: KeychainKind): String

Return the checksum of the public descriptor associated to keychain.

Link copied to clipboard
open override fun destroy()
Link copied to clipboard
open override fun finalizePsbt(psbt: Psbt, signOptions: SignOptions?): Boolean

Finalize a PSBT, i.e., for each input determine if sufficient data is available to pass validation and construct the respective scriptSig or scriptWitness. Please refer to BIP174, and BIP371 for further information.

Link copied to clipboard
open override fun getTx(txid: String): CanonicalTx?

Get a single transaction from the wallet as a `WalletTx` (if the transaction exists).

Link copied to clipboard
open override fun getUtxo(op: OutPoint): LocalOutput?

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

Link copied to clipboard
open override fun isMine(script: Script): Boolean

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

Link copied to clipboard
open override fun listOutput(): List<LocalOutput>

List all relevant outputs (includes both spent and unspent, confirmed and unconfirmed).

Link copied to clipboard
open override fun listUnspent(): List<LocalOutput>

Return the list of unspent outputs of this wallet.

Link copied to clipboard
open override fun listUnusedAddresses(keychain: KeychainKind): List<AddressInfo>

List addresses that are revealed but unused.

Link copied to clipboard
open override fun markUsed(keychain: KeychainKind, index: UInt): Boolean

Marks an address used of the given keychain at index.

Link copied to clipboard
open override fun network(): Network

Get the Bitcoin network the wallet is using.

Link copied to clipboard
open override fun nextDerivationIndex(keychain: KeychainKind): UInt

The index of the next address that you would get if you were to ask the wallet for a new address.

Link copied to clipboard
open override fun nextUnusedAddress(keychain: KeychainKind): AddressInfo

Get the next unused address for the given keychain, i.e. the address with the lowest derivation index that hasn't been used in a transaction.

Link copied to clipboard
open override fun peekAddress(keychain: KeychainKind, index: UInt): AddressInfo

Peek an address of the given keychain at index without revealing it.

Link copied to clipboard
open override fun persist(connection: Connection): Boolean

Persist staged changes of wallet into persister.

Link copied to clipboard
open override fun policies(keychain: KeychainKind): Policy?

Return the spending policies for the wallet’s descriptor.

Link copied to clipboard
open override fun revealAddressesTo(keychain: KeychainKind, index: UInt): List<AddressInfo>

Reveal addresses up to and including the target index and return an iterator of newly revealed addresses.

Link copied to clipboard
open override fun revealNextAddress(keychain: KeychainKind): AddressInfo

Attempt to reveal the next address of the given keychain.

Link copied to clipboard

Compute the tx's sent and received `Amount`s.

Link copied to clipboard
open override fun sign(psbt: Psbt, signOptions: SignOptions?): Boolean

Sign a transaction with all the wallet's signers, in the order specified by every signer's `SignerOrdering`. This function returns the Result type with an encapsulated bool that has the value true if the PSBT was finalized, or false otherwise.

Link copied to clipboard

Create a `FullScanRequest for this wallet.

Link copied to clipboard

Create a partial `SyncRequest` for this wallet for all revealed spks.

Link copied to clipboard
open override fun transactions(): List<CanonicalTx>

Iterate over the transactions in the wallet.

Link copied to clipboard
fun uniffiClonePointer(): Pointer