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:
Xiliang Chen
2019-10-10 23:41:42 +13:00
committed by Bastian Köcher
parent 21fae718c4
commit 34c7338211
8 changed files with 46 additions and 33 deletions
+1 -3
View File
@@ -17,8 +17,6 @@ rstd = { package = "sr-std", path = "../../core/sr-std", default-features = fals
sandbox = { package = "sr-sandbox", path = "../../core/sr-sandbox", default-features = false }
support = { package = "srml-support", path = "../support", default-features = false }
system = { package = "srml-system", path = "../system", default-features = false }
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../randomness-collective-flip", default-features = false }
timestamp = { package = "srml-timestamp", path = "../timestamp", default-features = false }
[dev-dependencies]
wabt = "0.9.2"
@@ -27,6 +25,7 @@ hex-literal = "0.2.1"
balances = { package = "srml-balances", path = "../balances" }
hex = "0.3.2"
timestamp = { package = "srml-timestamp", path = "../timestamp" }
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../randomness-collective-flip" }
[features]
default = ["std"]
@@ -35,7 +34,6 @@ std = [
"codec/std",
"primitives/std",
"sr-primitives/std",
"randomness-collective-flip/std",
"runtime-io/std",
"rstd/std",
"sandbox/std",
+2 -2
View File
@@ -22,7 +22,7 @@ use crate::rent;
use rstd::prelude::*;
use sr_primitives::traits::{Bounded, CheckedAdd, CheckedSub, Zero};
use support::traits::{WithdrawReason, Currency, Time};
use support::traits::{WithdrawReason, Currency, Time, Randomness};
pub type AccountIdOf<T> = <T as system::Trait>::AccountId;
pub type CallOf<T> = <T as Trait>::Call;
@@ -753,7 +753,7 @@ where
}
fn random(&self, subject: &[u8]) -> SeedOf<T> {
randomness_collective_flip::Module::<T>::random(subject)
T::Randomness::random(subject)
}
fn now(&self) -> &MomentOf<T> {
+3 -2
View File
@@ -122,9 +122,9 @@ use sr_primitives::{
use support::dispatch::{Result, Dispatchable};
use support::{
Parameter, decl_module, decl_event, decl_storage, storage::child,
parameter_types,
parameter_types, IsSubType
};
use support::{traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time}, IsSubType};
use support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness};
use system::{ensure_signed, RawOrigin, ensure_root};
use primitives::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
@@ -335,6 +335,7 @@ parameter_types! {
pub trait Trait: system::Trait {
type Currency: Currency<Self::AccountId>;
type Time: Time;
type Randomness: Randomness<Self::Hash>;
/// The outer call dispatch type.
type Call: Parameter + Dispatchable<Origin=<Self as system::Trait>::Origin> + IsSubType<Module<Self>, Self>;
+2
View File
@@ -159,6 +159,7 @@ parameter_types! {
impl Trait for Test {
type Currency = Balances;
type Time = Timestamp;
type Randomness = Randomness;
type Call = Call;
type DetermineContractAddress = DummyContractAddressFor;
type Event = MetaEvent;
@@ -187,6 +188,7 @@ type Balances = balances::Module<Test>;
type Timestamp = timestamp::Module<Test>;
type Contract = Module<Test>;
type System = system::Module<Test>;
type Randomness = randomness_collective_flip::Module<Test>;
pub struct DummyContractAddressFor;
impl ContractAddressFor<H256, u64> for DummyContractAddressFor {