[−][src]Struct bdk::wallet::Wallet
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" OfflineBlockchain
is used. Offline wallets only expose
methods that don't need any interaction with the blockchain to work.
Implementations
impl<B, D> Wallet<B, D> where
B: BlockchainMarker,
D: BatchDatabase,
[src]
B: BlockchainMarker,
D: BatchDatabase,
pub fn new_offline(
descriptor: &str,
change_descriptor: Option<&str>,
network: Network,
database: D
) -> Result<Self, Error>
[src]
descriptor: &str,
change_descriptor: Option<&str>,
network: Network,
database: D
) -> Result<Self, Error>
Create a new "offline" wallet
pub fn get_new_address(&self) -> Result<Address, Error>
[src]
Return a newly generated address using the external descriptor
pub fn is_mine(&self, script: &Script) -> Result<bool, Error>
[src]
Return whether or not a script
is part of this wallet (either internal or external)
pub fn list_unspent(&self) -> Result<Vec<UTXO>, Error>
[src]
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.
pub fn list_transactions(
&self,
include_raw: bool
) -> Result<Vec<TransactionDetails>, Error>
[src]
&self,
include_raw: bool
) -> Result<Vec<TransactionDetails>, Error>
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.
pub fn get_balance(&self) -> Result<u64, Error>
[src]
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.
pub fn add_signer(
&mut self,
script_type: ScriptType,
id: SignerId<DescriptorPublicKey>,
ordering: SignerOrdering,
signer: Arc<Box<dyn Signer>>
)
[src]
&mut self,
script_type: ScriptType,
id: SignerId<DescriptorPublicKey>,
ordering: SignerOrdering,
signer: Arc<Box<dyn Signer>>
)
Add an external signer
See the signer
module for an example.
pub fn add_address_validator(
&mut self,
validator: Arc<Box<dyn AddressValidator>>
)
[src]
&mut self,
validator: Arc<Box<dyn AddressValidator>>
)
Add an address validator
See the address_validator
module for an example.
pub fn create_tx<Cs: CoinSelectionAlgorithm>(
&self,
builder: TxBuilder<Cs>
) -> Result<(PSBT, TransactionDetails), Error>
[src]
&self,
builder: TxBuilder<Cs>
) -> Result<(PSBT, TransactionDetails), Error>
Create a new transaction following the options specified in the builder
Example
let (psbt, details) = wallet.create_tx( TxBuilder::with_recipients(vec![(to_address.script_pubkey(), 50_000)]) )?; // sign and broadcast ...
pub fn bump_fee<Cs: CoinSelectionAlgorithm>(
&self,
txid: &Txid,
builder: TxBuilder<Cs>
) -> Result<(PSBT, TransactionDetails), Error>
[src]
&self,
txid: &Txid,
builder: TxBuilder<Cs>
) -> Result<(PSBT, TransactionDetails), Error>
Bump the fee of a transaction following the options specified in the builder
Return an error if the transaction is already confirmed or doesn't explicitly signal RBF.
NOTE: if the original transaction was made with TxBuilder::send_all
, the same
option must be enabled when bumping its fees to correctly reduce the only output's value to
increase the fees.
Example
let txid = Txid::from_str("faff0a466b70f5d5f92bd757a92c1371d4838bdd5bc53a06764e2488e51ce8f8").unwrap(); let (psbt, details) = wallet.bump_fee( &txid, TxBuilder::new().fee_rate(FeeRate::from_sat_per_vb(5.0)), )?; // sign and broadcast ...
pub fn sign(
&self,
psbt: PSBT,
assume_height: Option<u32>
) -> Result<(PSBT, bool), Error>
[src]
&self,
psbt: PSBT,
assume_height: Option<u32>
) -> Result<(PSBT, bool), Error>
Sign a transaction with all the wallet's signers, in the order specified by every signer's
SignerOrdering
Example
let (signed_psbt, finalized) = wallet.sign(psbt, None)?;
pub fn policies(&self, script_type: ScriptType) -> Result<Option<Policy>, Error>
[src]
Return the spending policies for the wallet's descriptor
pub fn public_descriptor(
&self,
script_type: ScriptType
) -> Result<Option<ExtendedDescriptor>, Error>
[src]
&self,
script_type: ScriptType
) -> Result<Option<ExtendedDescriptor>, Error>
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
pub fn finalize_psbt(
&self,
psbt: PSBT,
assume_height: Option<u32>
) -> Result<(PSBT, bool), Error>
[src]
&self,
psbt: PSBT,
assume_height: Option<u32>
) -> Result<(PSBT, bool), Error>
Try to finalize a PSBT
impl<B, D> Wallet<B, D> where
B: Blockchain,
D: BatchDatabase,
[src]
B: Blockchain,
D: BatchDatabase,
pub fn new(
descriptor: &str,
change_descriptor: Option<&str>,
network: Network,
database: D,
client: B
) -> Result<Self, Error>
[src]
descriptor: &str,
change_descriptor: Option<&str>,
network: Network,
database: D,
client: B
) -> Result<Self, Error>
Create a new "online" wallet
pub fn sync<P: 'static + Progress>(
&self,
progress_update: P,
max_address_param: Option<u32>
) -> Result<(), Error>
[src]
&self,
progress_update: P,
max_address_param: Option<u32>
) -> Result<(), Error>
Sync the internal database with the blockchain
pub fn client(&self) -> Option<&B>
[src]
Return a reference to the internal blockchain client
pub fn broadcast(&self, tx: Transaction) -> Result<Txid, Error>
[src]
Broadcast a transaction to the network
Auto Trait Implementations
impl<B, D> !RefUnwindSafe for Wallet<B, D>
impl<B, D> !Send for Wallet<B, D>
impl<B, D> !Sync for Wallet<B, D>
impl<B, D> Unpin for Wallet<B, D> where
B: Unpin,
D: Unpin,
B: Unpin,
D: Unpin,
impl<B, D> !UnwindSafe for Wallet<B, D>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,