bdk_wallet

Struct AddressInfo

Source
pub struct AddressInfo {
    pub index: u32,
    pub address: Address,
    pub keychain: KeychainKind,
}
Expand description

A derived address and the index it was found at. For convenience this automatically derefs to Address

Fields§

§index: u32

Child index of this address

§address: Address

Address

§keychain: KeychainKind

Type of keychain

Methods from Deref<Target = Address>§

pub fn as_unchecked(&self) -> &Address<NetworkUnchecked>

Returns a reference to the address as if it was unchecked.

pub fn address_type(&self) -> Option<AddressType>

Gets the address type of the address.

§Returns

None if unknown, non-standard or related to the future witness version.

pub fn to_address_data(&self) -> AddressData

Gets the address data from this address.

pub fn pubkey_hash(&self) -> Option<PubkeyHash>

Gets the pubkey hash for this address if this is a P2PKH address.

pub fn script_hash(&self) -> Option<ScriptHash>

Gets the script hash for this address if this is a P2SH address.

pub fn witness_program(&self) -> Option<WitnessProgram>

Gets the witness program for this address if this is a segwit address.

pub fn is_spend_standard(&self) -> bool

Checks whether or not the address is following Bitcoin standardness rules when spending from this address. NOT to be called by senders.

Spending Standardness

For forward compatibility, the senders must send to any [Address]. Receivers can use this method to check whether or not they can spend from this address.

SegWit addresses with unassigned witness versions or non-standard program sizes are considered non-standard.

pub fn script_pubkey(&self) -> ScriptBuf

Generates a script pubkey spending to this address.

pub fn to_qr_uri(&self) -> String

Creates a URI string bitcoin:address optimized to be encoded in QR codes.

If the address is bech32, the address becomes uppercase. If the address is base58, the address is left mixed case.

Quoting BIP 173 “inside QR codes uppercase SHOULD be used, as those permit the use of alphanumeric mode, which is 45% more compact than the normal byte mode.”

Note however that despite BIP21 explicitly stating that the bitcoin: prefix should be parsed as case-insensitive many wallets got this wrong and don’t parse correctly. See compatibility table.

If you want to avoid allocation you can use alternate display instead:


write!(writer, "{:#}", address)?;

Returns true if the given pubkey is directly related to the address payload.

This is determined by directly comparing the address payload with either the hash of the given public key or the segwit redeem hash generated from the given key. For taproot addresses, the supplied key is assumed to be tweaked

Returns true if the supplied xonly public key can be used to derive the address.

This will only work for Taproot addresses. The Public Key is assumed to have already been tweaked.

pub fn matches_script_pubkey(&self, script: &Script) -> bool

Returns true if the address creates a particular script This function doesn’t make any allocations.

pub fn assume_checked_ref(&self) -> &Address

Returns a reference to the checked address.

This function is dangerous in case the address is not a valid checked address.

pub fn is_valid_for_network(&self, n: Network) -> bool

Parsed addresses do not always have one network. The problem is that legacy testnet, regtest and signet addresse use the same prefix instead of multiple different ones. When parsing, such addresses are always assumed to be testnet addresses (the same is true for bech32 signet addresses). So if one wants to check if an address belongs to a certain network a simple comparison is not enough anymore. Instead this function can be used.

use bitcoin::{Address, Network};
use bitcoin::address::NetworkUnchecked;

let address: Address<NetworkUnchecked> = "2N83imGV3gPwBzKJQvWJ7cRUY2SpUyU6A5e".parse().unwrap();
assert!(address.is_valid_for_network(Network::Testnet));
assert!(address.is_valid_for_network(Network::Regtest));
assert!(address.is_valid_for_network(Network::Signet));

assert_eq!(address.is_valid_for_network(Network::Bitcoin), false);

let address: Address<NetworkUnchecked> = "32iVBEu4dxkUQk9dJbZUiBiQdmypcEyJRf".parse().unwrap();
assert!(address.is_valid_for_network(Network::Bitcoin));
assert_eq!(address.is_valid_for_network(Network::Testnet4), false);

Trait Implementations§

Source§

impl Clone for AddressInfo

Source§

fn clone(&self) -> AddressInfo

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AddressInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for AddressInfo

Source§

type Target = Address

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for AddressInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AddressInfo

Source§

fn eq(&self, other: &AddressInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AddressInfo

Source§

impl StructuralPartialEq for AddressInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V