pub struct Address { /* private fields */ }Expand description
A Bitcoin address derived from a public key hash (P2PKH).
Implementations§
Source§impl Address
impl Address
Sourcepub fn from_public_key_hash(hash: &[u8; 20], mainnet: bool) -> Self
pub fn from_public_key_hash(hash: &[u8; 20], mainnet: bool) -> Self
Create an address from a 20-byte public key hash.
Uses mainnet prefix (0x00) when mainnet is true,
testnet prefix (0x6f) otherwise.
Sourcepub fn from_public_key(pubkey: &PublicKey, mainnet: bool) -> Self
pub fn from_public_key(pubkey: &PublicKey, mainnet: bool) -> Self
Create an address from a PublicKey.
Computes hash160 of the compressed public key bytes, then encodes with the appropriate network prefix.
Sourcepub fn from_string(s: &str) -> Result<Self, ScriptError>
pub fn from_string(s: &str) -> Result<Self, ScriptError>
Decode an address from a Base58Check string.
Validates that the prefix is 0x00 (mainnet) or 0x6f (testnet) and that the hash is exactly 20 bytes.
Sourcepub fn to_public_key_hash(&self) -> &[u8] ⓘ
pub fn to_public_key_hash(&self) -> &[u8] ⓘ
Return the 20-byte public key hash.
Sourcepub fn is_mainnet(&self) -> bool
pub fn is_mainnet(&self) -> bool
Check whether this is a mainnet address (prefix 0x00).
Sourcepub fn to_locking_script(&self) -> LockingScript
pub fn to_locking_script(&self) -> LockingScript
Create a P2PKH locking script for this address.
Script: OP_DUP OP_HASH160 <pubkeyhash> OP_EQUALVERIFY OP_CHECKSIG
Trait Implementations§
impl Eq for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more