Struct Runtime

Source
pub struct Runtime<'a, R> { /* private fields */ }
Expand description

Represents the runtime properties of a WASM execution.

Implementations§

Source§

impl<'a, R> Runtime<'a, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source

pub fn call_package_version_with_stack( &mut self, contract_package_hash: PackageHash, protocol_version_major: Option<ProtocolVersionMajor>, version: Option<EntityVersion>, entry_point_name: String, args: RuntimeArgs, stack: RuntimeStack, ) -> Result<CLValue, ExecError>

Call a version within a package by pushing a stack element onto the frame.

Source

pub fn call_contract( &mut self, contract_hash: AddressableEntityHash, entry_point_name: &str, args: RuntimeArgs, ) -> Result<CLValue, ExecError>

Calls contract living under a key, with supplied args.

Source

pub fn call_versioned_contract( &mut self, contract_package_hash: PackageHash, contract_version: Option<EntityVersion>, entry_point_name: String, args: RuntimeArgs, ) -> Result<CLValue, ExecError>

Calls version of the contract living at key, invoking method with supplied args. This function also checks the args conform with the types given in the contract header.

Source

pub fn call_package_version( &mut self, contract_package_hash: PackageHash, protocol_version_major: Option<ProtocolVersionMajor>, version: Option<EntityVersion>, entry_point_name: String, args: RuntimeArgs, ) -> Result<CLValue, ExecError>

Calls version of the contract living at key, invoking method with supplied args. This function also checks the args conform with the types given in the contract header.

Source

pub fn take_host_buffer(&mut self) -> Option<CLValue>

If host_buffer set, clears the host_buffer and returns value, else None

Trait Implementations§

Source§

impl<R> AccountProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn set_main_purse(&mut self, purse: URef)

Set main purse.

Source§

fn get_main_purse(&self) -> Result<URef, Error>

Get currently executing account’s purse.
Source§

impl<R> Auction for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn get_era_validators( &mut self, ) -> Result<BTreeMap<EraId, BTreeMap<PublicKey, U512>>, Error>

Returns active validators and auction winners for a number of future eras determined by the configured auction_delay.
Source§

fn read_seigniorage_recipients( &mut self, ) -> Result<BTreeMap<PublicKey, SeigniorageRecipientV2>, Error>

Returns validators in era_validators, mapped to their bids or founding stakes, delegation rates and lists of delegators together with their delegated quantities from delegators. This function is publicly accessible, but intended for system use by the Handle Payment contract, because this data is necessary for distributing seigniorage.
Source§

fn add_bid( &mut self, public_key: PublicKey, delegation_rate: u8, amount: U512, minimum_delegation_amount: u64, maximum_delegation_amount: u64, minimum_bid_amount: u64, max_delegators_per_validator: u32, reserved_slots: u32, ) -> Result<U512, ApiError>

This entry point adds or modifies an entry in the Key::Bid section of the global state and creates (or tops off) a bid purse. Post genesis, any new call on this entry point causes a non-founding validator in the system to exist. Read more
Source§

fn withdraw_bid( &mut self, public_key: PublicKey, amount: U512, minimum_bid_amount: u64, ) -> Result<U512, Error>

Unbonds aka reduces stake by specified amount, adding an entry to the unbonding queue. For a genesis validator, this is subject to vesting if applicable to a given network. Read more
Source§

fn delegate( &mut self, delegator_kind: DelegatorKind, validator_public_key: PublicKey, amount: U512, max_delegators_per_validator: u32, ) -> Result<U512, ApiError>

Adds a new delegator to delegators or increases its current stake. If the target validator is missing, the function call returns an error and does nothing. Read more
Source§

fn undelegate( &mut self, delegator_kind: DelegatorKind, validator_public_key: PublicKey, amount: U512, ) -> Result<U512, Error>

Unbonds aka reduces stake by specified amount, adding an entry to the unbonding queue Read more
Source§

fn redelegate( &mut self, delegator_kind: DelegatorKind, validator_public_key: PublicKey, amount: U512, new_validator: PublicKey, ) -> Result<U512, Error>

Unbonds aka reduces stake by specified amount, adding an entry to the unbonding queue, which when processed will attempt to re-delegate the stake to the specified new validator. If this is not possible at that future point in time, the unbonded stake will instead downgrade to a standard undelegate operation automatically (the unbonded stake is returned to the associated purse). Read more
Source§

fn add_reservations( &mut self, reservations: Vec<Reservation>, ) -> Result<(), Error>

