Static Decoding of Signed Extensions: Simple Approach (#1235)

* skeleton commit

* signed extension decoding

* fix some minor things

* make api more similar to Extrinsics

* defer decoding of signed extensions

* fix byte slices

* add test for nonce signed extension

* adjust test and extend for tip

* clippy

* support both  ChargeTransactionPayment and ChargeAssetTxPayment

* address PR comments

* Extend lifetimes, expose pub structs, remove as_type

* add signed extensions to block subscribing example

* add Decoded type

* fix merging bug and tests

* add decoded type in CustomSignedExtension

* fix minor issues, extend test

* cargo fmt differences

* remove the `decoded` function

* new as_signed_extra fn, do not expose as_type anymore

* fix Result-Option order, simplify obtaining Nonce

* tx: Remove `wait_for_in_block` helper method (#1237)

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update smoldot to 0.12 (#1212)

* Update lightclient

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Fix typo

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Update cargo.toml

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add tracing logs to improve debugging

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add socket buffers module for `PlatformRef`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Update `SubxtPlatform`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cargo: Add lightclient dependencies

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock of wasm tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add constant for with-buffer module

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Replace rand crate with getrandom

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* example: Update cargo lock file

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Update deps

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com>

* ChargeAssetTxPayment: support providing u32 or MultiLocation in default impl (#1227)

* Asset Id in Config trait

* add example configuring the config

* fmt

* fix Default trait bound

* merge examples, fix default again

* adjust config in examples

* Update subxt/src/config/mod.rs

Co-authored-by: James Wilson <james@jsdw.me>

---------

Co-authored-by: James Wilson <james@jsdw.me>

* generic AssetId

* fix generics

* fmt

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: James Wilson <james@jsdw.me>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
This commit is contained in:
Tadeo Hepperle
2023-11-10 18:32:58 +01:00
committed by GitHub
parent e7c1f73429
commit 56d0cdae78
7 changed files with 150 additions and 44 deletions
+37 -2
View File
@@ -12,6 +12,9 @@ use crate::utils::Era;
use crate::{client::OfflineClientT, Config};
use codec::{Compact, Encode};
use core::fmt::Debug;
use scale_decode::DecodeAsType;
use std::collections::HashMap;
/// A single [`SignedExtension`] has a unique name, but is otherwise the
@@ -21,6 +24,11 @@ pub trait SignedExtension<T: Config>: ExtrinsicParams<T> {
/// The name of the signed extension. This is used to associate it
/// with the signed extensions that the node is making use of.
const NAME: &'static str;
/// The type representing the `extra` bytes of a signed extension.
/// Decoding from this type should be symmetrical to the respective
/// `ExtrinsicParamsEncoder::encode_extra_to()` implementation of this signed extension.
type Decoded: DecodeAsType;
}
/// The [`CheckSpecVersion`] signed extension.
@@ -48,6 +56,7 @@ impl ExtrinsicParamsEncoder for CheckSpecVersion {
impl<T: Config> SignedExtension<T> for CheckSpecVersion {
const NAME: &'static str = "CheckSpecVersion";
type Decoded = ();
}
/// The [`CheckNonce`] signed extension.
@@ -75,6 +84,7 @@ impl ExtrinsicParamsEncoder for CheckNonce {
impl<T: Config> SignedExtension<T> for CheckNonce {
const NAME: &'static str = "CheckNonce";
type Decoded = Compact<u64>;
}
/// The [`CheckTxVersion`] signed extension.
@@ -102,6 +112,7 @@ impl ExtrinsicParamsEncoder for CheckTxVersion {
impl<T: Config> SignedExtension<T> for CheckTxVersion {
const NAME: &'static str = "CheckTxVersion";
type Decoded = ();
}
/// The [`CheckGenesis`] signed extension.
@@ -134,6 +145,7 @@ impl<T: Config> ExtrinsicParamsEncoder for CheckGenesis<T> {
impl<T: Config> SignedExtension<T> for CheckGenesis<T> {
const NAME: &'static str = "CheckGenesis";
type Decoded = ();
}
/// The [`CheckMortality`] signed extension.
@@ -213,15 +225,29 @@ impl<T: Config> ExtrinsicParamsEncoder for CheckMortality<T> {
impl<T: Config> SignedExtension<T> for CheckMortality<T> {
const NAME: &'static str = "CheckMortality";
type Decoded = Era;
}
/// The [`ChargeAssetTxPayment`] signed extension.
#[derive(Debug)]
#[derive(Debug, DecodeAsType)]
#[decode_as_type(trait_bounds = "T::AssetId: DecodeAsType")]
pub struct ChargeAssetTxPayment<T: Config> {
tip: Compact<u128>,
asset_id: Option<T::AssetId>,
}
impl<T: Config> ChargeAssetTxPayment<T> {
/// Tip to the extrinsic author in the native chain token.
pub fn tip(&self) -> u128 {
self.tip.0
}
/// Tip to the extrinsic author using the asset ID given.
pub fn asset_id(&self) -> Option<&T::AssetId> {
self.asset_id.as_ref()
}
}
/// Parameters to configure the [`ChargeAssetTxPayment`] signed extension.
pub struct ChargeAssetTxPaymentParams<T: Config> {
tip: u128,
@@ -285,14 +311,22 @@ impl<T: Config> ExtrinsicParamsEncoder for ChargeAssetTxPayment<T> {
impl<T: Config> SignedExtension<T> for ChargeAssetTxPayment<T> {
const NAME: &'static str = "ChargeAssetTxPayment";
type Decoded = Self;
}
/// The [`ChargeTransactionPayment`] signed extension.
#[derive(Debug)]
#[derive(Debug, DecodeAsType)]
pub struct ChargeTransactionPayment {
tip: Compact<u128>,
}
impl ChargeTransactionPayment {
/// Tip to the extrinsic author in the native chain token.
pub fn tip(&self) -> u128 {
self.tip.0
}
}
/// Parameters to configure the [`ChargeTransactionPayment`] signed extension.
#[derive(Default)]
pub struct ChargeTransactionPaymentParams {
@@ -333,6 +367,7 @@ impl ExtrinsicParamsEncoder for ChargeTransactionPayment {
impl<T: Config> SignedExtension<T> for ChargeTransactionPayment {
const NAME: &'static str = "ChargeTransactionPayment";
type Decoded = Self;
}
/// This accepts a tuple of [`SignedExtension`]s, and will dynamically make use of whichever