referrerpolicy=no-referrer-when-downgrade

Type Alias pallet_babe::pallet::Randomness

source ·
pub type Randomness<T> = StorageValue<_GeneratedPrefixForStorageRandomness<T>, Randomness, ValueQuery>;
Expand description

The epoch randomness for the current epoch.

§Security

This MUST NOT be used for gambling, as it can be influenced by a malicious validator in the short term. It MAY be used in many cryptographic protocols, however, so long as one remembers that this (like everything else on-chain) it is public. For example, it can be used where a number is needed that cannot have been chosen by an adversary, for purposes such as public-coin zero-knowledge proofs.

Storage type is [StorageValue] with value type BabeRandomness.

Aliased Type§

struct Randomness<T>(/* private fields */);

Implementations

§

impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty>
where Prefix: StorageInstance, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query> + 'static,

pub fn hashed_key() -> [u8; 32]

Get the storage key.

pub fn exists() -> bool

Does the value (explicitly) exist in storage?

pub fn get() -> <QueryKind as QueryKindTrait<Value, OnEmpty>>::Query

Load the value from the provided storage instance.

pub fn try_get() -> Result<Value, ()>

Try to get the underlying value from the provided storage instance; Ok if it exists, Err if not.

pub fn translate<O, F>(f: F) -> Result<Option<Value>, ()>
where O: Decode, F: FnOnce(Option<O>) -> Option<Value>,

Translate a value from some previous type (O) to the current type.

f: F is the translation function.

Returns Err if the storage item could not be interpreted as the old type, and Ok, along with the new value if it could.

NOTE: This operates from and to Option<_> types; no effort is made to respect the default value of the original type.

§Warning

This function must be used with care, before being updated the storage still contains the old type, thus other calls (such as get) will fail at decoding it.

§Usage

This would typically be called inside the module implementation of on_runtime_upgrade, while ensuring no usage of this storage are made before the call to on_runtime_upgrade. (More precisely prior initialized modules doesn’t make use of this storage).

pub fn put<Arg>(val: Arg)
where Arg: EncodeLike<Value>,

Store a value under this key into the provided storage instance.

pub fn set(val: <QueryKind as QueryKindTrait<Value, OnEmpty>>::Query)

Store a value under this key into the provided storage instance.

this uses the query type rather than the underlying value.

pub fn mutate<R, F>(f: F) -> R
where F: FnOnce(&mut <QueryKind as QueryKindTrait<Value, OnEmpty>>::Query) -> R,

Mutate the value

pub fn mutate_extant<R, F>(f: F) -> R
where R: Default, F: FnOnce(&mut Value) -> R,

Mutate the value under a key iff it exists. Do nothing and return the default value if not.

pub fn try_mutate<R, E, F>(f: F) -> Result<R, E>
where F: FnOnce(&mut <QueryKind as QueryKindTrait<Value, OnEmpty>>::Query) -> Result<R, E>,

Mutate the value if closure returns Ok

pub fn mutate_exists<R, F>(f: F) -> R
where F: FnOnce(&mut Option<Value>) -> R,

Mutate the value. Deletes the item if mutated to a None.

pub fn try_mutate_exists<R, E, F>(f: F) -> Result<R, E>
where F: FnOnce(&mut Option<Value>) -> Result<R, E>,

Mutate the value if closure returns Ok. Deletes the item if mutated to a None.

pub fn kill()

Clear the storage value.

pub fn take() -> <QueryKind as QueryKindTrait<Value, OnEmpty>>::Query

Take a value from storage, removing it afterwards.

pub fn append<Item, EncodeLikeItem>(item: EncodeLikeItem)
where Item: Encode, EncodeLikeItem: EncodeLike<Item>, Value: StorageAppend<Item>,

Append the given item to the value in the storage.

Value is required to implement [StorageAppend].

§Warning

If the storage item is not encoded properly, the storage item will be overwritten and set to [item]. Any default value set for the storage item will be ignored on overwrite.

pub fn decode_len() -> Option<usize>
where Value: StorageDecodeLength,

Read the length of the storage value without decoding the entire value.

Value is required to implement [StorageDecodeLength].

If the value does not exists or it fails to decode the length, None is returned. Otherwise Some(len) is returned.

§Warning

None does not mean that get() does not return a value. The default value is completely ignored by this function.

pub fn decode_non_dedup_len() -> Option<usize>
where Value: StorageDecodeNonDedupLength,

Read the length of the storage value without decoding the entire value.

Value is required to implement [StorageDecodeNonDedupLength].

If the value does not exists or it fails to decode the length, None is returned. Otherwise Some(len) is returned.

§Warning
  • None does not mean that get() does not return a value. The default value is completely ignored by this function.

  • The value returned is the non-deduplicated length of the underlying Vector in storage.This means that any duplicate items are included.

pub fn try_append<Item, EncodeLikeItem>(item: EncodeLikeItem) -> Result<(), ()>
where Item: Encode, EncodeLikeItem: EncodeLike<Item>, Value: StorageTryAppend<Item>,

Try and append the given item to the value in the storage.

Is only available if Value of the storage implements [StorageTryAppend].

Trait Implementations

§

impl<Prefix, Value, QueryKind, OnEmpty> PartialStorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty>
where Prefix: StorageInstance, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query> + 'static,

It doesn’t require to implement MaxEncodedLen and give no information for max_size.

§

fn partial_storage_info() -> Vec<StorageInfo>

§

impl<Prefix, Value, QueryKind, OnEmpty> StorageEntryMetadataBuilder for StorageValue<Prefix, Value, QueryKind, OnEmpty>
where Prefix: StorageInstance, Value: FullCodec + StaticTypeInfo, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query> + 'static,

§

fn build_metadata( deprecation_status: DeprecationStatusIR, docs: Vec<&'static str>, entries: &mut Vec<StorageEntryMetadataIR>, )

Build into entries the storage metadata entries of a storage given some docs.
§

impl<Prefix, Value, QueryKind, OnEmpty> StorageInfoTrait for StorageValue<Prefix, Value, QueryKind, OnEmpty>
where Prefix: StorageInstance, Value: FullCodec + MaxEncodedLen, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query> + 'static,

§

fn storage_info() -> Vec<StorageInfo>

§

impl<Prefix, Value, QueryKind, OnEmpty> TryDecodeEntireStorage for StorageValue<Prefix, Value, QueryKind, OnEmpty>
where Prefix: StorageInstance, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query> + 'static,

§

fn try_decode_entire_state() -> Result<usize, Vec<TryDecodeEntireStorageError>>

Decode the entire data under the given storage, returning Ok(bytes_decoded) if success.