Skip to main content

Address

Struct Address 

Source
pub struct Address(/* private fields */);
Expand description

The address of a Solana account.

Some account addresses are ed25519 public keys, with corresponding secret keys that are managed off-chain. Often, though, account addresses do not have corresponding secret keys — as with program derived addresses — or the secret key is not relevant to the operation of a program, and may have even been disposed of. As running Solana programs can not safely create or manage secret keys, the full Keypair is not defined in solana-program but in solana-sdk.

Implementations§

Source§

impl Address

Source

pub fn derive_address<const N: usize>( seeds: &[&[u8]; N], bump: Option<u8>, program_id: &Address, ) -> Address

Derive a program address from the given seeds, optional bump and program id.

In general, the derivation uses an optional bump (byte) value to ensure a valid PDA (off-curve) is generated. Even when a program stores a bump to derive a program address, it is necessary to use the [Address::create_program_address] to validate the derivation. In most cases, the program has the correct seeds for the derivation, so it would be sufficient to just perform the derivation and compare it against the expected resulting address.

This function avoids the cost of the create_program_address syscall (1500 compute units) by directly computing the derived address calculating the hash of the seeds, bump and program id using the sol_sha256 syscall.

§Important

This function differs from [Address::create_program_address] in that it does not perform a validation to ensure that the derived address is a valid (off-curve) program derived address. It is intended for use in cases where the seeds, bump, and program id are known to be valid, and the caller wants to derive the address without incurring the cost of the create_program_address syscall.

Source

pub const fn derive_address_const<const N: usize>( seeds: &[&[u8]; N], bump: Option<u8>, program_id: &Address, ) -> Address

Derive a program address from the given seeds, optional bump and program id.

In general, the derivation uses an optional bump (byte) value to ensure a valid PDA (off-curve) is generated.

This function is intended for use in const contexts - i.e., the seeds and bump are known at compile time and the program id is also a constant. It avoids the cost of the create_program_address syscall (1500 compute units) by directly computing the derived address using the SHA-256 hash of the seeds, bump and program id.

§Important

This function differs from [Address::create_program_address] in that it does not perform a validation to ensure that the derived address is a valid (off-curve) program derived address. It is intended for use in cases where the seeds, bump, and program id are known to be valid, and the caller wants to derive the address without incurring the cost of the create_program_address syscall.

This function is a compile-time constant version of Address::derive_address. It has worse performance than derive_address, so only use this function in const contexts, where all parameters are known at compile-time.

Source

pub fn derive_program_address<const N: usize>( seeds: &[&[u8]; N], program_id: &Address, ) -> Option<(Address, u8)>

Attempt to derive a valid program derived address (PDA) and its corresponding bump seed.

The main difference between this method and Address::derive_address is that this method iterates through all possible bump seed values (starting from 255 and decrementing) until it finds a valid (off-curve) program derived address.

If a valid PDA is found, it returns the PDA and the bump seed used to derive it; otherwise, it returns None.

Source§

impl Address

Source

pub const fn new_from_array(address_array: [u8; 32]) -> Address

Source

pub const fn from_str_const(s: &str) -> Address

Decode a string into an Address, usable in a const context

Source

pub fn new_unique() -> Address

Create a unique Address for tests and benchmarks.

Source

pub fn create_with_seed( base: &Address, seed: &str, owner: &Address, ) -> Result<Address, AddressError>

Source

pub const fn to_bytes(&self) -> [u8; 32]

Source

pub const fn as_array(&self) -> &[u8; 32]

Return a reference to the Address’s byte array.

Source

pub fn is_on_curve(&self) -> bool

Checks whether the given address lies on the Ed25519 curve.

On-curve addresses correspond to valid Ed25519 public keys (and therefore can have associated private keys). Off-curve addresses are typically used for program-derived addresses (PDAs).

Trait Implementations§

Source§

impl AsMut<[u8]> for Address

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for Address

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Address

Source§

impl Debug for Address

Available on crate feature decode only.
Source§

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

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

impl Default for Address

Source§

fn default() -> Address

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Address

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Address, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Address

Available on crate feature decode only.
Source§

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

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

impl Eq for Address

Source§

impl From<&Address> for Address

Source§

fn from(value: &Address) -> Address

Converts to this type from the input type.
Source§

impl From<[u8; 32]> for Address

Source§

fn from(from: [u8; 32]) -> Address

Converts to this type from the input type.
Source§

impl FromStr for Address

Available on crate feature decode only.
Source§

type Err = ParseAddressError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Address, <Address as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Address

Custom impl of Hash for Address.

This allows us to skip hashing the length of the address which is always the same anyway.

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Address

Source§

fn cmp(&self, other: &Address) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Address

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Address

Source§

fn partial_cmp(&self, other: &Address) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sanitize for Address

