compact param in calls (#1499)

* impl #[codec(compact)] for param

* update modules

* test all and build runtime

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* delete wip comment

* update param to use #[compact] instead of Cmpact<>

* fmt

* impl metadata

* test metadata

* add compact attr test

* script buid

* update test
This commit is contained in:
thiolliere
2019-01-22 14:42:13 +01:00
committed by Bastian Köcher
parent 8f38593def
commit 2492931944
24 changed files with 576 additions and 541 deletions
+6 -9
View File
@@ -47,7 +47,6 @@ extern crate srml_system as system;
extern crate srml_consensus as consensus;
extern crate parity_codec as codec;
use codec::HasCompact;
use runtime_support::{StorageValue, Parameter};
use runtime_primitives::CheckInherentError;
use runtime_primitives::traits::{
@@ -100,10 +99,8 @@ decl_module! {
/// 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) {
fn set(origin, #[compact] now: T::Moment) {
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),
@@ -175,7 +172,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
let t = match (xt.is_signed(), extract_function(&xt)) {
(Some(false), Some(Call::set(ref t))) => t.clone(),
_ => return Err(CheckInherentError::Other("No valid timestamp inherent in block".into())),
}.into().as_();
}.as_();
let minimum = (Self::now() + Self::block_period()).as_();
if t > data.as_() + MAX_TIMESTAMP_DRIFT {
@@ -239,7 +236,7 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT));
assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT));
assert_eq!(Timestamp::now(), 69);
});
}
@@ -254,8 +251,8 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT));
let _ = Timestamp::dispatch(Call::set(70.into()), Origin::INHERENT);
assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT));
let _ = Timestamp::dispatch(Call::set(70), Origin::INHERENT);
});
}
@@ -269,7 +266,7 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
let _ = Timestamp::dispatch(Call::set(46.into()), Origin::INHERENT);
let _ = Timestamp::dispatch(Call::set(46), Origin::INHERENT);
});
}
}