Struct RuntimeNative

Source
pub struct RuntimeNative<S> { /* private fields */ }
Expand description

State held by an instance of runtime native.

Implementations§

Source§

impl<S> RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

Source

pub fn new( config: Config, protocol_version: ProtocolVersion, id: Id, address_generator: Arc<RwLock<AddressGenerator>>, tracking_copy: Rc<RefCell<TrackingCopy<S>>>, address: AccountHash, context_key: Key, runtime_footprint: RuntimeFootprint, access_rights: ContextAccessRights, remaining_spending_limit: U512, phase: Phase, ) -> Self

Ctor.

Source

pub fn new_system_runtime( config: Config, protocol_version: ProtocolVersion, id: Id, address_generator: Arc<RwLock<AddressGenerator>>, tracking_copy: Rc<RefCell<TrackingCopy<S>>>, phase: Phase, ) -> Result<Self, TrackingCopyError>

Creates a runtime with elevated permissions for systemic behaviors.

Source

pub fn new_system_contract_runtime( config: Config, protocol_version: ProtocolVersion, id: Id, address_generator: Arc<RwLock<AddressGenerator>>, tracking_copy: Rc<RefCell<TrackingCopy<S>>>, phase: Phase, name: &str, ) -> Result<Self, TrackingCopyError>

Creates a runtime context for a system contract.

Source

pub fn address_generator(&mut self) -> Arc<RwLock<AddressGenerator>>

Returns mutable reference to address generator.

Source

pub fn config(&self) -> &Config

Returns reference to config.

Source

pub fn transfer_config(&self) -> &TransferConfig

Returns reference to transfer config.

Source

pub fn protocol_version(&self) -> ProtocolVersion

Returns protocol version.

Source

pub fn tracking_copy(&self) -> Rc<RefCell<TrackingCopy<S>>>

Returns handle to tracking copy.

Source

pub fn address(&self) -> AccountHash

Returns account hash being used by this instance.

Source

pub fn with_address(&mut self, account_hash: AccountHash)

Changes the account hash being used by this instance.

Source

pub fn context_key(&self) -> &Key

Returns the context key being used by this instance.

Source

pub fn runtime_footprint(&self) -> &RuntimeFootprint

Returns a reference to the runtime footprint used by this instance.

Source

pub fn runtime_footprint_mut(&mut self) -> &mut RuntimeFootprint

Returns the addressable entity being used by this instance.

Source

pub fn with_addressable_entity(&mut self, runtime_footprint: RuntimeFootprint)

Changes the addressable entity being used by this instance.

Source

pub fn named_keys(&self) -> &NamedKeys

Returns a reference to the named keys being used by this instance.

Source

pub fn named_keys_mut(&mut self) -> &mut NamedKeys

Returns a mutable reference to the named keys being used by this instance.

Source

pub fn access_rights(&self) -> &ContextAccessRights

Returns a reference to the access rights being used by this instance.

Source

pub fn access_rights_mut(&mut self) -> &mut ContextAccessRights

Returns a mutable reference to the access rights being used by this instance.

Source

pub fn extend_access_rights(&mut self, urefs: &[URef])

Extends the access rights being used by this instance.

Source

pub fn remaining_spending_limit(&self) -> U512

Returns the remaining spending limit.

Source

pub fn set_remaining_spending_limit(&mut self, remaining: U512)

Set remaining spending limit.

Source

pub fn transfers(&self) -> &Vec<Transfer>

Get references to transfers.

Source

pub fn push_transfer(&mut self, transfer: Transfer)

Push transfer instance.

Source

pub fn id(&self) -> &Id

Get id.

Source

pub fn phase(&self) -> Phase

Get phase.

Source

pub fn vesting_schedule_period_millis(&self) -> u64

Vesting schedule period in milliseconds.

Source

pub fn allow_auction_bids(&self) -> bool

Are auction bids allowed?

Source

pub fn compute_rewards(&self) -> bool

Are rewards computed?

Source

pub fn into_transfers(self) -> Vec<Transfer>

Extracts transfer items.

Trait Implementations§

Source§

impl<S> AccountProvider for RuntimeNative<S>
where S: 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<S> Auction for RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

Source§

fn get_era_validators(&mut self) -> Result<EraValidators, 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<SeigniorageRecipientsV2, 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: DelegationRate, 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<S> HandlePayment for RuntimeNative<S>
where S: 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<S> Mint for RuntimeNative<S>
where S: 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<S> MintProvider for RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

Source§

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

Returns successfully unbonded stake to origin account.
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.
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<S> MintProvider for RuntimeNative<S>
where S: 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<S> RuntimeProvider for RuntimeNative<S>
where S: 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<S> RuntimeProvider for RuntimeNative<S>
where S: 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<S> RuntimeProvider for RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

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, amount: 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§

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

Validate URef against context access rights.
Source§

impl<S> StorageProvider for RuntimeNative<S>
where S: 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<S> StorageProvider for RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

Source§

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

Write new balance.
Source§

impl<S> StorageProvider for RuntimeNative<S>
where S: StateReader<Key, StoredValue, Error = Error>,

Source§

fn new_uref<T: CLTyped + ToBytes>(&mut self, value: 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<S> SystemProvider for RuntimeNative<S>
where S: 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<S> Freeze for RuntimeNative<S>

§

impl<S> !RefUnwindSafe for RuntimeNative<S>

§

impl<S> !Send for RuntimeNative<S>

§

impl<S> !Sync for RuntimeNative<S>

§

impl<S> Unpin for RuntimeNative<S>

§

impl<S> !UnwindSafe for RuntimeNative<S>

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