Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to alpha.8 #114

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 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,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;
Expand All @@ -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,
}
Expand All @@ -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>,
Expand All @@ -242,17 +279,24 @@ 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