Adds new reservations for a given validator with specified delegator public keys and delegation rates. If during adding reservations configured number of reserved delegator slots is exceeded it returns an error. Read more
Source§

fn cancel_reservations( &mut self, validator: PublicKey, delegators: Vec<DelegatorKind>, max_delegators_per_validator: u32, ) -> Result<(), Error>

Removes reservations for given delegator public keys. If a reservation for one of the keys does not exist it returns an error.
Source§

fn slash(&mut self, validator_public_keys: Vec<PublicKey>) -> Result<(), Error>

Slashes each validator. Read more
Source§

fn run_auction( &mut self, era_end_timestamp_millis: u64, evicted_validators: Vec<PublicKey>, max_delegators_per_validator: u32, include_credits: bool, credit_cap: Ratio<U512>, minimum_bid_amount: u64, ) -> Result<(), ApiError>

Takes active_bids and delegators to construct a list of validators’ total bids (their own added to their delegators’) ordered by size from largest to smallest, then takes the top N (number of auction slots) bidders and replaces era_validators with these. Read more
Source§

fn distribute( &mut self, rewards: BTreeMap<PublicKey, Vec<U512>>, ) -> Result<(), Error>

Mint and distribute seigniorage rewards to validators and their delegators, according to reward_factors returned by the consensus component.
Source§

fn read_era_id(&mut self) -> Result<EraId, Error>

Reads current era id.
Source§

fn activate_bid( &mut self, validator: PublicKey, minimum_bid: u64, ) -> Result<(), Error>

Activates a given validator’s bid. To be used when a validator has been marked as inactive by consensus (aka “evicted”).
Source§

fn change_bid_public_key( &mut self, public_key: PublicKey, new_public_key: PublicKey, ) -> Result<(), Error>

Updates a ValidatorBid and all related delegator bids to use a new public key. Read more
Source§

fn write_validator_credit( &mut self, validator: PublicKey, era_id: EraId, amount: U512, ) -> Result<Option<BidAddr>, Error>

Writes a validator credit record.
Source§

