Instruction

Struct Instruction 

Source
pub struct Instruction {
    pub program_id: Pubkey,
    pub accounts: Vec<AccountMeta>,
    pub data: Vec<u8>,
}
Expand description

An instruction for a program to execute.

Each instruction contains:

  • The program ID (public key) of the program that should process this instruction
  • A list of accounts that the instruction will operate on
  • A byte array of instruction data that is program-specific

Fields§

§program_id: Pubkey

Program ID that executes this instruction

§accounts: Vec<AccountMeta>

Metadata for accounts that this instruction interacts with

§data: Vec<u8>

Program-specific instruction data

Implementations§

Source§

impl Instruction

Source

pub fn new( program_id: Pubkey, data: Vec<u8>, accounts: Vec<AccountMeta>, ) -> Self

Source

pub fn serialize(&self) -> Vec<u8>

Serializes an instruction to a byte array.

The serialization format is:

  • program_id (32 bytes)
  • accounts length (1 byte)
  • account metadata (34 bytes per account)
  • data length (8 bytes)
  • instruction data (variable)
§Returns

A vector containing the serialized instruction

Source

pub fn from_slice(data: &[u8]) -> Self

Deserializes an instruction from a byte slice.

§Parameters
  • data - The byte slice containing the serialized instruction
§Returns

A new Instruction instance

Source

pub fn hash(&self) -> String

Computes a unique hash for this instruction.

§Returns

A string containing the double SHA-256 hash of the serialized instruction

Source

pub fn new_with_bincode<T: Serialize>( program_id: Pubkey, data: T, accounts: Vec<AccountMeta>, ) -> Self

Source

pub fn new_with_borsh<T: BorshSerialize>( program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>, ) -> Self

Trait Implementations§

Source§

impl BorshDeserialize for Instruction

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 Instruction

Source§

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

Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

Returns a duplicate 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 Instruction

Source§

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

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

impl<'de> Deserialize<'de> for Instruction

Source§

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

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

impl From<Instruction> for StableInstruction

Source§

fn from(other: Instruction) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Instruction

Source§

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

Source§

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

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

impl<'__de> Decode<'__de> for Instruction
where '__de:,

Source§

impl Encode for Instruction

Source§

impl Eq for Instruction

Source§

impl StructuralPartialEq for Instruction

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<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> 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<T> DecodeOwned for T
where T: for<'de> Decode<'de>,

Source§

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