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: PubkeyProgram 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
impl Instruction
pub fn new( program_id: Pubkey, data: Vec<u8>, accounts: Vec<AccountMeta>, ) -> Self
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
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
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Sourcepub fn hash(&self) -> String
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
pub fn new_with_bincode<T: Serialize>( program_id: Pubkey, data: T, accounts: Vec<AccountMeta>, ) -> Self
pub fn new_with_borsh<T: BorshSerialize>( program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>, ) -> Self
Trait Implementations§
Source§impl BorshDeserialize for Instruction
impl BorshDeserialize for Instruction
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
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>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for Instruction
impl BorshSerialize for Instruction
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl<'de> Deserialize<'de> for Instruction
impl<'de> Deserialize<'de> for Instruction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl From<Instruction> for StableInstruction
Source§fn from(other: Instruction) -> Self
fn from(other: Instruction) -> Self
Converts to this type from the input type.
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
Source§impl Serialize for Instruction
impl Serialize for Instruction
impl<'__de> Decode<'__de> for Instructionwhere
'__de:,
impl Encode for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
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
Mutably borrows from an owned value. Read more