impl<R> Externals for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn invoke_index( &mut self, index: usize, args: RuntimeArgs<'_>, ) -> Result<Option<RuntimeValue>, Trap>

Perform invoke of a host function by specified index.
Source§

impl<R> HandlePayment for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn get_payment_purse(&mut self) -> Result<URef, Error>

Get payment purse.
Source§

fn set_refund_purse(&mut self, purse: URef) -> Result<(), Error>

Set refund purse.
Source§

fn get_refund_purse(&mut self) -> Result<Option<URef>, Error>

Get refund purse.
Source§

fn clear_refund_purse(&mut self) -> Result<(), Error>

Clear refund purse.
Source§

fn calculate_overpayment_and_fee( &mut self, limit: U512, gas_price: u8, cost: U512, consumed: U512, source_purse: URef, refund_ratio: Ratio<U512>, ) -> Result<(U512, U512), Error>

Calculate overpayment and fees (if any) for payment finalization.
Source§

fn distribute_accumulated_fees( &mut self, source_uref: URef, amount: Option<U512>, ) -> Result<(), Error>

Distribute fees from an accumulation purse.
Source§

fn payment_burn( &mut self, source_uref: URef, amount: Option<U512>, ) -> Result<(), Error>

Burns the imputed amount from the imputed purse.
Source§

impl<R> Mint for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn purse_exists(&mut self, uref: URef) -> Result<bool, Error>

Check if a purse exists.
Source§

fn mint(&mut self, initial_balance: U512) -> Result<URef, Error>

Mint new token with given initial_balance balance. Returns new purse on success, otherwise an error.
Source§

fn burn(&mut self, purse: URef, amount: U512) -> Result<(), Error>

Burns native tokens.
Source§

fn reduce_total_supply(&mut self, amount: U512) -> Result<(), Error>

Reduce total supply by amount. Returns unit on success, otherwise an error.
Source§

fn balance(&mut self, purse: URef) -> Result<Option<U512>, Error>

Read balance of given purse.
Source§

fn transfer( &mut self, maybe_to: Option<AccountHash>, source: URef, target: URef, amount: U512, id: Option<u64>, ) -> Result<(), Error>

Transfers amount of tokens from source purse to a target purse.
Source§

fn read_base_round_reward(&mut self) -> Result<U512, Error>

Retrieves the base round reward.
Source§

fn mint_into_existing_purse( &mut self, existing_purse: URef, amount: U512, ) -> Result<(), Error>

Mint amount new token into existing_purse. Returns unit on success, otherwise an error.
Source§

impl<R> MintProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn mint_transfer_direct( &mut self, to: Option<AccountHash>, source: URef, target: URef, amount: U512, id: Option<u64>, ) -> Result<Result<(), Error>, Error>

Allows optimized auction and mint interaction. Intended to be used only by system contracts to manage staked purses. NOTE: Never expose this through FFI.

Source§

fn unbond( &mut self, unbond_kind: &UnbondKind, unbond_era: &UnbondEra, ) -> Result<(), Error>

Returns successfully unbonded stake to origin account.
Source§

fn mint_into_existing_purse( &mut self, amount: U512, existing_purse: URef, ) -> Result<(), Error>

Mint amount new token into existing_purse. Returns unit on success, otherwise an error.
Source§

fn create_purse(&mut self) -> Result<URef, Error>

Creates new purse.
Source§

fn available_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>

Gets purse balance.
Source§

fn read_base_round_reward(&mut self) -> Result<U512, Error>

Reads the base round reward.
Source§

fn mint(&mut self, amount: U512) -> Result<URef, Error>

Mints new token with given initial_balance balance. Returns new purse on success, otherwise an error.
Source§

fn reduce_total_supply(&mut self, amount: U512) -> Result<(), Error>

Reduce total supply by amount. Returns unit on success, otherwise an error.
Source§

impl<R> MintProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn transfer_purse_to_account( &mut self, source: URef, target: AccountHash, amount: U512, ) -> Result<TransferredTo, Error>

Transfer amount from source purse to a target account. Note: the source should always be a system purse of some kind, such as the payment purse or an accumulator purse. The target should be the recipient of a refund or a reward
Source§

fn transfer_purse_to_purse( &mut self, source: URef, target: URef, amount: U512, ) -> Result<(), Error>

Transfer amount from source purse to a target purse. Note: the source should always be a system purse of some kind, such as the payment purse or an accumulator purse. The target should be the recipient of a refund or a reward
Source§

fn available_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>

Checks balance of a purse. Returns None if given purse does not exist.
Source§

fn reduce_total_supply(&mut self, amount: U512) -> Result<(), Error>

Reduce total supply by amount.
Source§

impl<R> RuntimeProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn get_caller(&self) -> AccountHash

This method should return the caller of the current context.
Source§

fn is_allowed_session_caller(&self, account_hash: &AccountHash) -> bool

Checks if account_hash matches the active session’s account.
Source§

fn is_valid_uref(&self, uref: URef) -> bool

Checks if uref is in access rights.
Source§

fn named_keys_get(&self, name: &str) -> Option<Key>

Gets named key under a name.
Source§

fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, Error>

Gets keys in a given keyspace
Source§

fn get_keys_by_prefix(&mut self, prefix: &[u8]) -> Result<Vec<Key>, Error>

Gets keys by prefix.
Source§

fn delegator_count(&mut self, bid_addr: &BidAddr) -> Result<usize, Error>

Returns the current number of delegators for this validator.
Source§

fn reservation_count(&mut self, bid_addr: &BidAddr) -> Result<usize, Error>

Returns number of reservations for this validator.
Source§

fn used_reservation_count(&mut self, bid_addr: &BidAddr) -> Result<usize, Error>

Returns number of reservations for which a delegator bid exists.
Source§

fn vesting_schedule_period_millis(&self) -> u64

Returns vesting schedule period.
Source§

fn allow_auction_bids(&self) -> bool

Check if auction bids are allowed.
Source§

fn should_compute_rewards(&self) -> bool

Check if auction should compute rewards.
Source§

impl<R> RuntimeProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn get_key(&mut self, name: &str) -> Option<Key>

Get named key under a name.
Source§

fn put_key(&mut self, name: &str, key: Key) -> Result<(), Error>

Put key under a name.
Source§

fn remove_key(&mut self, name: &str) -> Result<(), Error>

Remove a named key by name.
Source§

fn get_phase(&self) -> Phase

Get current execution phase.
Source§

fn get_caller(&self) -> AccountHash

Get caller.
Source§

fn refund_handling(&self) -> RefundHandling

Get refund handling.
Source§

fn fee_handling(&self) -> FeeHandling

Returns fee handling value.
Source§

fn administrative_accounts(&self) -> BTreeSet<AccountHash>

Returns list of administrative accounts.
Source§

impl<R> RuntimeProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn is_valid_uref(&self, uref: &URef) -> bool

Validate URef against context access rights.

Source§

fn get_caller(&self) -> AccountHash

This method should return the caller of the current context.
Source§

fn get_immediate_caller(&self) -> Option<Caller>

This method should return the immediate caller of the current context.
Source§

fn is_called_from_standard_payment(&self) -> bool

Is the caller standard payment logic?
Source§

fn get_system_entity_registry( &self, ) -> Result<SystemHashRegistry, ProviderError>

Get system entity registry.
Source§

fn runtime_footprint_by_account_hash( &mut self, account_hash: AccountHash, ) -> Result<Option<RuntimeFootprint>, ProviderError>

Read addressable entity by account hash.
Source§

fn get_phase(&self) -> Phase

Gets execution phase
Source§

fn get_key(&self, name: &str) -> Option<Key>

This method should handle obtaining a given named Key under a name.
Source§

fn get_approved_spending_limit(&self) -> U512

Returns approved CSPR spending limit.
Source§

fn sub_approved_spending_limit(&mut self, transferred: U512)

Signal to host that amount of tokens has been transferred.
Source§

fn get_main_purse(&self) -> Option<URef>

Returns main purse of the sender account.
Source§

fn is_administrator(&self, account_hash: &AccountHash) -> bool

Returns true if the account hash belongs to an administrator account, otherwise false.
Source§

fn allow_unrestricted_transfers(&self) -> bool

Checks if users can perform unrestricted transfers. This option is valid only for private chains.
Source§

impl<R> StorageProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn read<T: FromBytes + CLTyped>( &mut self, uref: URef, ) -> Result<Option<T>, Error>

Reads data from URef.
Source§

fn write<T: ToBytes + CLTyped>( &mut self, uref: URef, value: T, ) -> Result<(), Error>

Writes data to `URef.
Source§

fn read_bid(&mut self, key: &Key) -> Result<Option<BidKind>, Error>

Reads casper_types::system::auction::Bid at account hash derived from given public key
Source§

fn write_bid(&mut self, key: Key, bid_kind: BidKind) -> Result<(), Error>

Writes given BidKind at given key.
Source§

fn read_unbond(&mut self, bid_addr: BidAddr) -> Result<Option<Unbond>, Error>

Reads Unbonds at bid address.
Source§

fn write_unbond( &mut self, bid_addr: BidAddr, unbond: Option<Unbond>, ) -> Result<(), Error>

Writes given Unbond if some, else prunes if none at bid address.
Source§

fn record_era_info(&mut self, era_info: EraInfo) -> Result<(), Error>

Records era info.
Source§

fn prune_bid(&mut self, bid_addr: BidAddr)

Prunes a given bid at BidAddr.
Source§

impl<R> StorageProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn write_balance(&mut self, purse_uref: URef, amount: U512) -> Result<(), Error>

Write new balance.
Source§

impl<R> StorageProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn new_uref<T: CLTyped + ToBytes>(&mut self, init: T) -> Result<URef, Error>

Create new URef.
Source§

fn read<T: CLTyped + FromBytes>( &mut self, uref: URef, ) -> Result<Option<T>, Error>

Read data from URef.
Source§

fn write_amount(&mut self, uref: URef, amount: U512) -> Result<(), Error>

Write a U512 amount under a URef.
Source§

fn add<T: CLTyped + ToBytes>( &mut self, uref: URef, value: T, ) -> Result<(), Error>

Add data to a URef.
Source§

fn total_balance(&mut self, purse: URef) -> Result<U512, Error>

Read total balance.
Source§

fn available_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>

Read balance.
Source§

fn write_balance(&mut self, uref: URef, balance: U512) -> Result<(), Error>

Write balance.
Source§

fn add_balance(&mut self, uref: URef, value: U512) -> Result<(), Error>

Add amount to an existing balance.
Source§

impl<R> SystemProvider for Runtime<'_, R>
where R: StateReader<Key, StoredValue, Error = Error>,

Source§

fn record_transfer( &mut self, maybe_to: Option<AccountHash>, source: URef, target: URef, amount: U512, id: Option<u64>, ) -> Result<(), Error>

Records a transfer.

Auto Trait Implementations§

§

impl<'a, R> Freeze for Runtime<'a, R>

§

impl<'a, R> !RefUnwindSafe for Runtime<'a, R>

§

impl<'a, R> !Send for Runtime<'a, R>

§

impl<'a, R> !Sync for Runtime<'a, R>

§

impl<'a, R> Unpin for Runtime<'a, R>

§

impl<'a, R> !UnwindSafe for Runtime<'a, R>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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