Issue 212 - refactor Checkable trait to be more generic (#287)

* runtime: refactor Checkable and BlindCheckable traits

* fix impl BlindCheckable for Extrinsic

* fix impl Checkable for TestXt

* fix impl Checkable for UncheckedExtrinsic

* fix tabs

* add ::Address to system::Trait since its no longer in Checkable trait

* replace tab by space in comment

* replace occurences of Checkable::check with ::check_with

* tx-pool: replace CheckedIntrinsic type alias since it now would require type param

* make more uses of Checkable compile

* adapt Executive impl to new Checkable trait

* fix that CheckedExtrinsic takes AccountId not Address as first type param

* Checkable trait: return error again since it's required in some cases

* Checkable: improve docstrings

* consistent punctuation and capitalization in docstrings

* Ctx -> Context

addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200956240

* reduce trait bounds for impl Checkable for TestXt

addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200839303

* use <UncheckedExtrinsic as Checkable>::Checked

addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200955165

* Revert "add ::Address to system::Trait since its no longer in Checkable trait"

This reverts commit 02eb103015b833c995c9f9067aac2542bb7ce5ea.

* runtime/executive: properly fix that Address no longer in Checkable

* return `Result<Self::Checked, &'static str>` from `Checkable::check`
This commit is contained in:
snd
2018-07-11 21:12:22 +02:00
committed by Gav Wood
parent 042ded7cc5
commit 2963f6b911
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -47,5 +47,5 @@ pub fn inherent_extrinsics(timestamp: ::primitives::Timestamp, parachain_heads:
/// Checks an unchecked extrinsic for validity. /// Checks an unchecked extrinsic for validity.
pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool { pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool {
xt.check(Staking::lookup).is_ok() xt.check_with(Staking::lookup).is_ok()
} }
+2 -2
View File
@@ -55,7 +55,7 @@ pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransacti
pub use error::{Error, ErrorKind, Result}; pub use error::{Error, ErrorKind, Result};
/// Type alias for convenience. /// Type alias for convenience.
pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable>::Checked; pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable<fn(Address) -> std::result::Result<AccountId, &'static str>>>::Checked;
/// A verified transaction which should be includable and non-inherent. /// A verified transaction which should be includable and non-inherent.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@@ -281,7 +281,7 @@ impl<'a, A> txpool::Verifier<UncheckedExtrinsic> for Verifier<'a, A> where
} }
let (encoded_size, hash) = uxt.using_encoded(|e| (e.len(), BlakeTwo256::hash(e))); let (encoded_size, hash) = uxt.using_encoded(|e| (e.len(), BlakeTwo256::hash(e)));
let inner = match uxt.clone().check(|a| self.lookup(a)) { let inner = match uxt.clone().check_with(|a| self.lookup(a)) {
Ok(xt) => Some(xt), Ok(xt) => Some(xt),
// keep the transaction around in the future pool and attempt to promote it later. // keep the transaction around in the future pool and attempt to promote it later.
Err(Self::NO_ACCOUNT) => None, Err(Self::NO_ACCOUNT) => None,