mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Multiple improvements to the decl_module! macro (#953)
* General `decl_module` improvements * Make `deposit_event` implementable by `decl_module!` * Make `decl_module!` implement calls directly * Regenerate the wasm file after master rebase
This commit is contained in:
@@ -74,7 +74,33 @@ pub trait Trait: consensus::Trait + system::Trait {
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn set(origin, now: <T::Moment as HasCompact>::Type) -> Result;
|
||||
/// Set the current time.
|
||||
///
|
||||
/// Extrinsic with this call should be placed at the specific position in the each block
|
||||
/// (specified by the Trait::TIMESTAMP_SET_POSITION) typically at the start of the each block.
|
||||
/// This call should be invoked exactly once per block. It will panic at the finalization phase,
|
||||
/// if this call hasn't been invoked by that time.
|
||||
///
|
||||
/// The timestamp should be greater than the previous one by the amount specified by `block_period`.
|
||||
fn set(origin, now: <T::Moment as HasCompact>::Type) -> Result {
|
||||
ensure_inherent(origin)?;
|
||||
let now = now.into();
|
||||
|
||||
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
|
||||
assert!(
|
||||
<system::Module<T>>::extrinsic_index() == Some(T::TIMESTAMP_SET_POSITION),
|
||||
"Timestamp extrinsic must be at position {} in the block",
|
||||
T::TIMESTAMP_SET_POSITION
|
||||
);
|
||||
assert!(
|
||||
Self::now().is_zero() || now >= Self::now() + Self::block_period(),
|
||||
"Timestamp must increment by at least <BlockPeriod> between sequential blocks"
|
||||
);
|
||||
<Self as Store>::Now::put(now);
|
||||
<Self as Store>::DidUpdate::put(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_finalise() {
|
||||
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
|
||||
}
|
||||
@@ -103,33 +129,6 @@ impl<T: Trait> Module<T> {
|
||||
Self::now()
|
||||
}
|
||||
|
||||
/// Set the current time.
|
||||
///
|
||||
/// Extrinsic with this call should be placed at the specific position in the each block
|
||||
/// (specified by the Trait::TIMESTAMP_SET_POSITION) typically at the start of the each block.
|
||||
/// This call should be invoked exactly once per block. It will panic at the finalization phase,
|
||||
/// if this call hasn't been invoked by that time.
|
||||
///
|
||||
/// The timestamp should be greater than the previous one by the amount specified by `block_period`.
|
||||
fn set(origin: T::Origin, now: <T::Moment as HasCompact>::Type) -> Result {
|
||||
ensure_inherent(origin)?;
|
||||
let now = now.into();
|
||||
|
||||
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
|
||||
assert!(
|
||||
<system::Module<T>>::extrinsic_index() == Some(T::TIMESTAMP_SET_POSITION),
|
||||
"Timestamp extrinsic must be at position {} in the block",
|
||||
T::TIMESTAMP_SET_POSITION
|
||||
);
|
||||
assert!(
|
||||
Self::now().is_zero() || now >= Self::now() + Self::block_period(),
|
||||
"Timestamp must increment by at least <BlockPeriod> between sequential blocks"
|
||||
);
|
||||
<Self as Store>::Now::put(now);
|
||||
<Self as Store>::DidUpdate::put(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the timestamp to something in particular. Only used for tests.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn set_timestamp(now: T::Moment) {
|
||||
|
||||
Reference in New Issue
Block a user