pub struct InstructionContext<'a> { /* private fields */ }Expand description
Context provided to instruction hook functions
Implementations§
Source§impl<'a> InstructionContext<'a>
impl<'a> InstructionContext<'a>
Sourcepub fn new(
accounts: HashMap<String, String>,
state_id: u32,
reverse_lookup_tx: &'a mut dyn ReverseLookupUpdater,
) -> Self
pub fn new( accounts: HashMap<String, String>, state_id: u32, reverse_lookup_tx: &'a mut dyn ReverseLookupUpdater, ) -> Self
Create a new InstructionContext (primarily for use by generated code)
Sourcepub fn with_metrics(
accounts: HashMap<String, String>,
state_id: u32,
reverse_lookup_tx: &'a mut dyn ReverseLookupUpdater,
registers: &'a mut Vec<RegisterValue>,
state_reg: Register,
compiled_paths: &'a HashMap<String, CompiledPath>,
instruction_data: &'a Value,
slot: Option<u64>,
signature: Option<String>,
timestamp: i64,
) -> Self
pub fn with_metrics( accounts: HashMap<String, String>, state_id: u32, reverse_lookup_tx: &'a mut dyn ReverseLookupUpdater, registers: &'a mut Vec<RegisterValue>, state_reg: Register, compiled_paths: &'a HashMap<String, CompiledPath>, instruction_data: &'a Value, slot: Option<u64>, signature: Option<String>, timestamp: i64, ) -> Self
Create InstructionContext with metrics support
Sourcepub fn account(&self, name: &str) -> Option<String>
pub fn account(&self, name: &str) -> Option<String>
Get an account address by its name from the instruction
Sourcepub fn register_pda_reverse_lookup(
&mut self,
pda_address: &str,
seed_value: &str,
)
pub fn register_pda_reverse_lookup( &mut self, pda_address: &str, seed_value: &str, )
Register a reverse lookup: PDA address -> seed value This also flushes any pending account updates for this PDA
The pending account updates are accumulated internally and can be retrieved
via take_pending_updates() after all hooks have executed.
Sourcepub fn take_pending_updates(&mut self) -> Vec<PendingAccountUpdate>
pub fn take_pending_updates(&mut self) -> Vec<PendingAccountUpdate>
Take all accumulated pending updates
This should be called after all instruction hooks have executed to retrieve any pending account updates that need to be reprocessed.
Sourcepub fn dirty_fields(&self) -> &HashSet<String>
pub fn dirty_fields(&self) -> &HashSet<String>
Get the fields modified by imperative hooks
Sourcepub fn state_value(&self) -> Option<&Value>
pub fn state_value(&self) -> Option<&Value>
Get the current state register value (for generating mutations)
Sourcepub fn get<T: DeserializeOwned>(&self, field_path: &str) -> Option<T>
pub fn get<T: DeserializeOwned>(&self, field_path: &str) -> Option<T>
Get a field value from the entity state This allows reading aggregated values or other entity fields
Sourcepub fn set<T: Serialize>(&mut self, field_path: &str, value: T)
pub fn set<T: Serialize>(&mut self, field_path: &str, value: T)
Set a field value in the entity state
Sourcepub fn increment(&mut self, field_path: &str, amount: i64)
pub fn increment(&mut self, field_path: &str, amount: i64)
Increment a numeric field (creates it as 0 if it doesn’t exist)
Sourcepub fn data<T: DeserializeOwned>(&self, field: &str) -> Option<T>
pub fn data<T: DeserializeOwned>(&self, field: &str) -> Option<T>
Access instruction data field