Function bdk::wallet::wallet_name_from_descriptor
source · pub fn wallet_name_from_descriptor<T>(
descriptor: T,
change_descriptor: Option<T>,
network: Network,
secp: &Secp256k1<All>
) -> Result<String, DescriptorError>where
T: IntoWalletDescriptor,Expand description
Deterministically generate a unique name given the descriptors defining the wallet
+
Function bdk::wallet::wallet_name_from_descriptor
source · pub fn wallet_name_from_descriptor<T>(
descriptor: T,
change_descriptor: Option<T>,
network: Network,
secp: &Secp256k1<All>
) -> Result<String, DescriptorError>where
T: IntoWalletDescriptor,Expand description
Deterministically generate a unique name given the descriptors defining the wallet
Compatible with wallet_name_from_descriptor
Expand description
Wallet
+
Module wallet
Expand description
Wallet
This module defines the Wallet.
Modules
Structs
AddressEnums
Panics
This panics when the caller requests for an address of derivation index greater than the
BIP32 max index.
-source§impl<D> Wallet<D>
impl<D> Wallet<D>
sourcepub fn new<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
pub fn new<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
Initialize an empty Wallet.
source§impl<D> Wallet<D>
impl<D> Wallet<D>
sourcepub fn new<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
pub fn new<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
Initialize an empty Wallet.
sourcepub fn new_with_genesis_hash<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network,
genesis_hash: BlockHash
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
pub fn new_with_genesis_hash<E: IntoWalletDescriptor>(
descriptor: E,
change_descriptor: Option<E>,
db: D,
network: Network,
genesis_hash: BlockHash
) -> Result<Self, NewError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
Initialize an empty Wallet with a custom genesis hash.
This is like Wallet::new with an additional genesis_hash parameter. This is useful
for syncing from alternative networks.
let tx = wallet.get_tx(txid).expect("transaction").tx_node.tx;
-let fee = wallet.calculate_fee(tx).expect("fee");let tx = &psbt.clone().extract_tx();
let fee = wallet.calculate_fee(tx).expect("fee");let tx = wallet.get_tx(txid).expect("transaction").tx_node.tx;
-let fee_rate = wallet.calculate_fee_rate(tx).expect("fee rate");let tx = &psbt.clone().extract_tx();
-let fee_rate = wallet.calculate_fee_rate(tx).expect("fee rate");let tx = psbt.clone().extract_tx();
+let fee_rate = wallet.calculate_fee_rate(&tx).expect("fee rate");sourcepub fn sent_and_received(&self, tx: &Transaction) -> (u64, u64)
pub fn sent_and_received(&self, tx: &Transaction) -> (u64, u64)
Compute the txâs sent and received amounts (in satoshis).
This method returns a tuple (sent, received). Sent is the sum of the txin amounts
that spend from previous txouts tracked by this wallet. Received is the summation
of this txâs outputs that send to script pubkeys tracked by this wallet.
Examples
-let tx = wallet.get_tx(txid).expect("transaction").tx_node.tx;
-let (sent, received) = wallet.sent_and_received(tx);let tx = wallet.get_tx(txid).expect("tx exists").tx_node.tx;
+let (sent, received) = wallet.sent_and_received(&tx);let tx = &psbt.clone().extract_tx();
let (sent, received) = wallet.sent_and_received(tx);sourcepub fn get_tx(
&self,
txid: Txid
) -> Option<CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>>
pub fn get_tx(
&self,
txid: Txid
) -> Option<CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>>
Get a single transaction from the wallet as a CanonicalTx (if the transaction exists).
sourcepub fn get_tx(
&self,
txid: Txid
) -> Option<CanonicalTx<'_, Arc<Transaction>, ConfirmationTimeHeightAnchor>>
pub fn get_tx(
&self,
txid: Txid
) -> Option<CanonicalTx<'_, Arc<Transaction>, ConfirmationTimeHeightAnchor>>
Get a single transaction from the wallet as a CanonicalTx (if the transaction exists).
CanonicalTx contains the full transaction alongside meta-data such as:
- Blocks that the transaction is
Anchored in. These may or may not be blocks that exist @@ -161,12 +161,12 @@ inserting new transactions.WARNING: If
-positionis confirmed, we anchor thetxto a the lowest checkpoint that is >= thepositionâs height. The caller is responsible for ensuring thetxexists in our local view of the best chainâs history.
sourcepub fn transactions(
&self
) -> impl Iterator<Item = CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>> + '_
pub fn transactions(
&self
) -> impl Iterator<Item = CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>> + '_
Iterate over the transactions in the wallet.
-sourcepub fn get_balance(&self) -> Balance
pub fn get_balance(&self) -> Balance
Return the balance, separated into available, trusted-pending, untrusted-pending and immature +
sourcepub fn transactions(
&self
) -> impl Iterator<Item = CanonicalTx<'_, Arc<Transaction>, ConfirmationTimeHeightAnchor>> + '_
pub fn transactions(
&self
) -> impl Iterator<Item = CanonicalTx<'_, Arc<Transaction>, ConfirmationTimeHeightAnchor>> + '_
Iterate over the transactions in the wallet.
+sourcepub fn get_balance(&self) -> Balance
pub fn get_balance(&self) -> Balance
Return the balance, separated into available, trusted-pending, untrusted-pending and immature values.
-sourcepub fn add_signer(
&mut self,
keychain: KeychainKind,
ordering: SignerOrdering,
signer: Arc<dyn TransactionSigner>
)
pub fn add_signer(
&mut self,
keychain: KeychainKind,
ordering: SignerOrdering,
signer: Arc<dyn TransactionSigner>
)
Add an external signer
+sourcepub fn add_signer(
&mut self,
keychain: KeychainKind,
ordering: SignerOrdering,
signer: Arc<dyn TransactionSigner>
)
pub fn add_signer(
&mut self,
keychain: KeychainKind,
ordering: SignerOrdering,
signer: Arc<dyn TransactionSigner>
)
Add an external signer
See the signer module for an example.
sourcepub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer>
pub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer>
Get the signers
+sourcepub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer>
pub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer>
Get the signers
Example
let wallet = Wallet::new_no_persist("wpkh(tprv8ZgxMBicQKsPe73PBRSmNbTfbcsZnwWhz5eVmhHpi31HW29Z7mc9B4cWGRQzopNUzZUT391DeDJxL2PefNunWyLgqCKRMDkU1s2s8bAfoSk/84'/0'/0'/0/*)", None, Network::Testnet)?;
for secret_key in wallet.get_signers(KeychainKind::External).signers().iter().filter_map(|s| s.descriptor_secret_key()) {
@@ -175,7 +175,7 @@ values.
}
Ok::<(), Box<dyn std::error::Error>>(())sourcepub fn build_tx(
&mut self
) -> TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, CreateTx>
pub fn build_tx(
&mut self
) -> TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, CreateTx>
Start building a transaction.
+sourcepub fn build_tx(
&mut self
) -> TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, CreateTx>
pub fn build_tx(
&mut self
) -> TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, CreateTx>
sourcepub fn build_fee_bump(
&mut self,
txid: Txid
) -> Result<TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, BumpFee>, BuildFeeBumpError>
pub fn build_fee_bump(
&mut self,
txid: Txid
) -> Result<TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, BumpFee>, BuildFeeBumpError>
Bump the fee of a transaction previously created with this wallet.
+sourcepub fn build_fee_bump(
&mut self,
txid: Txid
) -> Result<TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, BumpFee>, BuildFeeBumpError>
pub fn build_fee_bump(
&mut self,
txid: Txid
) -> Result<TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, BumpFee>, BuildFeeBumpError>
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
replace 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.
sourcepub fn sign(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
pub fn sign(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
Sign a transaction with all the walletâs signers, in the order specified by every signerâs +
sourcepub fn sign(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
pub fn sign(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
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.
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
@@ -225,52 +225,52 @@ in this library will.
sourcepub fn policies(
&self,
keychain: KeychainKind
) -> Result<Option<Policy>, DescriptorError>
pub fn policies(
&self,
keychain: KeychainKind
) -> Result<Option<Policy>, DescriptorError>
Return the spending policies for the walletâs descriptor
-sourcepub fn public_descriptor(
&self,
keychain: KeychainKind
) -> Option<&ExtendedDescriptor>
pub fn public_descriptor(
&self,
keychain: KeychainKind
) -> Option<&ExtendedDescriptor>
Return the âpublicâ version of the walletâs descriptor, meaning a new descriptor that has +
sourcepub fn policies(
&self,
keychain: KeychainKind
) -> Result<Option<Policy>, DescriptorError>
pub fn policies(
&self,
keychain: KeychainKind
) -> Result<Option<Policy>, DescriptorError>
Return the spending policies for the walletâs descriptor
+sourcepub fn public_descriptor(
&self,
keychain: KeychainKind
) -> Option<&ExtendedDescriptor>
pub fn public_descriptor(
&self,
keychain: KeychainKind
) -> Option<&ExtendedDescriptor>
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
-sourcepub fn finalize_psbt(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
pub fn finalize_psbt(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
Finalize a PSBT, i.e., for each input determine if sufficient data is available to pass +
sourcepub fn finalize_psbt(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
pub fn finalize_psbt(
&self,
psbt: &mut PartiallySignedTransaction,
sign_options: SignOptions
) -> Result<bool, SignerError>
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
for further information.
Returns true if the PSBT could be finalized, and false otherwise.
The SignOptions can be used to tweak the behavior of the finalizer.
sourcepub fn secp_ctx(&self) -> &Secp256k1<All>
pub fn secp_ctx(&self) -> &Secp256k1<All>
Return the secp256k1 context used for all signing operations
-sourcepub fn get_descriptor_for_keychain(
&self,
keychain: KeychainKind
) -> &ExtendedDescriptor
pub fn get_descriptor_for_keychain(
&self,
keychain: KeychainKind
) -> &ExtendedDescriptor
Returns the descriptor used to create addresses for a particular keychain.
sourcepub fn derivation_index(&self, keychain: KeychainKind) -> Option<u32>
pub fn derivation_index(&self, keychain: KeychainKind) -> Option<u32>
The derivation index of this wallet. It will return None if it has not derived any addresses.
+
sourcepub fn secp_ctx(&self) -> &Secp256k1<All>
pub fn secp_ctx(&self) -> &Secp256k1<All>
Return the secp256k1 context used for all signing operations
+sourcepub fn get_descriptor_for_keychain(
&self,
keychain: KeychainKind
) -> &ExtendedDescriptor
pub fn get_descriptor_for_keychain(
&self,
keychain: KeychainKind
) -> &ExtendedDescriptor
Returns the descriptor used to create addresses for a particular keychain.
sourcepub fn derivation_index(&self, keychain: KeychainKind) -> Option<u32>
pub fn derivation_index(&self, keychain: KeychainKind) -> Option<u32>
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.
sourcepub fn next_derivation_index(&self, keychain: KeychainKind) -> u32
pub fn next_derivation_index(&self, keychain: KeychainKind) -> u32
The index of the next address that you would get if you were to ask the wallet for a new address
-sourcepub fn cancel_tx(&mut self, tx: &Transaction)
pub fn cancel_tx(&mut self, tx: &Transaction)
Informs the wallet that you no longer intend to broadcast a tx that was built from it.
+sourcepub fn next_derivation_index(&self, keychain: KeychainKind) -> u32
pub fn next_derivation_index(&self, keychain: KeychainKind) -> u32
The index of the next address that you would get if you were to ask the wallet for a new address
+sourcepub fn cancel_tx(&mut self, tx: &Transaction)
pub fn cancel_tx(&mut self, tx: &Transaction)
Informs the wallet that you no longer intend to broadcast a tx that was built from it.
This frees up the change address used when creating the tx for use in future transactions.
-sourcepub fn get_psbt_input(
&self,
utxo: LocalOutput,
sighash_type: Option<PsbtSighashType>,
only_witness_utxo: bool
) -> Result<Input, CreateTxError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
pub fn get_psbt_input(
&self,
utxo: LocalOutput,
sighash_type: Option<PsbtSighashType>,
only_witness_utxo: bool
) -> Result<Input, CreateTxError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
get the corresponding PSBT Input for a LocalUtxo
-sourcepub fn descriptor_checksum(&self, keychain: KeychainKind) -> String
pub fn descriptor_checksum(&self, keychain: KeychainKind) -> String
Return the checksum of the public descriptor associated to keychain
sourcepub fn get_psbt_input(
&self,
utxo: LocalOutput,
sighash_type: Option<PsbtSighashType>,
only_witness_utxo: bool
) -> Result<Input, CreateTxError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
pub fn get_psbt_input(
&self,
utxo: LocalOutput,
sighash_type: Option<PsbtSighashType>,
only_witness_utxo: bool
) -> Result<Input, CreateTxError<D::WriteError>>where
D: PersistBackend<ChangeSet>,
get the corresponding PSBT Input for a LocalUtxo
+sourcepub fn descriptor_checksum(&self, keychain: KeychainKind) -> String
pub fn descriptor_checksum(&self, keychain: KeychainKind) -> String
Return the checksum of the public descriptor associated to keychain
Internally calls Self::get_descriptor_for_keychain to fetch the right descriptor
sourcepub fn apply_update(&mut self, update: Update) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
pub fn apply_update(&mut self, update: Update) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
Applies an update to the wallet and stages the changes (but does not commit them).
sourcepub fn apply_update(&mut self, update: Update) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
pub fn apply_update(&mut self, update: Update) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
Applies an update to the wallet and stages the changes (but does not commit them).
Usually you create an update by interacting with some blockchain data source and inserting
transactions related to your wallet into it.
sourcepub fn commit(&mut self) -> Result<bool, D::WriteError>where
D: PersistBackend<ChangeSet>,
pub fn commit(&mut self) -> Result<bool, D::WriteError>where
D: PersistBackend<ChangeSet>,
Commits all currently staged changed to the persistence backend returning and error when
+
sourcepub fn commit(&mut self) -> Result<bool, D::WriteError>where
D: PersistBackend<ChangeSet>,
pub fn commit(&mut self) -> Result<bool, D::WriteError>where
D: PersistBackend<ChangeSet>,
Commits all currently staged changed to the persistence backend returning and error when
this fails.
This returns whether the update resulted in any changes.
sourcepub fn staged(&self) -> &ChangeSetwhere
D: PersistBackend<ChangeSet>,
pub fn staged(&self) -> &ChangeSetwhere
D: PersistBackend<ChangeSet>,
Returns the changes that will be committed with the next call to commit.
sourcepub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeHeightAnchor>
pub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeHeightAnchor>
Get a reference to the inner TxGraph.
sourcepub fn spk_index(&self) -> &KeychainTxOutIndex<KeychainKind>
pub fn spk_index(&self) -> &KeychainTxOutIndex<KeychainKind>
Get a reference to the inner KeychainTxOutIndex.
sourcepub fn local_chain(&self) -> &LocalChain
pub fn local_chain(&self) -> &LocalChain
Get a reference to the inner LocalChain.
sourcepub fn apply_block(
&mut self,
block: &Block,
height: u32
) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
pub fn apply_block(
&mut self,
block: &Block,
height: u32
) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
Introduces a block of height to the wallet, and tries to connect it to the
+
sourcepub fn staged(&self) -> &ChangeSetwhere
D: PersistBackend<ChangeSet>,
pub fn staged(&self) -> &ChangeSetwhere
D: PersistBackend<ChangeSet>,
Returns the changes that will be committed with the next call to commit.
sourcepub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeHeightAnchor>
pub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeHeightAnchor>
Get a reference to the inner TxGraph.
sourcepub fn spk_index(&self) -> &KeychainTxOutIndex<KeychainKind>
pub fn spk_index(&self) -> &KeychainTxOutIndex<KeychainKind>
Get a reference to the inner KeychainTxOutIndex.
sourcepub fn local_chain(&self) -> &LocalChain
pub fn local_chain(&self) -> &LocalChain
Get a reference to the inner LocalChain.
sourcepub fn apply_block(
&mut self,
block: &Block,
height: u32
) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
pub fn apply_block(
&mut self,
block: &Block,
height: u32
) -> Result<(), CannotConnectError>where
D: PersistBackend<ChangeSet>,
Introduces a block of height to the wallet, and tries to connect it to the
prev_blockhash of the blockâs header.
This is a convenience method that is equivalent to calling apply_block_connected_to
with prev_blockhash and height-1 as the connected_to parameter.
sourcepub fn apply_block_connected_to(
&mut self,
block: &Block,
height: u32,
connected_to: BlockId
) -> Result<(), ApplyHeaderError>where
D: PersistBackend<ChangeSet>,
pub fn apply_block_connected_to(
&mut self,
block: &Block,
height: u32,
connected_to: BlockId
) -> Result<(), ApplyHeaderError>where
D: PersistBackend<ChangeSet>,
Applies relevant transactions from block of height to the wallet, and connects the
+
sourcepub fn apply_block_connected_to(
&mut self,
block: &Block,
height: u32,
connected_to: BlockId
) -> Result<(), ApplyHeaderError>where
D: PersistBackend<ChangeSet>,
pub fn apply_block_connected_to(
&mut self,
block: &Block,
height: u32,
connected_to: BlockId
) -> Result<(), ApplyHeaderError>where
D: PersistBackend<ChangeSet>,
Applies relevant transactions from block of height to the wallet, and connects the
block to the internal chain.
The connected_to parameter informs the wallet how this block connects to the internal
LocalChain. Relevant transactions are filtered from the block and inserted into the
internal TxGraph.
sourcepub fn apply_unconfirmed_txs<'t>(
&mut self,
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>
)where
D: PersistBackend<ChangeSet>,
pub fn apply_unconfirmed_txs<'t>(
&mut self,
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>
)where
D: PersistBackend<ChangeSet>,
Apply relevant unconfirmed transactions to the wallet.
+sourcepub fn apply_unconfirmed_txs<'t>(
&mut self,
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>
)where
D: PersistBackend<ChangeSet>,
pub fn apply_unconfirmed_txs<'t>(
&mut self,
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>
)where
D: PersistBackend<ChangeSet>,
Apply relevant unconfirmed transactions to the wallet.
Transactions that are not relevant are filtered out.
This method takes in an iterator of (tx, last_seen) where last_seen is the timestamp of
when the transaction was last seen in the mempool. This is used for conflict resolution
when there is conflicting unconfirmed transactions. The transaction with the later
last_seen is prioritized.