mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 08:37:56 +00:00
Decouple randomness-collective-flip (#3792)
* Abstract Randomness trait * bump version * fix doc test * simpify code a bit * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * fix tests
This commit is contained in:
committed by
Bastian Köcher
parent
21fae718c4
commit
34c7338211
@@ -717,3 +717,23 @@ pub trait InitializeMembers<AccountId> {
|
||||
impl<T> InitializeMembers<T> for () {
|
||||
fn initialize_members(_: &[T]) {}
|
||||
}
|
||||
|
||||
// A trait that is able to provide randomness.
|
||||
pub trait Randomness<Output> {
|
||||
/// Get a "random" value
|
||||
///
|
||||
/// Being a deterministic blockchain, real randomness is difficult to come by. This gives you
|
||||
/// something that approximates it. `subject` is a context identifier and allows you to get a
|
||||
/// different result to other callers of this function; use it like
|
||||
/// `random(&b"my context"[..])`.
|
||||
fn random(subject: &[u8]) -> Output;
|
||||
|
||||
/// Get the basic random seed.
|
||||
///
|
||||
/// In general you won't want to use this, but rather `Self::random` which allows you to give a
|
||||
/// subject for the random result and whose value will be independently low-influence random
|
||||
/// from any other such seeds.
|
||||
fn random_seed() -> Output {
|
||||
Self::random(&[][..])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user