Struct Address

Source
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

Source

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);
Source

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");
Source

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"));
Source

pub fn set_purpose(&mut self, purpose: String)

Sets the purpose descriptor for this address.

§Arguments
  • purpose - A string describing the intended use of this address
§Examples
let mut address = Address::new(ProtocolAddress::Transparent(
    transparent::Address::new("t1example")
));

address.set_purpose("Donations".to_string());
Source

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");
Source

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(_)));
Source

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(_)));
Source

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");
Source

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

Source§

fn attachments(&self) -> &Attachments

Returns a reference to the attachments container.
Source§

fn attachments_mut(&mut self) -> &mut Attachments

Returns a mutable reference to the attachments container.
Source§

fn add_attachment( &mut self, payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, )

Adds a new attachment with the specified payload and metadata. Read more
Source§

fn get_attachment(&self, digest: &Digest) -> Option<&Envelope>

Retrieves an attachment by its digest. Read more
Source§

fn remove_attachment(&mut self, digest: &Digest) -> Option<Envelope>

Removes an attachment by its digest. Read more
Source§

fn clear_attachments(&mut self)

Removes all attachments from the object.
Source§

fn has_attachments(&self) -> bool

Returns whether the object has any attachments. Read more
Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

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 Address

Source§

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

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

impl From<Address> for Envelope

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl Indexed for Address

Source§

fn index(&self) -> usize

Source§

fn set_index(&mut self, index: usize)

Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> 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 TryFrom<Envelope> for Address

Source§

type Error = Error

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

fn try_from(envelope: Envelope) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Address

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
Source§

impl<T> EnvelopeEncodable for T
where T: Into<Envelope> + Clone,

Source§

fn into_envelope(self) -> Envelope

Converts the value into an envelope by using its Into<Envelope> implementation.

Source§

fn to_envelope(&self) -> Envelope
where Self: Clone,

Converts a reference to this value into a Gordian Envelope. 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T