Make deposit_event work with none generic events (#1309)

* Make `deposit_event` work with none generic events

`fn deposit_event() = default` will now be used for none generic events
`fn deposit_event<T>() = default` is now for generic events.

* Update wasm files

* Fixes some spelling mistakes

* Update wasm and fix new module
This commit is contained in:
Bastian Köcher
2018-12-22 17:37:05 +01:00
committed by Gav Wood
parent 031826ebdb
commit d15cc63370
17 changed files with 39 additions and 19 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ type AssetId = u32;
decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
/// such assets and they'll all belong to the `origin` initially. It will have an
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
+1 -1
View File
@@ -136,7 +136,7 @@ pub trait Trait: system::Trait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Transfer some liquid free balance to another staker.
pub fn transfer(
+1 -1
View File
@@ -147,7 +147,7 @@ where
decl_module! {
/// Contracts module.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
// TODO: Change AccountId to staking::Address
/// Make a call to a specified account, optionally transferring some balance.
/// Make a call to a specified account, optionally transferring some balance.
+1 -1
View File
@@ -67,7 +67,7 @@ decl_event!(
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
fn propose(origin, threshold: Compact<u32>, proposal: Box<<T as Trait>::Proposal>) {
let who = ensure_signed(origin)?;
let threshold = threshold.into();
+1 -1
View File
@@ -87,7 +87,7 @@ pub trait Trait: democracy::Trait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
/// are registered.
+1 -1
View File
@@ -33,7 +33,7 @@ pub trait Trait: CouncilTrait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
fn propose(origin, proposal: Box<T::Proposal>) {
let who = ensure_signed(origin)?;
+2 -2
View File
@@ -87,7 +87,7 @@ pub trait Trait: balances::Trait + Sized {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Propose a sensitive action to be taken.
fn propose(
@@ -376,7 +376,7 @@ impl<T: Trait> Module<T> {
.map(|a| (a.clone(), Self::vote_of((index, a))))
// ^^^ defensive only: all items come from `voters`; for an item to be in `voters` there must be a vote registered; qed
.filter(|&(_, vote)| vote.is_aye() == approved) // Just the winning coins
{
{
// now plus: the base lock period multiplied by the number of periods this voter offered to
// lock should they win...
let locked_until = now + lock_period * T::BlockNumber::sa((vote.multiplier()) as u64);
+3 -1
View File
@@ -98,7 +98,9 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Deposit one of this module's events by using the default implementation.
/// It is also possible to provide a custom implementation.
fn deposit_event() = default;
/// For non-generic events, the generic parameter just needs to be dropped, so that it
/// looks like: `fn deposit_event() = default;`.
fn deposit_event<T>() = default;
/// This is your public interface. Be extremely careful.
/// This is just a simple example of how to interact with the module from the external
/// world.
+1 -1
View File
@@ -176,7 +176,7 @@ decl_storage! {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Report some misbehaviour.
fn report_misbehavior(origin, _report: Vec<u8>) {
+1 -1
View File
@@ -89,7 +89,7 @@ pub trait Trait: timestamp::Trait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Sets the session key of `_validator` to `_key`. This doesn't take effect until the next
/// session.
+1 -1
View File
@@ -100,7 +100,7 @@ pub trait Trait: balances::Trait + session::Trait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Declare the desire to stake for the transactor.
///
+1 -1
View File
@@ -49,7 +49,7 @@ pub trait Trait: consensus::Trait + system::Trait {
decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
fn sudo(origin, proposal: Box<T::Proposal>) {
// This is a public call, so we ensure that the origin is some signed account.
+22 -4
View File
@@ -104,14 +104,14 @@ macro_rules! decl_module {
{ $( $on_finalise:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$vis:vis fn deposit_event() = default;
$vis:vis fn deposit_event $(<$dpeg:ident>)* () = default;
$($rest:tt)*
) => {
decl_module!(@normalize
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name>
for enum $call_type where origin: $origin_type, system = $system
{ $vis fn deposit_event() = default; }
{ $vis fn deposit_event $(<$dpeg>)* () = default; }
{ $( $on_finalise )* }
[ $($t)* ]
$($rest)*
@@ -125,14 +125,16 @@ macro_rules! decl_module {
{ $( $on_finalise:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$vis:vis fn deposit_event($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
$vis:vis fn deposit_event $(<$dpeg:ident>)* (
$($param_name:ident : $param:ty),*
) { $( $impl:tt )* }
$($rest:tt)*
) => {
decl_module!(@normalize
$(#[$attr])*
pub struct $mod_type<$trait_instance: $trait_name>
for enum $call_type where origin: $origin_type, system = $system
{ $vis fn deposit_event($( $param_name: $param ),* ) { $( $impl )* } }
{ $vis fn deposit_event $(<$dpeg>)* ($( $param_name: $param ),* ) { $( $impl )* } }
{ $( $on_finalise )* }
[ $($t)* ]
$($rest)*
@@ -296,10 +298,26 @@ macro_rules! decl_module {
$system:ident;
) => {};
// Non-generic event
(@impl_deposit_event
$module:ident<$trait_instance:ident: $trait_name:ident>;
$system:ident;
$vis:vis fn deposit_event() = default;
) => {
impl<$trait_instance: $trait_name> $module<$trait_instance> {
$vis fn deposit_event(event: Event) {
<$system::Module<$trait_instance>>::deposit_event(
<$trait_instance as $trait_name>::Event::from(event).into()
);
}
}
};
// Generic event
(@impl_deposit_event
$module:ident<$trait_instance:ident: $trait_name:ident>;
$system:ident;
$vis:vis fn deposit_event<$ignore:ident>() = default;
) => {
impl<$trait_instance: $trait_name> $module<$trait_instance> {
$vis fn deposit_event(event: Event<$trait_instance>) {
+1 -1
View File
@@ -68,7 +68,7 @@ type ProposalIndex = u32;
decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
/// Put forward a suggestion for spending. A deposit proportional to the value
/// is reserved and slashed if the proposal is rejected. It is returned once the
/// proposal is awarded.
+1 -1
View File
@@ -46,7 +46,7 @@ pub trait Trait: consensus::Trait + system::Trait {
decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
fn deposit_event<T>() = default;
fn upgrade(origin, new: Vec<u8>) {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;