mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-07 06:08:03 +00:00
Simplify deposit_event declaration in decl_module (#3506)
* simplify module deposit_event declaration * fix * bump version * fix * fix test * fix doc
This commit is contained in:
committed by
Bastian Köcher
parent
f830db9642
commit
b07fd450e2
@@ -35,7 +35,7 @@ decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
// Initializing events
|
||||
// this is needed only if you are using events in your module
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
// Just a dummy entry point.
|
||||
// function that can be called by the external world as an extrinsics call
|
||||
|
||||
@@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 154,
|
||||
impl_version: 156,
|
||||
impl_version: 157,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ pub trait Trait: system::Trait {
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = 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.
|
||||
|
||||
@@ -413,7 +413,7 @@ decl_module! {
|
||||
/// The fee to be paid for making a transaction; the per-byte portion.
|
||||
const TransactionByteFee: T::Balance = T::TransactionByteFee::get();
|
||||
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Transfer some liquid free balance to another account.
|
||||
///
|
||||
|
||||
@@ -138,7 +138,7 @@ decl_event!(
|
||||
// operational class.
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as system::Trait>::Origin {
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Set the collective's membership manually to `new_members`. Be nice to the chain and
|
||||
/// provide it pre-sorted.
|
||||
|
||||
@@ -504,7 +504,7 @@ decl_module! {
|
||||
/// default value is 10_000_000.
|
||||
const BlockGasLimit: Gas = T::BlockGasLimit::get();
|
||||
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Updates the schedule for metering contracts.
|
||||
///
|
||||
|
||||
@@ -354,7 +354,7 @@ decl_module! {
|
||||
/// Period in blocks where an external proposal may not be re-submitted after being vetoed.
|
||||
const CooloffPeriod: T::BlockNumber = T::CooloffPeriod::get();
|
||||
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Propose a sensitive action to be taken.
|
||||
///
|
||||
|
||||
@@ -296,7 +296,7 @@ decl_module! {
|
||||
/// The chunk size of the approval vector.
|
||||
const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32;
|
||||
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
|
||||
/// are registered.
|
||||
|
||||
@@ -363,7 +363,7 @@ decl_module! {
|
||||
/// It is also possible to provide a custom implementation.
|
||||
/// 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;
|
||||
fn deposit_event() = 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.
|
||||
|
||||
@@ -324,7 +324,7 @@ impl<AccountId> Into<PermissionVersions<AccountId>> for PermissionLatest<Account
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Create a new kind of asset.
|
||||
fn create(origin, options: AssetOptions<T::Balance, T::AccountId>) -> Result {
|
||||
|
||||
@@ -238,7 +238,7 @@ decl_storage! {
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn heartbeat(
|
||||
origin,
|
||||
|
||||
@@ -73,7 +73,7 @@ pub trait Trait: system::Trait {
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ decl_module! {
|
||||
for enum Call
|
||||
where origin: T::Origin
|
||||
{
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Add a member `who` to the set.
|
||||
///
|
||||
|
||||
@@ -228,7 +228,7 @@ decl_module! {
|
||||
for enum Call
|
||||
where origin: T::Origin
|
||||
{
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Every `Period` blocks the `Members` set is refreshed from the
|
||||
/// highest scoring members in the pool.
|
||||
|
||||
@@ -674,7 +674,7 @@ decl_module! {
|
||||
/// Number of eras that staked funds must remain bonded for.
|
||||
const BondingDuration: EraIndex = T::BondingDuration::get();
|
||||
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn on_finalize() {
|
||||
// Set the start of the first era.
|
||||
@@ -1595,7 +1595,7 @@ impl<T, Reporter, Offender, R, O> ReportOffence<Reporter, Offender, O>
|
||||
R::report_offence(reporters, offence)
|
||||
} else {
|
||||
<Module<T>>::deposit_event(
|
||||
RawEvent::OldSlashingReportDiscarded(offence_session).into()
|
||||
RawEvent::OldSlashingReportDiscarded(offence_session)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ pub trait Trait: system::Trait {
|
||||
decl_module! {
|
||||
// Simple declaration of the `Module` type. Lets the macro know what it's working on.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Authenticates the sudo key and dispatches a function call with `Root` origin.
|
||||
///
|
||||
|
||||
@@ -203,7 +203,7 @@ impl<T> Parameter for T where T: Codec + Clone + Eq {}
|
||||
/// * `deposit_event`: Helper function for depositing an [event](https://docs.substrate.dev/docs/event-enum).
|
||||
/// The default behavior is to call `deposit_event` from the [System module](../srml_system/index.html).
|
||||
/// However, you can write your own implementation for events in your runtime. To use the default behavior,
|
||||
/// add `fn deposit_event<T>() = default;` to your `Module`.
|
||||
/// add `fn deposit_event() = default;` to your `Module`.
|
||||
///
|
||||
/// The following reserved functions also take the block number (with type `T::BlockNumber`) as an optional input:
|
||||
///
|
||||
@@ -288,7 +288,7 @@ macro_rules! decl_module {
|
||||
{ $( $constants:tt )* }
|
||||
[ $( $dispatchables:tt )* ]
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* () = default;
|
||||
$vis:vis fn deposit_event() = default;
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::decl_module!(@normalize
|
||||
@@ -296,7 +296,7 @@ macro_rules! decl_module {
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $other_where_bounds )* }
|
||||
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* () = default; }
|
||||
{ $vis fn deposit_event() = default; }
|
||||
{ $( $on_initialize )* }
|
||||
{ $( $on_finalize )* }
|
||||
{ $( $offchain )* }
|
||||
@@ -317,23 +317,11 @@ macro_rules! decl_module {
|
||||
{ $( $constants:tt )* }
|
||||
[ $( $dispatchables:tt )* ]
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* (
|
||||
$($param_name:ident : $param:ty),*
|
||||
) { $( $impl:tt )* }
|
||||
$vis:vis fn deposit_event
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::decl_module!(@normalize
|
||||
$(#[$attr])*
|
||||
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
|
||||
for enum $call_type where origin: $origin_type, system = $system
|
||||
{ $( $other_where_bounds )* }
|
||||
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* ($( $param_name: $param ),* ) { $( $impl )* } }
|
||||
{ $( $on_initialize )* }
|
||||
{ $( $on_finalize )* }
|
||||
{ $( $offchain )* }
|
||||
{ $( $constants )* }
|
||||
[ $( $dispatchables )* ]
|
||||
$($rest)*
|
||||
compile_error!(
|
||||
"`deposit_event` function is reserved and must follow the syntax: `$vis:vis fn deposit_event() = default;`"
|
||||
);
|
||||
};
|
||||
(@normalize
|
||||
@@ -685,25 +673,10 @@ macro_rules! decl_module {
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?>
|
||||
where $( $other_where_bounds )*
|
||||
{
|
||||
$vis fn deposit_event(event: Event$(<$event_trait_instance $(, $event_instance)?>)?) {
|
||||
<$system::Module<$trait_instance>>::deposit_event(
|
||||
<$trait_instance as $trait_name$(<$instance>)?>::Event::from(event).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(@impl_deposit_event
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
|
||||
$system:ident;
|
||||
{ $( $other_where_bounds:tt )* }
|
||||
$vis:vis fn deposit_event($param:ident : $param_ty:ty) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?>
|
||||
where $( $other_where_bounds )*
|
||||
{
|
||||
$vis fn deposit_event($param: $param_ty) {
|
||||
$( $impl )*
|
||||
$vis fn deposit_event(
|
||||
event: impl Into<< $trait_instance as $trait_name $(<$instance>)? >::Event>
|
||||
) {
|
||||
<$system::Module<$trait_instance>>::deposit_event(event.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ mod module1 {
|
||||
{
|
||||
fn offchain_worker() {}
|
||||
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn one(origin) {
|
||||
system::ensure_root(origin)?;
|
||||
@@ -132,7 +132,7 @@ mod module2 {
|
||||
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where
|
||||
origin: <T as system::Trait>::Origin
|
||||
{
|
||||
fn deposit_event<T, I>() = default;
|
||||
fn deposit_event() = default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't mat
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
|
||||
error: `deposit_event` function is reserved and must follow the syntax: `$vis:vis fn deposit_event() = default;`
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
|
||||
@@ -12,8 +12,11 @@ pub trait Trait: 'static + Eq + Clone {
|
||||
|
||||
srml_support::decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
pub fn deposit_event(_event: T::Event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
pub fn deposit_event(_event: impl Into<T::Event>) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +52,4 @@ pub fn ensure_root<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'stati
|
||||
where OuterOrigin: Into<Result<RawOrigin<AccountId>, OuterOrigin>>
|
||||
{
|
||||
o.into().map(|_| ()).map_err(|_| "bad origin: expected to be a root origin")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,11 +246,6 @@ pub type KeyValue = (Vec<u8>, Vec<u8>);
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// Deposits an event into this block's event record.
|
||||
pub fn deposit_event(event: T::Event) {
|
||||
Self::deposit_event_indexed(&[], event);
|
||||
}
|
||||
|
||||
/// A big dispatch that will disallow any other transaction to be included.
|
||||
// TODO: this must be preferable available for testing really (not possible at the moment).
|
||||
#[weight = SimpleDispatchInfo::MaxOperational]
|
||||
@@ -545,6 +540,11 @@ pub fn ensure_none<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'stati
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Deposits an event into this block's event record.
|
||||
pub fn deposit_event(event: impl Into<T::Event>) {
|
||||
Self::deposit_event_indexed(&[], event.into());
|
||||
}
|
||||
|
||||
/// Deposits an event into this block's event record adding this event
|
||||
/// to the corresponding topic indexes.
|
||||
///
|
||||
@@ -815,7 +815,7 @@ impl<T: Trait> Module<T> {
|
||||
Self::deposit_event(match r {
|
||||
Ok(_) => Event::ExtrinsicSuccess,
|
||||
Err(_) => Event::ExtrinsicFailed,
|
||||
}.into());
|
||||
});
|
||||
|
||||
let next_extrinsic_index = Self::extrinsic_index().unwrap_or_default() + 1u32;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ decl_module! {
|
||||
/// Percentage of spare funds (if any) that are burnt per spend period.
|
||||
const Burn: Permill = T::Burn::get();
|
||||
|
||||
fn deposit_event<T>() = default;
|
||||
fn deposit_event() = 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.
|
||||
|
||||
Reference in New Issue
Block a user