Available on crate feature sanitize only.
Source§

impl<'de, WincodeConfig> SchemaRead<'de, WincodeConfig> for Address
where WincodeConfig: Config,

Source§

const TYPE_META: TypeMeta

Metadata about the type’s serialization. Read more
Source§

type Dst = Address

Source§

fn read( reader: impl Reader<'de>, dst: &mut MaybeUninit<<Address as SchemaRead<'de, WincodeConfig>>::Dst>, ) -> Result<(), ReadError>

Read into dst from reader. Read more
Source§

fn get(reader: impl Reader<'de>) -> Result<Self::Dst, ReadError>

Read Self::Dst from reader into a new Self::Dst.
Source§

impl<WincodeConfig> SchemaWrite<WincodeConfig> for Address
where WincodeConfig: Config,

Source§

const TYPE_META: TypeMeta

Metadata about the type’s serialization. Read more
Source§

type Src = Address

Source§

fn size_of( src: &<Address as SchemaWrite<WincodeConfig>>::Src, ) -> Result<usize, WriteError>

Get the serialized size of Self::Src. Read more
Source§

fn write( writer: impl Writer, src: &<Address as SchemaWrite<WincodeConfig>>::Src, ) -> Result<(), WriteError>

Write Self::Src to writer.
Source§

impl Serialize for Address

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Address

Source§

impl TryFrom<&[u8]> for Address

Source§

type Error = TryFromSliceError

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

fn try_from( address: &[u8], ) -> Result<Address, <Address as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Address

Available on crate feature decode only.
Source§

type Error = ParseAddressError

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

fn try_from(s: &str) -> Result<Address, <Address as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl<WincodeConfig> ZeroCopy<WincodeConfig> for Address
where WincodeConfig: Config, [u8; 32]: for<'_wincode_internal> ZeroCopy<WincodeConfig>, Assert<solana_address::::_#3::{impl#1}::{constant#1}>: for<'_wincode_internal> IsTrue,

Source§

fn from_bytes<'de>(bytes: &'de [u8], config: C) -> Result<&'de Self, ReadError>
where Self: Sized + SchemaRead<'de, C, Dst = Self>,

Like crate::ZeroCopy::from_bytes, but allows the caller to provide a custom configuration.
Source§

fn from_bytes_mut<'de>( bytes: &'de mut [u8], config: C, ) -> Result<&'de mut Self, ReadError>
where Self: Sized + SchemaRead<'de, C, Dst = Self>,

Like crate::ZeroCopy::from_bytes_mut, but allows the caller to provide a custom configuration.

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, dest: *mut u8)

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

impl<'de, T, C> Deserialize<'de, C> for T
where C: Config, T: SchemaRead<'de, C>,

Source§

fn deserialize(src: &'de [u8], config: C) -> Result<Self::Dst, ReadError>

Deserialize the input bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, config: C, ) -> Result<(), ReadError>

Deserialize the input bytes into dst.
Source§

impl<'de, T> Deserialize<'de> for T
where T: SchemaRead<'de, Configuration>,

Source§

fn deserialize(src: &'de [u8]) -> Result<Self::Dst, ReadError>

Deserialize the input src bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize the input src bytes into dst.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DeserializeOwned for T

Source§

fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize from the given Reader into dst.
Source§

impl<T, C> DeserializeOwned<C> for T
where C: Config, T: SchemaReadOwned<C>,

Source§

fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize from the given Reader into dst.
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> MaybeSendSync for T

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, C> SchemaReadOwned<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C>,

Source§

impl<T> Serialize for T

Source§

fn serialize(src: &Self::Src) -> Result<Vec<u8>, WriteError>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into(dst: impl Writer, src: &Self::Src) -> Result<(), WriteError>

Serialize a serializable type into the given byte buffer.
Source§

fn serialized_size(src: &Self::Src) -> Result<u64, WriteError>

Get the size in bytes of the type when serialized.
Source§

impl<T, C> Serialize<C> for T
where C: Config, T: SchemaWrite<C> + ?Sized,

Source§

fn serialize(src: &Self::Src, config: C) -> Result<Vec<u8>, WriteError>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> Result<(), WriteError>

Serialize a serializable type into the given Writer.
Source§

fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>

Get the size in bytes of the type when serialized.
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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ZeroCopy for T

Source§

fn from_bytes<'de>(bytes: &'de [u8]) -> Result<&'de Self, ReadError>
where Self: Sized + SchemaRead<'de, Configuration, Dst = Self>,

Get a reference to a type from the given bytes. Read more
Source§

fn from_bytes_mut<'de>(bytes: &'de mut [u8]) -> Result<&'de mut Self, ReadError>
where Self: Sized + SchemaRead<'de, Configuration, Dst = Self>,

Get a mutable reference to a type from the given bytes. Read more