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>
impl<'a, R> Runtime<'a, R>
Sourcepub fn call_contract(
&mut self,
contract_hash: AddressableEntityHash,
entry_point_name: &str,
args: RuntimeArgs,
) -> Result<CLValue, ExecError>
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
.
Sourcepub fn call_versioned_contract(
&mut self,
contract_package_hash: PackageHash,
contract_version: Option<EntityVersion>,
entry_point_name: String,
args: RuntimeArgs,
) -> Result<CLValue, ExecError>
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.
Sourcepub fn take_host_buffer(&mut self) -> Option<CLValue>
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>
impl<R> AccountProvider for Runtime<'_, R>
Source§fn set_main_purse(&mut self, purse: URef)
fn set_main_purse(&mut self, purse: URef)
Set main purse.
Source§impl<R> Auction for Runtime<'_, R>
impl<R> Auction for Runtime<'_, R>
Source§fn get_era_validators(
&mut self,
) -> Result<BTreeMap<EraId, BTreeMap<PublicKey, U512>>, Error>
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>
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>
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 moreSource§fn withdraw_bid(
&mut self,
public_key: PublicKey,
amount: U512,
minimum_bid_amount: u64,
) -> Result<U512, Error>
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>
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>
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>
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 forced_undelegate(&mut self) -> Result<(), Error>
fn forced_undelegate(&mut self) -> Result<(), Error>
Unbond delegator bids which fall outside validator-configured delegation limits.
Source§fn add_reservations(
&mut self,
reservations: Vec<Reservation>,
) -> Result<(), Error>
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>
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>
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>
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>
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 activate_bid(
&mut self,
validator: PublicKey,
minimum_bid: u64,
) -> Result<(), Error>
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§impl<R> Externals for Runtime<'_, R>
impl<R> Externals for Runtime<'_, R>
Source§fn invoke_index(
&mut self,
index: usize,
args: RuntimeArgs<'_>,
) -> Result<Option<RuntimeValue>, Trap>
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>
impl<R> HandlePayment for Runtime<'_, R>
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>
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§impl<R> Mint for Runtime<'_, R>
impl<R> Mint for Runtime<'_, R>
Source§fn mint(&mut self, initial_balance: U512) -> Result<URef, Error>
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 reduce_total_supply(&mut self, amount: U512) -> Result<(), Error>
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>
fn balance(&mut self, purse: URef) -> Result<Option<U512>, Error>
Read balance of given
purse
.Source§impl<R> MintProvider for Runtime<'_, R>
impl<R> MintProvider for Runtime<'_, R>
Source§fn mint_transfer_direct(
&mut self,
to: Option<AccountHash>,
source: URef,
target: URef,
amount: U512,
id: Option<u64>,
) -> Result<Result<(), Error>, Error>
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>
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>
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 available_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>
fn available_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>
Gets purse balance.
Source§impl<R> MintProvider for Runtime<'_, R>
impl<R> MintProvider for Runtime<'_, R>
Source§fn transfer_purse_to_account(
&mut self,
source: URef,
target: AccountHash,
amount: U512,
) -> Result<TransferredTo, Error>
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 rewardSource§fn transfer_purse_to_purse(
&mut self,
source: URef,
target: URef,
amount: U512,
) -> Result<(), Error>
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 rewardSource§impl<R> RuntimeProvider for Runtime<'_, R>
impl<R> RuntimeProvider for Runtime<'_, R>
Source§fn get_caller(&self) -> AccountHash
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
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
fn is_valid_uref(&self, uref: URef) -> bool
Checks if uref is in access rights.
Source§fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, Error>
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>
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>
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>
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>
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
fn vesting_schedule_period_millis(&self) -> u64
Returns vesting schedule period.
Source§fn allow_auction_bids(&self) -> bool
fn allow_auction_bids(&self) -> bool
Check if auction bids are allowed.
Source§fn should_compute_rewards(&self) -> bool
fn should_compute_rewards(&self) -> bool
Check if auction should compute rewards.
Source§impl<R> RuntimeProvider for Runtime<'_, R>
impl<R> RuntimeProvider for Runtime<'_, R>
Source§fn get_caller(&self) -> AccountHash
fn get_caller(&self) -> AccountHash
Get caller.
Source§fn refund_handling(&self) -> RefundHandling
fn refund_handling(&self) -> RefundHandling
Get refund handling.
Source§fn fee_handling(&self) -> FeeHandling
fn fee_handling(&self) -> FeeHandling
Returns fee handling value.
Source§fn administrative_accounts(&self) -> BTreeSet<AccountHash>
fn administrative_accounts(&self) -> BTreeSet<AccountHash>
Returns list of administrative accounts.
Source§impl<R> RuntimeProvider for Runtime<'_, R>
impl<R> RuntimeProvider for Runtime<'_, R>
Source§fn is_valid_uref(&self, uref: &URef) -> bool
fn is_valid_uref(&self, uref: &URef) -> bool
Validate URef against context access rights.
Source§fn get_caller(&self) -> AccountHash
fn get_caller(&self) -> AccountHash
This method should return the caller of the current context.
Source§fn get_immediate_caller(&self) -> Option<Caller>
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
fn is_called_from_standard_payment(&self) -> bool
Is the caller standard payment logic?
Source§fn get_system_entity_registry(
&self,
) -> Result<SystemHashRegistry, ProviderError>
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>
fn runtime_footprint_by_account_hash( &mut self, account_hash: AccountHash, ) -> Result<Option<RuntimeFootprint>, ProviderError>
Read addressable entity by account hash.
Source§fn get_key(&self, name: &str) -> Option<Key>
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
fn get_approved_spending_limit(&self) -> U512
Returns approved CSPR spending limit.
Source§fn sub_approved_spending_limit(&mut self, transferred: U512)
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>
fn get_main_purse(&self) -> Option<URef>
Returns main purse of the sender account.
Source§fn is_administrator(&self, account_hash: &AccountHash) -> bool
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
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>
impl<R> StorageProvider for Runtime<'_, R>
Source§fn read<T: FromBytes + CLTyped>(
&mut self,
uref: URef,
) -> Result<Option<T>, Error>
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>
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>
fn read_bid(&mut self, key: &Key) -> Result<Option<BidKind>, Error>
Reads
casper_types::system::auction::Bid
at account hash derived from given public keySource§fn write_bid(&mut self, key: Key, bid_kind: BidKind) -> Result<(), Error>
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>
fn read_unbond(&mut self, bid_addr: BidAddr) -> Result<Option<Unbond>, Error>
Reads
Unbond
s at bid address.Source§impl<R> StorageProvider for Runtime<'_, R>
impl<R> StorageProvider for Runtime<'_, R>
Source§impl<R> StorageProvider for Runtime<'_, R>
impl<R> StorageProvider for Runtime<'_, R>
Source§fn read<T: CLTyped + FromBytes>(
&mut self,
uref: URef,
) -> Result<Option<T>, Error>
fn read<T: CLTyped + FromBytes>( &mut self, uref: URef, ) -> Result<Option<T>, Error>
Read data from
URef
.Source§impl<R> SystemProvider for Runtime<'_, R>
impl<R> SystemProvider for Runtime<'_, R>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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