pub struct ClarityDatabase<'a> {
    pub store: RollbackWrapper<'a>,
    /* private fields */
}

Fields§

§store: RollbackWrapper<'a>

Implementations§

§

impl<'a> ClarityDatabase<'a>

pub fn new( store: &'a mut dyn ClarityBackingStore, headers_db: &'a dyn HeadersDB, burn_state_db: &'a dyn BurnStateDB ) -> ClarityDatabase<'a>

pub fn new_with_rollback_wrapper( store: RollbackWrapper<'a>, headers_db: &'a dyn HeadersDB, burn_state_db: &'a dyn BurnStateDB ) -> ClarityDatabase<'a>

pub fn initialize(&mut self)

pub fn is_stack_empty(&self) -> bool

pub fn begin(&mut self)

Nest the key-value wrapper instance

pub fn commit(&mut self)

Commit current key-value wrapper layer

pub fn roll_back(&mut self)

Drop current key-value wrapper layer

pub fn set_block_hash( &mut self, bhh: StacksBlockId, query_pending_data: bool ) -> Result<StacksBlockId, Error>

pub fn put<T>(&mut self, key: &str, value: &T)where T: ClaritySerializable,

pub fn put_with_size<T>(&mut self, key: &str, value: &T) -> u64where T: ClaritySerializable,

Like put(), but returns the serialized byte size of the stored value

pub fn get<T>(&mut self, key: &str) -> Option<T>where T: ClarityDeserializable<T>,

pub fn get_value( &mut self, key: &str, expected: &TypeSignature ) -> Result<Option<ValueResult>, Error>

pub fn get_with_proof<T>(&mut self, key: &str) -> Option<(T, Vec<u8>)>where T: ClarityDeserializable<T>,

pub fn make_key_for_trip( contract_identifier: &QualifiedContractIdentifier, data: StoreType, var_name: &str ) -> String

pub fn make_metadata_key(data: StoreType, var_name: &str) -> String

pub fn make_key_for_quad( contract_identifier: &QualifiedContractIdentifier, data: StoreType, var_name: &str, key_value: &str ) -> String

pub fn insert_contract_hash( &mut self, contract_identifier: &QualifiedContractIdentifier, contract_content: &str ) -> Result<(), Error>

pub fn get_contract_src( &mut self, contract_identifier: &QualifiedContractIdentifier ) -> Option<String>

pub fn set_metadata( &mut self, contract_identifier: &QualifiedContractIdentifier, key: &str, data: &str )

pub fn fetch_metadata_manual<T>( &mut self, at_height: u32, contract_identifier: &QualifiedContractIdentifier, key: &str ) -> Result<Option<T>, Error>where T: ClarityDeserializable<T>,

pub fn load_contract_analysis( &mut self, contract_identifier: &QualifiedContractIdentifier ) -> Option<ContractAnalysis>

pub fn get_contract_size( &mut self, contract_identifier: &QualifiedContractIdentifier ) -> Result<u64, Error>

pub fn set_contract_data_size( &mut self, contract_identifier: &QualifiedContractIdentifier, data_size: u64 ) -> Result<(), Error>

used for adding the memory usage of define-constant variables.

pub fn insert_contract( &mut self, contract_identifier: &QualifiedContractIdentifier, contract: Contract )

pub fn has_contract( &mut self, contract_identifier: &QualifiedContractIdentifier ) -> bool

pub fn get_contract( &mut self, contract_identifier: &QualifiedContractIdentifier ) -> Result<Contract, Error>

pub fn ustx_liquid_supply_key() -> &'static str

pub fn get_clarity_epoch_version(&mut self) -> StacksEpochId

Returns the epoch version currently applied in the stored Clarity state. Since Clarity did not exist in stacks 1.0, the lowest valid epoch ID is stacks 2.0. The instantiation of subsequent epochs may bump up the epoch version in the clarity DB if Clarity is updated in that epoch.

pub fn set_clarity_epoch_version(&mut self, epoch: StacksEpochId)

Should be called after all of the epoch’s initialization has been invoked

pub fn get_total_liquid_ustx(&mut self) -> u128

Returns the current total liquid ustx

pub fn increment_ustx_liquid_supply( &mut self, incr_by: u128 ) -> Result<(), Error>

pub fn decrement_ustx_liquid_supply( &mut self, decr_by: u128 ) -> Result<(), Error>

pub fn destroy(self) -> RollbackWrapper<'a>

pub fn is_in_regtest(&self) -> bool

§

impl<'a> ClarityDatabase<'a>

pub fn get_index_block_header_hash( &mut self, block_height: u32 ) -> StacksBlockId

Returns the ID of a Stacks block, by a Stacks block height.

Fails if block_height >= the “currently” under construction Stacks block height.

pub fn get_current_block_height(&mut self) -> u32

This is the height we are currently constructing. It comes from the MARF.

pub fn get_v1_unlock_height(&self) -> u32

Return the height for PoX v1 -> v2 auto unlocks from the burn state db

pub fn get_pox_3_activation_height(&self) -> u32

Return the height for PoX 3 activation from the burn state db

pub fn get_v2_unlock_height(&mut self) -> u32

Return the height for PoX v2 -> v3 auto unlocks from the burn state db

pub fn get_current_burnchain_block_height(&mut self) -> u32

Get the last-known burnchain block height. Note that this is not the burnchain height in which this block was mined! This is the burnchain block height of the parent of the Stacks block at the current Stacks block height (i.e. that returned by get_index_block_header_hash for get_current_block_height).

pub fn get_block_header_hash(&mut self, block_height: u32) -> BlockHeaderHash

pub fn get_block_time(&mut self, block_height: u32) -> u64

pub fn get_burnchain_block_header_hash( &mut self, block_height: u32 ) -> BurnchainHeaderHash

pub fn get_burnchain_block_header_hash_for_burnchain_height( &mut self, burnchain_block_height: u32 ) -> Option<BurnchainHeaderHash>

Fetch the burnchain block header hash for a given burnchain height. Because the burnchain can fork, we need to resolve the burnchain hash from the currently-evaluated Stacks chain tip.

This way, the BurnchainHeaderHash returned is guaranteed to be on the burnchain fork that holds the currently-evaluated Stacks fork (even if it’s not the canonical burnchain fork).

pub fn get_pox_payout_addrs_for_burnchain_height( &mut self, burnchain_block_height: u32 ) -> Option<(Vec<TupleData>, u128)>

Get the PoX reward addresses and per-address payout for a given burnchain height. Because the burnchain can fork, we need to resolve the PoX addresses from the currently-evaluated Stacks chain tip.

pub fn get_burnchain_block_height( &mut self, id_bhh: &StacksBlockId ) -> Option<u32>

pub fn get_block_vrf_seed(&mut self, block_height: u32) -> VRFSeed

pub fn get_miner_address(&mut self, block_height: u32) -> StandardPrincipalData

pub fn get_miner_spend_winner(&mut self, block_height: u32) -> u128

pub fn get_miner_spend_total(&mut self, block_height: u32) -> u128

pub fn get_block_reward(&mut self, block_height: u32) -> Option<u128>

pub fn get_stx_btc_ops_processed(&mut self) -> u64

pub fn set_stx_btc_ops_processed(&mut self, processed: u64)

§

impl<'a> ClarityDatabase<'a>

pub fn make_microblock_pubkey_height_key(pubkey_hash: &Hash160) -> String

pub fn make_microblock_poison_key(height: u32) -> String

pub fn insert_microblock_pubkey_hash_height( &mut self, pubkey_hash: &Hash160, height: u32 ) -> Result<(), Error>

pub fn get_cc_special_cases_handler( &self ) -> Option<&'static dyn Fn(&mut GlobalContext<'_, '_>, Option<&PrincipalData>, Option<&PrincipalData>, &QualifiedContractIdentifier, &str, &[Value], &Value) -> Result<(), Error>>

pub fn insert_microblock_poison( &mut self, height: u32, reporter: &StandardPrincipalData, seq: u16 ) -> Result<(), Error>

pub fn get_microblock_pubkey_hash_height( &mut self, pubkey_hash: &Hash160 ) -> Option<u32>

pub fn get_microblock_poison_report( &mut self, height: u32 ) -> Option<(StandardPrincipalData, u16)>

Returns (who-reported-the-poison-microblock, sequence-of-microblock-fork)

§

impl<'a> ClarityDatabase<'a>

pub fn create_variable( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str, value_type: TypeSignature ) -> DataVariableMetadata

pub fn load_variable( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str ) -> Result<DataVariableMetadata, Error>

pub fn set_variable( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str, value: Value, variable_descriptor: &DataVariableMetadata ) -> Result<ValueResult, Error>

pub fn lookup_variable_unknown_descriptor( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str ) -> Result<Value, Error>

pub fn lookup_variable( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str, variable_descriptor: &DataVariableMetadata ) -> Result<Value, Error>

pub fn lookup_variable_with_size( &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str, variable_descriptor: &DataVariableMetadata ) -> Result<ValueResult, Error>

Same as lookup_variable, but returns the byte-size of the looked up Clarity value as well as the value.

§

impl<'a> ClarityDatabase<'a>

pub fn create_map( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_type: TypeSignature, value_type: TypeSignature ) -> DataMapMetadata

pub fn load_map( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str ) -> Result<DataMapMetadata, Error>

pub fn make_key_for_data_map_entry( contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value ) -> String

pub fn fetch_entry_unknown_descriptor( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value ) -> Result<Value, Error>

pub fn fetch_entry( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value, map_descriptor: &DataMapMetadata ) -> Result<Value, Error>

Returns a Clarity optional type wrapping a found or not found result

pub fn fetch_entry_with_size( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value, map_descriptor: &DataMapMetadata ) -> Result<ValueResult, Error>

pub fn set_entry( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key: Value, value: Value, map_descriptor: &DataMapMetadata ) -> Result<ValueResult, Error>

pub fn set_entry_unknown_descriptor( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key: Value, value: Value ) -> Result<Value, Error>

pub fn insert_entry_unknown_descriptor( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key: Value, value: Value ) -> Result<Value, Error>

pub fn insert_entry( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key: Value, value: Value, map_descriptor: &DataMapMetadata ) -> Result<ValueResult, Error>

pub fn delete_entry( &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value, map_descriptor: &DataMapMetadata ) -> Result<ValueResult, Error>

§

impl<'a> ClarityDatabase<'a>

pub fn create_fungible_token( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, total_supply: &Option<u128> ) -> FungibleTokenMetadata

pub fn load_ft( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str ) -> Result<FungibleTokenMetadata, Error>

pub fn create_non_fungible_token( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, key_type: &TypeSignature ) -> NonFungibleTokenMetadata

pub fn checked_increase_token_supply( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, amount: u128, descriptor: &FungibleTokenMetadata ) -> Result<(), Error>

pub fn checked_decrease_token_supply( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, amount: u128 ) -> Result<(), Error>

pub fn get_ft_balance( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, principal: &PrincipalData, descriptor: Option<&FungibleTokenMetadata> ) -> Result<u128, Error>

pub fn set_ft_balance( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, principal: &PrincipalData, balance: u128 ) -> Result<(), Error>

pub fn get_ft_supply( &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str ) -> Result<u128, Error>

pub fn get_nft_owner( &mut self, contract_identifier: &QualifiedContractIdentifier, asset_name: &str, asset: &Value, key_type: &TypeSignature ) -> Result<PrincipalData, Error>

pub fn get_nft_key_type( &mut self, contract_identifier: &QualifiedContractIdentifier, asset_name: &str ) -> Result<TypeSignature, Error>

pub fn set_nft_owner( &mut self, contract_identifier: &QualifiedContractIdentifier, asset_name: &str, asset: &Value, principal: &PrincipalData, key_type: &TypeSignature ) -> Result<(), Error>

pub fn burn_nft( &mut self, contract_identifier: &QualifiedContractIdentifier, asset_name: &str, asset: &Value, key_type: &TypeSignature ) -> Result<(), Error>

§

impl<'a> ClarityDatabase<'a>

pub fn make_key_for_account_balance(principal: &PrincipalData) -> String

pub fn make_key_for_account_nonce(principal: &PrincipalData) -> String

pub fn make_key_for_account_stx_locked(principal: &PrincipalData) -> String

pub fn make_key_for_account_unlock_height(principal: &PrincipalData) -> String

pub fn get_stx_balance_snapshot<'conn>( &'conn mut self, principal: &PrincipalData ) -> STXBalanceSnapshot<'a, 'conn>

pub fn get_stx_balance_snapshot_genesis<'conn>( &'conn mut self, principal: &PrincipalData ) -> STXBalanceSnapshot<'a, 'conn>

pub fn get_account_stx_balance( &mut self, principal: &PrincipalData ) -> STXBalance

pub fn get_account_nonce(&mut self, principal: &PrincipalData) -> u64

pub fn set_account_nonce(&mut self, principal: &PrincipalData, nonce: u64)

§

impl<'a> ClarityDatabase<'a>

pub fn get_burn_block_height(&self, sortition_id: &SortitionId) -> Option<u32>

pub fn get_stacks_epoch( &self, height: u32 ) -> Option<StacksEpoch<ExecutionCost>>

This function obtains the stacks epoch version, which is based on the burn block height. Valid epochs include stacks 1.0, 2.0, 2.05, and so on.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ClarityDatabase<'a>

§

impl<'a> !Send for ClarityDatabase<'a>

§

impl<'a> !Sync for ClarityDatabase<'a>

§

impl<'a> Unpin for ClarityDatabase<'a>

§

impl<'a> !UnwindSafe for ClarityDatabase<'a>

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