mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 21:25:41 +00:00
DecodeAsEvent and DecodeAsExtrinsic; make easier to implement by removing consts
This commit is contained in:
@@ -81,10 +81,15 @@ pub fn generate_calls(
|
|||||||
#struct_def
|
#struct_def
|
||||||
#alias_mod
|
#alias_mod
|
||||||
|
|
||||||
impl #crate_path::extrinsics::DecodeAsExtrinsic for #struct_name {
|
impl #struct_name {
|
||||||
const PALLET_NAME: &'static str = #pallet_name;
|
const PALLET_NAME: &'static str = #pallet_name;
|
||||||
const CALL_NAME: &'static str = #call_name;
|
const CALL_NAME: &'static str = #call_name;
|
||||||
}
|
}
|
||||||
|
impl #crate_path::extrinsics::DecodeAsExtrinsic for #struct_name {
|
||||||
|
fn is_extrinsic(pallet_name: &str, call_name: &str) -> bool {
|
||||||
|
pallet_name == Self::PALLET_NAME && call_name == Self::CALL_NAME
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let client_fn = quote! {
|
let client_fn = quote! {
|
||||||
|
|||||||
@@ -63,10 +63,15 @@ pub fn generate_events(
|
|||||||
#struct_def
|
#struct_def
|
||||||
#alias_mod
|
#alias_mod
|
||||||
|
|
||||||
impl #crate_path::events::DecodeAsEvent for #event_struct_name {
|
impl #event_struct_name {
|
||||||
const PALLET_NAME: &'static str = #pallet_name;
|
const PALLET_NAME: &'static str = #pallet_name;
|
||||||
const EVENT_NAME: &'static str = #event_name;
|
const EVENT_NAME: &'static str = #event_name;
|
||||||
}
|
}
|
||||||
|
impl #crate_path::events::DecodeAsEvent for #event_struct_name {
|
||||||
|
fn is_event(pallet_name: &str, event_name: &str) -> bool {
|
||||||
|
pallet_name == Self::PALLET_NAME && event_name == Self::EVENT_NAME
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ use scale_decode::DecodeAsFields;
|
|||||||
/// This adds information to the type about which event it is, which enforces that
|
/// This adds information to the type about which event it is, which enforces that
|
||||||
/// only the correct event can be decoded into it.
|
/// only the correct event can be decoded into it.
|
||||||
pub trait DecodeAsEvent: DecodeAsFields {
|
pub trait DecodeAsEvent: DecodeAsFields {
|
||||||
/// Pallet name.
|
|
||||||
const PALLET_NAME: &'static str;
|
|
||||||
/// Event name.
|
|
||||||
const EVENT_NAME: &'static str;
|
|
||||||
|
|
||||||
/// Returns true if the given pallet and event names match this event.
|
/// Returns true if the given pallet and event names match this event.
|
||||||
fn is_event(pallet: &str, event: &str) -> bool {
|
fn is_event(pallet: &str, event: &str) -> bool;
|
||||||
Self::PALLET_NAME == pallet && Self::EVENT_NAME == event
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ use scale_decode::DecodeAsFields;
|
|||||||
/// This adds information to the type about which extrinsic it is, which enforces that
|
/// This adds information to the type about which extrinsic it is, which enforces that
|
||||||
/// only the correct extrinsic can be decoded into it.
|
/// only the correct extrinsic can be decoded into it.
|
||||||
pub trait DecodeAsExtrinsic: DecodeAsFields {
|
pub trait DecodeAsExtrinsic: DecodeAsFields {
|
||||||
/// Pallet name.
|
|
||||||
const PALLET_NAME: &'static str;
|
|
||||||
/// Call name.
|
|
||||||
const CALL_NAME: &'static str;
|
|
||||||
|
|
||||||
/// Returns true if the given pallet and call names match this extrinsic.
|
/// Returns true if the given pallet and call names match this extrinsic.
|
||||||
fn is_extrinsic(pallet: &str, call: &str) -> bool {
|
fn is_extrinsic(pallet: &str, call: &str) -> bool;
|
||||||
Self::PALLET_NAME == pallet && Self::CALL_NAME == call
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user