Make `decl_error!` errors usable (#4449)
* Make `decl_error!` errors usable This pr implements support for returning errors of different pallets in a pallet. These errors need to be declared with `decl_error!`. The pr changes the following: - Each dispatchable function now returns a `DispatchResult` which is an alias for `Result<(), DispatchError>`. - `DispatchError` is an enum that has 4 variants: - `Other`: For storing string error messages - `CannotLookup`: Variant that is returned when something returns a `sp_runtime::LookupError` - `BadOrigin`: Variant that is returned for any kind of bad origin - `Module`: The error of a specific module. Contains the `index`, `error` and the `message`. The index is the index of the module in `construct_runtime!`. `error` is the index of the error in the error enum declared by `decl_error!`. `message` is the message to the error variant (this will not be encoded). - `construct_runtime!` now creates a new struct `ModuleToIndex`. This struct implements the trait `ModuleToIndex`. - `frame_system::Trait` has a new associated type: `ModuleToIndex` that expects the `ModuleToIndex` generated by `construct_runtime!`. - All error strings returned in any module are being converted now to `DispatchError`. - `BadOrigin` is the default error returned by any type that implements `EnsureOrigin`. * Fix frame system benchmarks
Showing
- substrate/bin/node-template/runtime/src/lib.rs 4 additions, 0 deletionssubstrate/bin/node-template/runtime/src/lib.rs
- substrate/bin/node-template/runtime/src/template.rs 2 additions, 1 deletionsubstrate/bin/node-template/runtime/src/template.rs
- substrate/bin/node/runtime/src/lib.rs 1 addition, 0 deletionssubstrate/bin/node/runtime/src/lib.rs
- substrate/frame/assets/src/lib.rs 15 additions, 14 deletionssubstrate/frame/assets/src/lib.rs
- substrate/frame/aura/src/mock.rs 1 addition, 0 deletionssubstrate/frame/aura/src/mock.rs
- substrate/frame/authority-discovery/src/lib.rs 1 addition, 0 deletionssubstrate/frame/authority-discovery/src/lib.rs
- substrate/frame/authorship/src/lib.rs 9 additions, 8 deletionssubstrate/frame/authorship/src/lib.rs
- substrate/frame/babe/src/mock.rs 1 addition, 0 deletionssubstrate/frame/babe/src/mock.rs
- substrate/frame/balances/src/lib.rs 22 additions, 22 deletionssubstrate/frame/balances/src/lib.rs
- substrate/frame/balances/src/mock.rs 1 addition, 0 deletionssubstrate/frame/balances/src/mock.rs
- substrate/frame/balances/src/tests.rs 2 additions, 2 deletionssubstrate/frame/balances/src/tests.rs
- substrate/frame/collective/src/lib.rs 21 additions, 20 deletionssubstrate/frame/collective/src/lib.rs
- substrate/frame/contracts/src/exec.rs 34 additions, 20 deletionssubstrate/frame/contracts/src/exec.rs
- substrate/frame/contracts/src/gas.rs 2 additions, 1 deletionsubstrate/frame/contracts/src/gas.rs
- substrate/frame/contracts/src/lib.rs 15 additions, 15 deletionssubstrate/frame/contracts/src/lib.rs
- substrate/frame/contracts/src/tests.rs 1 addition, 0 deletionssubstrate/frame/contracts/src/tests.rs
- substrate/frame/contracts/src/wasm/mod.rs 3 additions, 2 deletionssubstrate/frame/contracts/src/wasm/mod.rs
- substrate/frame/contracts/src/wasm/runtime.rs 3 additions, 3 deletionssubstrate/frame/contracts/src/wasm/runtime.rs
- substrate/frame/democracy/src/lib.rs 124 additions, 108 deletionssubstrate/frame/democracy/src/lib.rs
- substrate/frame/elections-phragmen/src/lib.rs 7 additions, 6 deletionssubstrate/frame/elections-phragmen/src/lib.rs
Please register or sign in to comment