diff --git a/demo/executor/src/lib.rs b/demo/executor/src/lib.rs index f0cb26cce3292..ce864d7592872 100644 --- a/demo/executor/src/lib.rs +++ b/demo/executor/src/lib.rs @@ -260,10 +260,7 @@ mod tests { construct_block( 1, [69u8; 32].into(), - // Blake - // hex!("3437bf4b182ab17bb322af5c67e55f6be487a77084ad2b4e27ddac7242e4ad21").into(), - // Keccak - hex!("508a68a0918f614b86b2ccfd0975754f6d2abe1026a34e42d6d8d5abdf4db010").into(), + hex!("ddfc4d60889b25215f4fe6ead4e38b7522fa20809a793476eae3ad5ab2d9c399").into(), vec![CheckedExtrinsic { signed: Some(alice()), index: 0, @@ -276,10 +273,7 @@ mod tests { construct_block( 2, block1().1, - // Blake - // hex!("741fcb660e6fa9f625fbcd993b49f6c1cc4040f5e0cc8727afdedf11fd3c464b").into(), - // Keccak - hex!("a72ec570c7642d9ad06ef0e5dd37be65fb04b71e0ab52b3927d760ed6c777a1f").into(), + hex!("2b4464c7e0d51325505663ae2ebd2246fcefc5cb998e9c29d8030c559cbbf27f").into(), vec![ CheckedExtrinsic { signed: Some(bob()), @@ -299,9 +293,6 @@ mod tests { construct_block( 1, [69u8; 32].into(), - // Blake - // hex!("2c7231a9c210a7aa4bea169d944bc4aaacd517862b244b8021236ffa7f697991").into(), - // Keccak hex!("e45221804da3a3609454d4e09debe6364cc6af63c2ff067d802d1af62fea32ae").into(), vec![CheckedExtrinsic { signed: Some(alice()), @@ -325,6 +316,15 @@ mod tests { phase: Phase::ApplyExtrinsic(0), event: Event::balances(balances::RawEvent::NewAccount(bob(), 1, balances::NewAccountOutcome::NoHint)) }, + EventRecord { + phase: Phase::ApplyExtrinsic(0), + event: Event::balances(balances::RawEvent::Transfer( + hex!["d172a74cda4c865912c32ba0a80a57ae69abae410e5ccb59dee84e2f4432db4f"].into(), + hex!["d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9"].into(), + 69, + 0 + )) + }, EventRecord { phase: Phase::ApplyExtrinsic(0), event: Event::system(system::Event::ExtrinsicSuccess) @@ -338,10 +338,32 @@ mod tests { assert_eq!(Balances::total_balance(&alice()), 30); assert_eq!(Balances::total_balance(&bob()), 78); assert_eq!(System::events(), vec![ + EventRecord { + phase: Phase::ApplyExtrinsic(0), + event: Event::balances( + balances::RawEvent::Transfer( + hex!["d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9"].into(), + hex!["d172a74cda4c865912c32ba0a80a57ae69abae410e5ccb59dee84e2f4432db4f"].into(), + 5, + 0 + ) + ) + }, EventRecord { phase: Phase::ApplyExtrinsic(0), event: Event::system(system::Event::ExtrinsicSuccess) }, + EventRecord { + phase: Phase::ApplyExtrinsic(1), + event: Event::balances( + balances::RawEvent::Transfer( + hex!["d172a74cda4c865912c32ba0a80a57ae69abae410e5ccb59dee84e2f4432db4f"].into(), + hex!["d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9"].into(), + 15, + 0 + ) + ) + }, EventRecord { phase: Phase::ApplyExtrinsic(1), event: Event::system(system::Event::ExtrinsicSuccess) diff --git a/demo/runtime/src/lib.rs b/demo/runtime/src/lib.rs index 9429c1a04e6cb..114351b91d628 100644 --- a/demo/runtime/src/lib.rs +++ b/demo/runtime/src/lib.rs @@ -148,6 +148,7 @@ pub type Staking = staking::Module; impl democracy::Trait for Runtime { type Proposal = Call; + type Event = Event; } /// Democracy module for this concrete runtime. @@ -162,7 +163,7 @@ pub type CouncilVoting = council::voting::Module; impl_outer_event! { pub enum Event for Runtime { - balances, session, staking + balances, session, staking, democracy } } diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm index de2df76c99f6f..c9521e1aae5b7 100644 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm differ diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm index e020bc5c087a5..4da0e20cc20b9 100755 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm differ diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm index 53ccb4352ecc0..4206e8627cd3e 100644 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm differ diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm index 0dbc2656ca2e6..a8c597e6f0f9f 100755 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm differ diff --git a/substrate/runtime/balances/src/lib.rs b/substrate/runtime/balances/src/lib.rs index 71a2ba2bfe7e1..d7588289b8898 100644 --- a/substrate/runtime/balances/src/lib.rs +++ b/substrate/runtime/balances/src/lib.rs @@ -69,7 +69,8 @@ pub type Address = RawAddress<::AccountId, :: pub type Event = RawEvent< ::AccountId, - ::AccountIndex + ::AccountIndex, + ::Balance, >; /// The account with the given id was killed. @@ -142,15 +143,17 @@ decl_module! { /// An event in this module. #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] #[derive(Encode, Decode, PartialEq, Eq, Clone)] -pub enum RawEvent { +pub enum RawEvent { /// A new account was created. NewAccount(AccountId, AccountIndex, NewAccountOutcome), /// An account was reaped. ReapedAccount(AccountId), + /// Transfer succeeded (from, to, value, fees). + Transfer(AccountId, AccountId, Balance, Balance), } -impl From> for () { - fn from(_: RawEvent) -> () { () } +impl From> for () { + fn from(_: RawEvent) -> () { () } } decl_storage! { @@ -312,6 +315,7 @@ impl Module { Self::set_free_balance(&transactor, new_from_balance); Self::decrease_total_stake_by(fee); Self::set_free_balance_creating(&dest, new_to_balance); + Self::deposit_event(RawEvent::Transfer(transactor, dest, value, fee)); } Ok(()) diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index 0ff41c2743f9f..483c07c79dcad 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -665,6 +665,7 @@ mod tests { } impl democracy::Trait for Test { type Proposal = Call; + type Event = (); } impl Trait for Test {} diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index 28e467296429a..ed3faf95b57fd 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -61,6 +61,8 @@ pub type ReferendumIndex = u32; pub trait Trait: balances::Trait + Sized { type Proposal: Parameter + Dispatchable + IsSubType> + MaybeSerializeDebug; + + type Event: From> + Into<::Event>; } decl_module! { @@ -106,8 +108,34 @@ decl_storage! { } } +/// An event in this module. +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] +#[derive(Encode, Decode, PartialEq, Eq, Clone)] +pub enum RawEvent { + Tabled(PropIndex, Balance, Vec), + Started(ReferendumIndex, VoteThreshold), + Passed(ReferendumIndex), + NotPassed(ReferendumIndex), + Cancelled(ReferendumIndex), + Executed(ReferendumIndex, bool), +} + +impl From> for () { + fn from(_: RawEvent) -> () { () } +} + +pub type Event = RawEvent< + ::Balance, + ::AccountId, +>; + impl Module { + /// Deposit one of this module's events. + fn deposit_event(event: Event) { + >::deposit_event(::Event::from(event).into()); + } + // exposed immutables. /// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal @@ -180,16 +208,14 @@ impl Module { } /// Vote in a referendum. If `approve_proposal` is true, the vote is to enact the proposal; - /// false would be a vote to keep the status quo.. + /// false would be a vote to keep the status quo. fn vote(origin: T::Origin, ref_index: ReferendumIndex, approve_proposal: bool) -> Result { let who = ensure_signed(origin)?; ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); ensure!(!>::total_balance(&who).is_zero(), "transactor must have balance to signal approval."); if !>::exists(&(ref_index, who.clone())) { - let mut voters = Self::voters_for(ref_index); - voters.push(who.clone()); - >::insert(ref_index, voters); + >::mutate(ref_index, |voters| voters.push(who.clone())); } >::insert(&(ref_index, who), approve_proposal); Ok(()) @@ -221,6 +247,7 @@ impl Module { /// Remove a referendum. Can be called directly by the council. pub fn internal_cancel_referendum(ref_index: ReferendumIndex) { + Self::deposit_event(RawEvent::Cancelled(ref_index)); >::clear_referendum(ref_index); } @@ -239,6 +266,7 @@ impl Module { >::put(ref_index + 1); >::insert(ref_index, (end, proposal, vote_threshold)); + Self::deposit_event(RawEvent::Started(ref_index, vote_threshold)); Ok(ref_index) } @@ -261,15 +289,15 @@ impl Module { .max_by_key(|x| Self::locked_for((x.1).0).unwrap_or_else(Zero::zero)/*defensive only: All current public proposals have an amount locked*/) { let (prop_index, proposal, _) = public_props.swap_remove(winner_index); + >::put(public_props); + if let Some((deposit, depositors)) = >::take(prop_index) {//: (T::Balance, Vec) = // refund depositors for d in &depositors { >::unreserve(d, deposit); } - >::put(public_props); + Self::deposit_event(RawEvent::Tabled(prop_index, deposit, depositors)); Self::inject_referendum(now + Self::voting_period(), proposal, VoteThreshold::SuperMajorityApprove)?; - } else { - return Err("depositors always exist for current proposals") } } } @@ -280,7 +308,11 @@ impl Module { let total_stake = >::total_stake(); Self::clear_referendum(index); if vote_threshold.approved(approve, against, total_stake) { - proposal.dispatch(system::RawOrigin::Root.into())?; + Self::deposit_event(RawEvent::Passed(index)); + let ok = proposal.dispatch(system::RawOrigin::Root.into()).is_ok(); + Self::deposit_event(RawEvent::Executed(index, ok)); + } else { + Self::deposit_event(RawEvent::NotPassed(index)); } >::put(index + 1); } @@ -388,6 +420,7 @@ mod tests { } impl Trait for Test { type Proposal = Call; + type Event = (); } fn new_test_ext() -> runtime_io::TestExternalities { diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index 82f46bf79d94c..78677fe859714 100644 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm index 50dd75b11d51e..92496dc47198f 100755 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm differ