pub struct Instruction {
pub program_id: Pubkey,
pub accounts: Vec<AccountMeta>,
pub data: Vec<u8>,
}
std
and WebAssembly only.Expand description
wasm-bindgen version of the Instruction struct. This duplication is required until https://github.com/rustwasm/wasm-bindgen/issues/3671 is fixed. This must not diverge from the regular non-wasm Instruction struct.
Fields§
§program_id: Pubkey
§accounts: Vec<AccountMeta>
§data: Vec<u8>
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn new_with_borsh<T: BorshSerialize>(
program_id: Pubkey,
data: &T,
accounts: Vec<AccountMeta>,
) -> Self
Available on crate feature borsh
only.
pub fn new_with_borsh<T: BorshSerialize>( program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>, ) -> Self
borsh
only.Create a new instruction from a value, encoded with borsh
.
program_id
is the address of the program that will execute the instruction.
accounts
contains a description of all accounts that may be accessed by the program.
Borsh serialization is often preferred over bincode as it has a stable specification and an implementation in JavaScript, neither of which are true of bincode.
§Examples
#[derive(BorshSerialize, BorshDeserialize)]
pub struct MyInstruction {
pub lamports: u64,
}
pub fn create_instruction(
program_id: &Pubkey,
from: &Pubkey,
to: &Pubkey,
lamports: u64,
) -> Instruction {
let instr = MyInstruction { lamports };
Instruction::new_with_borsh(
*program_id,
&instr,
vec![
AccountMeta::new(*from, true),
AccountMeta::new(*to, false),
],
)
}
Sourcepub fn new_with_bincode<T: Serialize>(
program_id: Pubkey,
data: &T,
accounts: Vec<AccountMeta>,
) -> Self
Available on crate feature bincode
only.
pub fn new_with_bincode<T: Serialize>( program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>, ) -> Self
bincode
only.Create a new instruction from a value, encoded with bincode
.
program_id
is the address of the program that will execute the instruction.
accounts
contains a description of all accounts that may be accessed by the program.
§Examples
#[derive(Serialize, Deserialize)]
pub struct MyInstruction {
pub lamports: u64,
}
pub fn create_instruction(
program_id: &Pubkey,
from: &Pubkey,
to: &Pubkey,
lamports: u64,
) -> Instruction {
let instr = MyInstruction { lamports };
Instruction::new_with_bincode(
*program_id,
&instr,
vec![
AccountMeta::new(*from, true),
AccountMeta::new(*to, false),
],
)
}
Sourcepub fn new_with_bytes(
program_id: Pubkey,
data: &[u8],
accounts: Vec<AccountMeta>,
) -> Self
pub fn new_with_bytes( program_id: Pubkey, data: &[u8], accounts: Vec<AccountMeta>, ) -> Self
Create a new instruction from a byte slice.
program_id
is the address of the program that will execute the instruction.
accounts
contains a description of all accounts that may be accessed by the program.
The caller is responsible for ensuring the correct encoding of data
as expected
by the callee program.
§Examples
#[derive(BorshSerialize, BorshDeserialize)]
pub struct MyInstruction {
pub lamports: u64,
}
pub fn create_instruction(
program_id: &Pubkey,
from: &Pubkey,
to: &Pubkey,
lamports: u64,
) -> Result<Instruction, Error> {
let instr = MyInstruction { lamports };
let mut instr_in_bytes: Vec<u8> = Vec::new();
instr.serialize(&mut instr_in_bytes)?;
Ok(Instruction::new_with_bytes(
*program_id,
&instr_in_bytes,
vec![
AccountMeta::new(*from, true),
AccountMeta::new(*to, false),
],
))
}
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
Source§impl From<Instruction> for JsValue
impl From<Instruction> for JsValue
Source§fn from(value: Instruction) -> Self
fn from(value: Instruction) -> Self
Source§impl FromWasmAbi for Instruction
impl FromWasmAbi for Instruction
Source§impl IntoWasmAbi for Instruction
impl IntoWasmAbi for Instruction
Source§impl LongRefFromWasmAbi for Instruction
impl LongRefFromWasmAbi for Instruction
Source§impl OptionFromWasmAbi for Instruction
impl OptionFromWasmAbi for Instruction
Source§impl OptionIntoWasmAbi for Instruction
impl OptionIntoWasmAbi for Instruction
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
Source§impl RefFromWasmAbi for Instruction
impl RefFromWasmAbi for Instruction
Source§type Anchor = RcRef<Instruction>
type Anchor = RcRef<Instruction>
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for Instruction
impl RefMutFromWasmAbi for Instruction
Source§impl Serialize for Instruction
impl Serialize for Instruction
Source§impl TryFromJsValue for Instruction
impl TryFromJsValue for Instruction
Source§impl VectorFromWasmAbi for Instruction
impl VectorFromWasmAbi for Instruction
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Instruction]>
Source§impl VectorIntoJsValue for Instruction
impl VectorIntoJsValue for Instruction
fn vector_into_jsvalue(vector: Box<[Instruction]>) -> JsValue
Source§impl VectorIntoWasmAbi for Instruction
impl VectorIntoWasmAbi for Instruction
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[Instruction]>) -> Self::Abi
Source§impl WasmDescribeVector for Instruction
impl WasmDescribeVector for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
impl SupportsConstructor for Instruction
impl SupportsInstanceProperty for Instruction
impl SupportsStaticProperty 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.