Struct stacks_rpc_client::clarity::vm::contexts::GlobalContext
pub struct GlobalContext<'a, 'hooks> {
pub event_batches: Vec<EventBatch>,
pub database: ClarityDatabase<'a>,
pub cost_track: LimitedCostTracker,
pub mainnet: bool,
pub epoch_id: StacksEpochId,
pub chain_id: u32,
pub eval_hooks: Option<Vec<&'hooks mut dyn EvalHook>>,
/* private fields */
}
Expand description
GlobalContext represents the outermost context for a single transaction’s execution. It tracks an asset changes that occurred during the processing of the transaction, whether or not the current context is read_only, and is responsible for committing/rolling-back transactions as they error or abort.
Fields§
§event_batches: Vec<EventBatch>
§database: ClarityDatabase<'a>
§cost_track: LimitedCostTracker
§mainnet: bool
§epoch_id: StacksEpochId
This is the epoch of the the block that this transaction is executing within.
chain_id: u32
This is the chain ID of the transaction
eval_hooks: Option<Vec<&'hooks mut dyn EvalHook>>
Implementations§
§impl<'a, 'hooks> GlobalContext<'a, 'hooks>
impl<'a, 'hooks> GlobalContext<'a, 'hooks>
pub fn new( mainnet: bool, chain_id: u32, database: ClarityDatabase<'a>, cost_track: LimitedCostTracker, epoch_id: StacksEpochId ) -> GlobalContext<'a, 'a>
pub fn is_top_level(&self) -> bool
pub fn log_asset_transfer( &mut self, sender: &PrincipalData, contract_identifier: &QualifiedContractIdentifier, asset_name: &ClarityName, transfered: Value )
pub fn log_token_transfer( &mut self, sender: &PrincipalData, contract_identifier: &QualifiedContractIdentifier, asset_name: &ClarityName, transfered: u128 ) -> Result<(), Error>
pub fn log_stx_transfer( &mut self, sender: &PrincipalData, transfered: u128 ) -> Result<(), Error>
pub fn log_stx_burn( &mut self, sender: &PrincipalData, transfered: u128 ) -> Result<(), Error>
pub fn execute<F, T>(&mut self, f: F) -> Result<T, Error>where F: FnOnce(&mut GlobalContext<'a, 'hooks>) -> Result<T, Error>,
pub fn special_cc_handler_execute_read_only<F, A, E>(
&mut self,
sender: PrincipalData,
sponsor: Option<PrincipalData>,
contract_context: ContractContext,
f: F
) -> Result<A, E>where
E: From<Error>,
F: FnOnce(&mut Environment<'_, '_, '_>) -> Result<A, E>,
pub fn special_cc_handler_execute_read_only<F, A, E>( &mut self, sender: PrincipalData, sponsor: Option<PrincipalData>, contract_context: ContractContext, f: F ) -> Result<A, E>where E: From<Error>, F: FnOnce(&mut Environment<'_, '_, '_>) -> Result<A, E>,
Run a snippet of Clarity code in the given contract context Only use within special-case contract-call handlers. DO NOT CALL FROM ANYWHERE ELSE!
pub fn is_read_only(&self) -> bool
pub fn begin(&mut self)
pub fn begin_read_only(&mut self)
pub fn commit( &mut self ) -> Result<(Option<AssetMap>, Option<EventBatch>), Error>
pub fn roll_back(&mut self)
pub fn handle_tx_result( &mut self, result: Result<Value, Error> ) -> Result<Value, Error>
pub fn destruct(self) -> Option<(ClarityDatabase<'a>, LimitedCostTracker)>
pub fn destruct(self) -> Option<(ClarityDatabase<'a>, LimitedCostTracker)>
Destroys this context, returning ownership of its database reference. If the context wasn’t top-level (i.e., it had uncommitted data), return None, because the database is not guaranteed to be in a sane state.