Struct solders_instruction::Instruction
source · pub struct Instruction(pub Instruction);
Expand description
A directive for a single invocation of a Solana program.
An instruction specifies which program it is calling, which accounts it may
read or modify, and additional data that serves as input to the program. One
or more instructions are included in transactions submitted by Solana
clients. Instructions are also used to describe cross-program invocations <https://docs.solana.com/developing/programming-model/calling-between-programs/>
_.
During execution, a program will receive a list of account data as one of
its arguments, in the same order as specified during Instruction
construction.
While Solana is agnostic to the format of the instruction data, it has
built-in support for serialization via
borsh <https://docs.rs/borsh/latest/borsh/>
_
and bincode <https://docs.rs/bincode/latest/bincode/>
_.
When constructing an Instruction
, a list of all accounts that may be
read or written during the execution of that instruction must be supplied as
:class:AccountMeta
values.
Specifying Account Metadata
Any account whose data may be mutated by the program during execution must be specified as writable. During execution, writing to an account that was not specified as writable will cause the transaction to fail. Writing to an account that is not owned by the program will cause the transaction to fail.
Any account whose lamport balance may be mutated by the program during execution must be specified as writable. During execution, mutating the lamports of an account that was not specified as writable will cause the transaction to fail. While subtracting lamports from an account not owned by the program will cause the transaction to fail, adding lamports to any account is allowed, as long is it is mutable.
Accounts that are not read or written by the program may still be specified
in an Instruction
’s account list. These will affect scheduling of program
execution by the runtime, but will otherwise be ignored.
When building a transaction, the Solana runtime coalesces all accounts used
by all instructions in that transaction, along with accounts and permissions
required by the runtime, into a single account list. Some accounts and
account permissions required by the runtime to process a transaction are
not required to be included in an Instruction
’s account list. These
include:
- The program ID: it is a separate field of
Instruction
- The transaction’s fee-paying account: it is added during :class:
~solders.message.Message
construction. A program may still require the fee payer as part of the account list if it directly references it.
Programs may require signatures from some accounts, in which case they
should be specified as signers during Instruction
construction. The
program must still validate during execution that the account is a signer.
Args: program_id (Pubkey): Pubkey of the program that executes this instruction. data (bytes): Opaque data passed to the program for its own interpretation. accounts (listAccountMeta): Metadata describing accounts that should be passed to the program.
Tuple Fields§
§0: Instruction
Implementations§
source§impl Instruction
impl Instruction
pub fn new(program_id: &Pubkey, data: &[u8], accounts: Vec<AccountMeta>) -> Self
pub fn program_id(&self) -> Pubkey
pub fn data<'a>(&self, py: Python<'a>) -> &'a PyBytes
pub fn accounts(&self) -> Vec<AccountMeta>
pub fn set_accounts(&mut self, accounts: Vec<AccountMeta>)
sourcepub fn from_bytes(data: &[u8]) -> PyResult<Self>
pub fn from_bytes(data: &[u8]) -> PyResult<Self>
Deserialize a serialized Instruction
object.
Args:
data (bytes): the serialized Instruction
.
Returns:
Instruction: the deserialized Instruction
.
Example: >>> from solders.pubkey import Pubkey >>> from solders.instruction import AccountMeta, Instruction >>> from_pubkey = Pubkey.new_unique() >>> to_pubkey = Pubkey.new_unique() >>> program_id = Pubkey.new_unique() >>> instruction_data = bytes([1]) >>> accounts = [AccountMeta(from_pubkey, is_signer=True, is_writable=True), AccountMeta(to_pubkey, is_signer=True, is_writable=True),] >>> instruction = Instruction(program_id, instruction_data, accounts) >>> serialized = bytes(instruction) >>> assert Instruction.from_bytes(serialized) == instruction
pub fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult<bool>
pub fn __bytes__<'a>(&self, py: Python<'a>) -> &'a PyBytes
pub fn __str__(&self) -> String
pub fn __repr__(&self) -> String
pub fn __reduce__(&self) -> PyResult<(PyObject, PyObject)>
Trait Implementations§
source§impl AsRef<Instruction> for Instruction
impl AsRef<Instruction> for Instruction
source§fn as_ref(&self) -> &InstructionOriginal
fn as_ref(&self) -> &InstructionOriginal
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 CommonMethods<'_> for Instruction
impl CommonMethods<'_> for Instruction
fn py_to_json(&self) -> String
fn py_from_json(raw: &'a str) -> Result<Self, PyErr>
source§impl CommonMethodsCore for Instruction
impl CommonMethodsCore for Instruction
source§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 Display for Instruction
impl Display for Instruction
source§impl From<Instruction> for Instruction
impl From<Instruction> for Instruction
source§fn from(original: InstructionOriginal) -> Instruction
fn from(original: InstructionOriginal) -> Instruction
source§impl From<Instruction> for Instruction
impl From<Instruction> for Instruction
source§fn from(original: Instruction) -> Self
fn from(original: Instruction) -> Self
source§impl PartialEq for Instruction
impl PartialEq for Instruction
source§fn eq(&self, other: &Instruction) -> bool
fn eq(&self, other: &Instruction) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PyBytesBincode for Instruction
impl PyBytesBincode for Instruction
fn pybytes_bincode<'a>(&self, py: Python<'a>) -> &'a PyBytes
source§impl PyBytesGeneral for Instruction
impl PyBytesGeneral for Instruction
fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes
source§impl PyClassImpl for Instruction
impl PyClassImpl for Instruction
source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type Layout = PyCell<Instruction>
type Layout = PyCell<Instruction>
§type ThreadChecker = ThreadCheckerStub<Instruction>
type ThreadChecker = ThreadCheckerStub<Instruction>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
source§impl PyClassNewTextSignature<Instruction> for PyClassImplCollector<Instruction>
impl PyClassNewTextSignature<Instruction> for PyClassImplCollector<Instruction>
fn new_text_signature(self) -> Option<&'static str>
source§impl PyFromBytesBincode<'_> for Instruction
impl PyFromBytesBincode<'_> for Instruction
source§impl PyFromBytesGeneral for Instruction
impl PyFromBytesGeneral for Instruction
fn py_from_bytes_general(raw: &[u8]) -> PyResult<Self>
source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Instruction
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Instruction
source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Instruction
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Instruction
source§impl PyMethods<Instruction> for PyClassImplCollector<Instruction>
impl PyMethods<Instruction> for PyClassImplCollector<Instruction>
fn py_methods(self) -> &'static PyClassItems
source§impl PyTypeInfo for Instruction
impl PyTypeInfo for Instruction
§type AsRefTarget = PyCell<Instruction>
type AsRefTarget = PyCell<Instruction>
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.