pub struct Address { /* private fields */ }
Expand description
A high-level address representation with metadata in a Zcash wallet.
Address
serves as the primary container for all Zcash addresses, wrapping
the protocol-specific address details with additional wallet-level metadata
such as a user-assigned name, purpose descriptor, and arbitrary attachments.
This structure bridges the raw cryptographic address formats with the
user-facing wallet experience.
§Zcash Concept Relation
In Zcash wallets, users typically assign labels or metadata to their addresses
for easier identification. Address
preserves these user-defined attributes
alongside the underlying cryptographic address details. It supports all Zcash
address protocols:
- Transparent addresses: Bitcoin-compatible addresses (t-prefixed)
- Sapling addresses: Shielded Sapling protocol addresses (z-prefixed)
- Unified addresses: Multi-protocol addresses (u-prefixed)
§Data Preservation
During wallet migration, the following components are preserved:
- Address Data: The complete protocol-specific address details
- User Labels: Custom names assigned to addresses by users
- Purpose Strings: Descriptions of the address’s intended use
- Attachments: Any additional metadata associated with the address
§Examples
// Create a transparent address
let t_addr = transparent::Address::new("t1exampleaddress");
let protocol_addr = ProtocolAddress::Transparent(t_addr);
// Wrap it in an Address with metadata
let mut address = Address::new(protocol_addr);
address.set_name("Donation Address".to_string());
address.set_purpose("Receiving public donations".to_string());
// Access the address string
assert!(address.as_string().starts_with("t1"));
assert_eq!(address.name(), "Donation Address");
Implementations§
Source§impl Address
impl Address
Sourcepub fn new(address: ProtocolAddress) -> Self
pub fn new(address: ProtocolAddress) -> Self
Creates a new Address
with the specified protocol address.
This constructor creates an Address
with default empty metadata
(blank name, no purpose) and the provided protocol-specific address.
§Arguments
address
- The protocol-specific address implementation
§Examples
let t_addr = transparent::Address::new("t1example");
let protocol_addr = ProtocolAddress::Transparent(t_addr);
let address = Address::new(protocol_addr);
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the user-assigned name for this address.
§Returns
The name string assigned to this address, or an empty string if no name has been set.
§Examples
let t_addr = transparent::Address::new("t1example");
let protocol_addr = ProtocolAddress::Transparent(t_addr);
let mut address = Address::new(protocol_addr);
address.set_name("Personal Savings".to_string());
assert_eq!(address.name(), "Personal Savings");
Sourcepub fn purpose(&self) -> Option<&str>
pub fn purpose(&self) -> Option<&str>
Returns the purpose descriptor for this address, if available.
§Returns
Some(&str)
containing the purpose string if set, or None
if no purpose was assigned.
§Examples
let mut address = Address::new(ProtocolAddress::Transparent(
transparent::Address::new("t1example")
));
// Initially there is no purpose
assert!(address.purpose().is_none());
// Set a purpose and verify it was stored
address.set_purpose("Business expenses".to_string());
assert_eq!(address.purpose(), Some("Business expenses"));
Sourcepub fn set_purpose(&mut self, purpose: String)
pub fn set_purpose(&mut self, purpose: String)
Sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Returns the address as a string in its canonical format.
§Returns
A string representation of the address.
§Examples
let address = Address::new(ProtocolAddress::Transparent(
transparent::Address::new("t1exampleaddress")
));
let addr_string = address.as_string();
assert_eq!(addr_string, "t1exampleaddress");
Sourcepub fn address(&self) -> &ProtocolAddress
pub fn address(&self) -> &ProtocolAddress
Returns a reference to the protocol-specific address.
§Returns
A reference to the ProtocolAddress
contained within this address.
§Examples
let t_addr = transparent::Address::new("t1example");
let protocol_addr = ProtocolAddress::Transparent(t_addr);
let address = Address::new(protocol_addr);
let protocol = address.address();
assert!(matches!(protocol, ProtocolAddress::Transparent(_)));
Sourcepub fn address_mut(&mut self) -> &mut ProtocolAddress
pub fn address_mut(&mut self) -> &mut ProtocolAddress
Returns a mutable reference to the protocol-specific address.
§Returns
A mutable reference to the ProtocolAddress
contained within this address.
§Examples
let mut address = Address::new(ProtocolAddress::Transparent(
transparent::Address::new("t1example")
));
// Swap the address out for a Sapling address
if let ProtocolAddress::Transparent(_) = address.address() {
*address.address_mut() = ProtocolAddress::Sapling(
Box::new(sapling::Address::new("zs1example".to_string()))
);
}
assert!(matches!(address.address(), ProtocolAddress::Sapling(_)));
Sourcepub fn set_name(&mut self, name: String)
pub fn set_name(&mut self, name: String)
Sets the name for this address.
§Arguments
name
- The user-defined name or label to assign to this address
§Examples
let mut address = Address::new(ProtocolAddress::Transparent(
transparent::Address::new("t1example")
));
address.set_name("Cold Storage".to_string());
assert_eq!(address.name(), "Cold Storage");
Sourcepub fn set_address(&mut self, address: ProtocolAddress)
pub fn set_address(&mut self, address: ProtocolAddress)
Replaces the protocol-specific address.
§Arguments
address
- The new protocol address to store
§Examples
let mut address = Address::new(ProtocolAddress::Transparent(
transparent::Address::new("t1old")
));
// Replace with a new address
let new_addr = transparent::Address::new("t1new");
address.set_address(ProtocolAddress::Transparent(new_addr));
assert_eq!(address.as_string(), "t1new");
Trait Implementations§
Source§impl Attachable for Address
impl Attachable for Address
Source§fn attachments(&self) -> &Attachments
fn attachments(&self) -> &Attachments
Source§fn attachments_mut(&mut self) -> &mut Attachments
fn attachments_mut(&mut self) -> &mut Attachments
Source§fn add_attachment(
&mut self,
payload: impl EnvelopeEncodable,
vendor: &str,
conforms_to: Option<&str>,
)
fn add_attachment( &mut self, payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, )
Source§fn get_attachment(&self, digest: &Digest) -> Option<&Envelope>
fn get_attachment(&self, digest: &Digest) -> Option<&Envelope>
Source§fn remove_attachment(&mut self, digest: &Digest) -> Option<Envelope>
fn remove_attachment(&mut self, digest: &Digest) -> Option<Envelope>
Source§fn clear_attachments(&mut self)
fn clear_attachments(&mut self)
Source§fn has_attachments(&self) -> bool
fn has_attachments(&self) -> bool
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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Converts the value into an envelope by using its Into<Envelope>
implementation.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more