WalletInterface

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.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

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

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

Link copied to clipboard
abstract fun applyUpdate(update: Update)

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

Link copied to clipboard
abstract fun balance(): Balance

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

Link copied to clipboard
abstract 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

Calculate the `FeeRate` for a given transaction.

Link copied to clipboard
abstract 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
abstract 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

Finds how the wallet derived the script pubkey spk.

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

Return the checksum of the public descriptor associated to keychain.

Link copied to clipboard
abstract fun finalizePsbt(psbt: Psbt, signOptions: SignOptions? = null): 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
abstract fun getTx(txid: String): CanonicalTx?

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

Link copied to clipboard
abstract 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
abstract fun isMine(script: Script): Boolean

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

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

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

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

Return the list of unspent outputs of this wallet.

Link copied to clipboard

List addresses that are revealed but unused.

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

Marks an address used of the given keychain at index.

Link copied to clipboard
abstract fun network(): Network

Get the Bitcoin network the wallet is using.

Link copied to clipboard
abstract 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
abstract 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
abstract fun peekAddress(keychain: KeychainKind, index: UInt): AddressInfo

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

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

Persist staged changes of wallet into persister.

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

Return the spending policies for the wallet’s descriptor.

Link copied to clipboard
abstract 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
abstract 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
abstract fun sign(psbt: Psbt, signOptions: SignOptions? = null): 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
abstract fun transactions(): List<CanonicalTx>

Iterate over the transactions in the wallet.