Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial draft
  • Loading branch information
gavofyork committed Aug 31, 2018
commit a530639646634ef6010bc6c54c6a37574842cd7f
6 changes: 6 additions & 0 deletions substrate/runtime-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ macro_rules! impl_outer_event {
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum $name {
system($crate::system::Event),
$(
$module($module::Event<$trait>),
)*
}
impl From<$crate::system::Event> for $name {
fn from(x: $create::system::Event) -> Self {
$name::system(x)
}
}
$(
impl From<$module::Event<$trait>> for $name {
fn from(x: $module::Event<$trait>) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct Executive<
Lookup,
Payment,
Finalisation,
>(PhantomData<(System, Block, Lookup, Payment, Finalisation)>);
>(PhantomData<(System, Block, Lookup, Payment, Event, Finalisation)>);

impl<
Address,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<
// decode parameters and dispatch
let r = xt.apply();

<system::Module<System>>::note_applied_extrinsic();
<system::Module<System>>::note_applied_extrinsic(&r);

r.map(|_| internal::ApplyOutcome::Success).or_else(|e| Ok(internal::ApplyOutcome::Fail(e)))
}
Expand Down
21 changes: 19 additions & 2 deletions substrate/runtime/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub trait Trait: Eq + Clone {
Hash = Self::Hash,
Digest = Self::Digest
>;
type Event: Parameter + Member;
type Event: Parameter + Member + From<Event>;
}

decl_module! {
Expand All @@ -110,6 +110,18 @@ pub struct EventRecord<E: Parameter + Member> {
pub event: E,
}

/// Event for the system module.
pub enum Event {
/// An extrinsic completed successfully.
ExtrinsicSuccess,
/// An extrinsic failed.
ExtrinsicFailed,
}

impl<N> From<RawEvent<N>> for () {
fn from(_: RawEvent<N>) -> () { () }
}

decl_storage! {
trait Store for Module<T: Trait> as System {

Expand Down Expand Up @@ -230,7 +242,12 @@ impl<T: Trait> Module<T> {
}

/// To be called immediately after an extrinsic has been applied.
pub fn note_applied_extrinsic() {
pub fn note_applied_extrinsic(r: &Result<(), &'static str>) {
Self::deposit_event(r
.map(|_| Event::ExtrinsicSuccess)
.map_err(|_| Event::ExtrinsicFailed)
.into()
);
<ExtrinsicIndex<T>>::put(<ExtrinsicIndex<T>>::get().unwrap_or_default() + 1u32);
}

Expand Down