Struct light_compressed_token::token_data::TokenData

source ·
pub struct TokenData {
    pub mint: Pubkey,
    pub owner: Pubkey,
    pub amount: u64,
    pub delegate: Option<Pubkey>,
    pub state: AccountState,
    pub tlv: Option<Vec<u8>>,
}

Fields§

§mint: Pubkey

The mint associated with this account

§owner: Pubkey

The owner of this account.

§amount: u64

The amount of tokens this account holds.

§delegate: Option<Pubkey>

If delegate is Some then delegated_amount represents the amount authorized by the delegate

§state: AccountState

The account’s state

§tlv: Option<Vec<u8>>

Placeholder for TokenExtension tlv data (unimplemented)

Implementations§

source§

impl TokenData

Hashing schema: H(mint, owner, amount, delegate, delegated_amount, is_native, state)

delegate, delegated_amount, is_native and state have dynamic positions. Always hash mint, owner and amount If delegate hash delegate and delegated_amount together. If is native hash is_native else is omitted. If frozen hash AccountState::Frozen else is omitted.

Security: to prevent the possibility that different fields with the same value to result in the same hash we add a prefix to the delegated amount, is native and state fields. This way we can have a dynamic hashing schema and hash only used values.

source

pub fn is_native(&self) -> bool

Only the spl representation of native tokens (wrapped SOL) is compressed. The sol value is stored in the token pool account. The sol value in the compressed account is independent from the wrapped sol amount.

source

pub fn hash_with_hashed_values<H: Hasher>( hashed_mint: &[u8; 32], hashed_owner: &[u8; 32], amount_bytes: &[u8; 8], hashed_delegate: &Option<&[u8; 32]>, ) -> Result<[u8; 32], HasherError>

source

pub fn hash_frozen_with_hashed_values<H: Hasher>( hashed_mint: &[u8; 32], hashed_owner: &[u8; 32], amount_bytes: &[u8; 8], hashed_delegate: &Option<&[u8; 32]>, ) -> Result<[u8; 32], HasherError>

source

pub fn hash_inputs_with_hashed_values<H: Hasher, const FROZEN_INPUTS: bool>( mint: &[u8; 32], owner: &[u8; 32], amount_bytes: &[u8; 8], hashed_delegate: &Option<&[u8; 32]>, ) -> Result<[u8; 32], HasherError>

We should not hash pubkeys multiple times. For all we can assume mints are equal. For all input compressed accounts we assume owners are equal.

Trait Implementations§

source§

impl BorshDeserialize for TokenData

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

source§

impl BorshSerialize for TokenData

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

source§

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
source§

impl Clone for TokenData

source§

fn clone(&self) -> TokenData

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 DataHasher for TokenData

source§

fn hash<H: Hasher>(&self) -> Result<[u8; 32], HasherError>

source§

impl Debug for TokenData

source§

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

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

impl IdlBuild for TokenData

source§

fn __anchor_private_full_path() -> String

Returns the full module path of the type.
source§

fn __anchor_private_gen_idl_type() -> Option<IdlTypeDefinition>

Returns the IDL type definition of the type or None if it doesn’t exist.
source§

fn __anchor_private_insert_idl_defined( defined_types: &mut HashMap<String, IdlTypeDefinition>, )

Insert the type definition to the defined types hashmap.
source§

impl PartialEq for TokenData

source§

fn eq(&self, other: &TokenData) -> 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 Eq for TokenData

source§

impl StructuralPartialEq for TokenData

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> AbiExample for T

source§

default fn example() -> T

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 T)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
source§

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

source§

fn vzip(self) -> V