Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Multiple improvements to the decl_module! macro #953

Merged
merged 4 commits into from
Oct 26, 2018
Merged

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Oct 23, 2018

  1. Removes weird where origin = Origin where system = System and replaces with more rusty syntax:
    where origin = Origin, system = System.
  2. Makes it possible to easier implement deposit_event by either writing fn deposit_event() = default which creates the default implementation or by using fn deposit_event(my_event: MyEvent) { //myimpl } which supports any custom implementation. This fixes: Automatically impl deposit_event  #920
  3. Calls are now required to be implemented directly in the decl_module! macro. This reduces boilerplate code, as now extra impl<T: Trait> Module<T> block is required.

This currently does not compile on stable, we need to wait for Thursday (23.10), where the required feature will be released as stable with rust 1.30.0.

@bkchr bkchr requested a review from gavofyork October 23, 2018 14:20
@bkchr bkchr added the A0-please_review Pull request needs code review. label Oct 23, 2018
@gavofyork
Copy link
Member

doesn't build, needs resolving...

@bkchr
Copy link
Member Author

bkchr commented Oct 25, 2018

Yeah as written in the description, this requires rust 1.30.0 that should be released today.

@bkchr bkchr force-pushed the bkchr-deposit_event branch from 6b1e2c3 to 65b99b0 Compare October 26, 2018 10:08
@bkchr bkchr merged commit 5cd9081 into master Oct 26, 2018
@bkchr bkchr deleted the bkchr-deposit_event branch October 26, 2018 10:34
@chrisdcosta
Copy link
Contributor

chrisdcosta commented Nov 27, 2018

I'm not sure if this is related I think this may be causing breaking changes to custom modules (Gavin's demo?) - I'm getting compile errors error: no rules expected the token 'normalize' this error originates in a macro outside of the current crate on rust 1.30.0 with or without function code in the impl<T: Trait> Module<T>

@bkchr
Copy link
Member Author

bkchr commented Nov 27, 2018

@chrisdcosta do you have more context for me? Did you tried to redo gav's demo? If yes, you now need to place your implementation directly into the decl_macro!.

So before you had something like:

decl_macro! {
    struct Module {
        fn my_call(origin, data:i32) -> Result;
    }
}

impl Module {
   fn my_call(origin, data: i32) -> Result { 
        //my impl
   }
}

Now you have to write it like:

decl_macro! {
    struct Module {
        fn my_call(origin, data: i32) -> Result { 
            //my impl
        }
    }
}

@chrisdcosta
Copy link
Contributor

Yes I'd seen the changes in the SRML modules. I was building using the paired-down demo version of substrate generated by substrate-node-new but it may have been installed before your recent updates from master. Am checking this now.

@bkchr
Copy link
Member Author

bkchr commented Nov 27, 2018

Okay

@chrisdcosta
Copy link
Contributor

OK I've tied this error down - it's not a problem with the build - it's my use of a type definition for origin in the struct following the live demo.

In the live demo the function signature for set_payment inside the struct Module explicitly typed the first argument fn set_payment(_: T::Origin, value: T::Balance) -> Result {...}.

This causes the error - and presumably is because the changes mean that if origin is typed in the where of the struct definition it does not now need to be specified in the structs own function signatures. Is this correct?

@chrisdcosta
Copy link
Contributor

Should add that it now compiles correctly like this fn set_payment(_origin, value: T::Balance) -> Result {...}

lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
…aritytech#948)

* Use `add_benchmark` macro

* Return error if `batches` is empty

* Update Cargo.lock

* Companion for paritytech#5463 (paritytech#953)

* Fix test with genesis block 0

* Update Cargo.lock
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically impl deposit_event
3 participants