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>

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>,

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)>

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.

Trait Implementations§

§

impl CostTracker for GlobalContext<'_, '_>

§

fn compute_cost( &mut self, cost_function: ClarityCostFunction, input: &[u64] ) -> Result<ExecutionCost, CostErrors>

§

fn add_cost(&mut self, cost: ExecutionCost) -> Result<(), CostErrors>

§

fn add_memory(&mut self, memory: u64) -> Result<(), CostErrors>

§

fn drop_memory(&mut self, memory: u64)

§

fn reset_memory(&mut self)

§

fn short_circuit_contract_call( &mut self, contract: &QualifiedContractIdentifier, function: &ClarityName, input: &[u64] ) -> Result<bool, CostErrors>

Check if the given contract-call should be short-circuited. If so: this charges the cost to the CostTracker, and return true If not: return false

Auto Trait Implementations§

§

impl<'a, 'hooks> !RefUnwindSafe for GlobalContext<'a, 'hooks>

§

impl<'a, 'hooks> !Send for GlobalContext<'a, 'hooks>

§

impl<'a, 'hooks> !Sync for GlobalContext<'a, 'hooks>

§

impl<'a, 'hooks> Unpin for GlobalContext<'a, 'hooks>

§

impl<'a, 'hooks> !UnwindSafe for GlobalContext<'a, 'hooks>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more