Struct bdk::wallet::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>§

source

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.

source

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.

source

pub fn is_standard(&self) -> bool

👎Deprecated since 0.30.0: Use Address::is_spend_standard instead

Checks whether or not the address is following Bitcoin standardness rules.

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

source

pub fn script_pubkey(&self) -> ScriptBuf

Generates a script pubkey spending to this address.

source

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, both the schema and the address become uppercase. If the address is base58, the schema is lowercase and 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.

source

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

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

source

pub fn is_valid_for_network(&self, network: 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::Testnet), false);

Trait Implementations§

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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 StructuralEq for AddressInfo

source§

impl StructuralPartialEq for AddressInfo

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V