Crates.io | pallet-randomness-collective-flip |
lib.rs | pallet-randomness-collective-flip |
version | 15.0.0 |
source | src |
created_at | 2020-02-27 09:38:06.833098 |
updated_at | 2023-02-05 12:50:49.416597 |
description | FRAME randomness collective flip pallet |
homepage | https://substrate.io |
repository | https://github.com/paritytech/substrate/ |
max_upload_size | |
id | 213032 |
size | 13,996 |
The Randomness Collective Flip module provides a random
function that generates low-influence random values based on the block hashes from the previous
81
blocks. Low-influence randomness can be useful when defending against relatively weak
adversaries. Using this pallet as a randomness source is advisable primarily in low-security
situations like testing.
See the Module
struct for details of publicly available functions.
Import the Randomness Collective Flip module and derive your module's configuration trait from the system trait.
use frame_support::traits::Randomness;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config + pallet_randomness_collective_flip::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn random_module_example(origin: OriginFor<T>) -> DispatchResult {
let _random_value = <pallet_randomness_collective_flip::Pallet<T>>::random(&b"my context"[..]);
Ok(())
}
}
}
License: Apache-2.0