mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
Add ‘transaction_version’ to the signed transaction (#5979)
* Add ‘transaction_version’ to the signed transaction This allows hardware wallets to know which transactions they can safely sign. To reduce transaction size, I reduced it to a ‘u8’ from a ‘u32’. Fixes #5951. * Restore transaction_version to a u32 * Fix comments `transaction_version` is not part of a tx, but is still signed. Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Fix the test suite I had forgotten to change the production of transactions in the test code. * Fix benchmarks * Improve docs for `CheckTxVersion` in `frame_system` Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Remove spurious cast Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -53,7 +53,9 @@
|
||||
//! - [`CheckEra`]: Checks the era of the transaction. Contains a single payload of type `Era`.
|
||||
//! - [`CheckGenesis`]: Checks the provided genesis hash of the transaction. Must be a part of the
|
||||
//! signed payload of the transaction.
|
||||
//! - [`CheckVersion`]: Checks that the runtime version is the same as the one encoded in the
|
||||
//! - [`CheckSpecVersion`]: Checks that the runtime version is the same as the one used to sign the
|
||||
//! transaction.
|
||||
//! - [`CheckTxVersion`]: Checks that the transaction version is the same as the one used to sign the
|
||||
//! transaction.
|
||||
//!
|
||||
//! Lookup the runtime aggregator file (e.g. `node/runtime`) to see the full list of signed
|
||||
@@ -1735,14 +1737,14 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the runtime version registered in the transaction is the same as at present.
|
||||
/// Ensure the transaction version registered in the transaction is the same as at present.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckVersion<T: Trait + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
pub struct CheckTxVersion<T: Trait + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Trait + Send + Sync> Debug for CheckVersion<T> {
|
||||
impl<T: Trait + Send + Sync> Debug for CheckTxVersion<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
write!(f, "CheckVersion")
|
||||
write!(f, "CheckTxVersion")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
@@ -1751,19 +1753,54 @@ impl<T: Trait + Send + Sync> Debug for CheckVersion<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> CheckVersion<T> {
|
||||
impl<T: Trait + Send + Sync> CheckTxVersion<T> {
|
||||
/// Create new `SignedExtension` to check transaction version.
|
||||
pub fn new() -> Self {
|
||||
Self(sp_std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> SignedExtension for CheckTxVersion<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type Call = <T as Trait>::Call;
|
||||
type AdditionalSigned = u32;
|
||||
type Pre = ();
|
||||
const IDENTIFIER: &'static str = "CheckTxVersion";
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
Ok(<Module<T>>::runtime_version().transaction_version)
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the runtime version registered in the transaction is the same as at present.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckSpecVersion<T: Trait + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Trait + Send + Sync> Debug for CheckSpecVersion<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
write!(f, "CheckSpecVersion")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> CheckSpecVersion<T> {
|
||||
/// Create new `SignedExtension` to check runtime version.
|
||||
pub fn new() -> Self {
|
||||
Self(sp_std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> SignedExtension for CheckVersion<T> {
|
||||
impl<T: Trait + Send + Sync> SignedExtension for CheckSpecVersion<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type Call = <T as Trait>::Call;
|
||||
type AdditionalSigned = u32;
|
||||
type Pre = ();
|
||||
const IDENTIFIER: &'static str = "CheckVersion";
|
||||
const IDENTIFIER: &'static str = "CheckSpecVersion";
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
Ok(<Module<T>>::runtime_version().spec_version)
|
||||
|
||||
Reference in New Issue
Block a user