Update to alpha.8 (#114)

This commit is contained in:
David Craven
2020-05-26 11:55:54 +02:00
committed by GitHub
parent 67f3ce529e
commit 4dadb2c9b5
2 changed files with 56 additions and 11 deletions
+53 -9
View File
@@ -43,18 +43,48 @@ use crate::frame::{
/// This is modified from the substrate version to allow passing in of the version, which is
/// returned via `additional_signed()`.
#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)]
pub struct CheckVersion<T: System>(
pub struct CheckSpecVersion<T: System>(
pub PhantomData<T>,
/// Local version to be used for `AdditionalSigned`
#[codec(skip)]
pub u32,
);
impl<T> SignedExtension for CheckVersion<T>
impl<T> SignedExtension for CheckSpecVersion<T>
where
T: System + Clone + Debug + Eq + Send + Sync,
{
const IDENTIFIER: &'static str = "CheckVersion";
const IDENTIFIER: &'static str = "CheckSpecVersion";
type AccountId = u64;
type Call = ();
type AdditionalSigned = u32;
type Pre = ();
fn additional_signed(
&self,
) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(self.1)
}
}
/// Ensure the transaction version registered in the transaction is the same as at present.
///
/// # Note
///
/// This is modified from the substrate version to allow passing in of the version, which is
/// returned via `additional_signed()`.
#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)]
pub struct CheckTxVersion<T: System>(
pub PhantomData<T>,
/// Local version to be used for `AdditionalSigned`
#[codec(skip)]
pub u32,
);
impl<T> SignedExtension for CheckTxVersion<T>
where
T: System + Clone + Debug + Eq + Send + Sync,
{
const IDENTIFIER: &'static str = "CheckTxVersion";
type AccountId = u64;
type Call = ();
type AdditionalSigned = u32;
@@ -215,7 +245,12 @@ pub trait SignedExtra<T: System> {
type Extra: SignedExtension;
/// Creates a new `SignedExtra`.
fn new(version: u32, nonce: T::Index, genesis_hash: T::Hash) -> Self;
fn new(
spec_version: u32,
tx_version: u32,
nonce: T::Index,
genesis_hash: T::Hash,
) -> Self;
/// Returns the transaction extra.
fn extra(&self) -> Self::Extra;
@@ -224,7 +259,8 @@ pub trait SignedExtra<T: System> {
/// Default `SignedExtra` for substrate runtimes.
#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)]
pub struct DefaultExtra<T: System> {
version: u32,
spec_version: u32,
tx_version: u32,
nonce: T::Index,
genesis_hash: T::Hash,
}
@@ -233,7 +269,8 @@ impl<T: System + Balances + Clone + Debug + Eq + Send + Sync> SignedExtra<T>
for DefaultExtra<T>
{
type Extra = (
CheckVersion<T>,
CheckSpecVersion<T>,
CheckTxVersion<T>,
CheckGenesis<T>,
CheckEra<T>,
CheckNonce<T>,
@@ -242,9 +279,15 @@ impl<T: System + Balances + Clone + Debug + Eq + Send + Sync> SignedExtra<T>
CheckBlockGasLimit<T>,
);
fn new(version: u32, nonce: T::Index, genesis_hash: T::Hash) -> Self {
fn new(
spec_version: u32,
tx_version: u32,
nonce: T::Index,
genesis_hash: T::Hash,
) -> Self {
DefaultExtra {
version,
spec_version,
tx_version,
nonce,
genesis_hash,
}
@@ -252,7 +295,8 @@ impl<T: System + Balances + Clone + Debug + Eq + Send + Sync> SignedExtra<T>
fn extra(&self) -> Self::Extra {
(
CheckVersion(PhantomData, self.version),
CheckSpecVersion(PhantomData, self.spec_version),
CheckTxVersion(PhantomData, self.tx_version),
CheckGenesis(PhantomData, self.genesis_hash),
CheckEra((Era::Immortal, PhantomData), self.genesis_hash),
CheckNonce(self.nonce),
+3 -2
View File
@@ -314,13 +314,14 @@ where
} else {
self.account(account_id).await?.nonce
};
let version = self.runtime_version.spec_version;
let spec_version = self.runtime_version.spec_version;
let tx_version = self.runtime_version.transaction_version;
let genesis_hash = self.genesis_hash;
let call = self
.metadata()
.module_with_calls(C::MODULE)
.and_then(|module| module.call(C::FUNCTION, call))?;
let extra: E = E::new(version, account_nonce, genesis_hash);
let extra: E = E::new(spec_version, tx_version, account_nonce, genesis_hash);
let raw_payload = SignedPayload::new(call, extra.extra())?;
Ok(raw_payload)
}