Skip to content

Commit

Permalink
Update to alpha.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed May 26, 2020
1 parent 67f3ce5 commit 4147407
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
52 changes: 43 additions & 9 deletions src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,7 +245,7 @@ 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;
Expand All @@ -224,7 +254,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,
}
Expand All @@ -233,7 +264,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>,
Expand All @@ -242,17 +274,19 @@ 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,
}
}

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),
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4147407

Please sign in to comment.