Skip to content
New issue

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

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

Already on GitHub? # to your account

config: Add SkipCheckIfFeeless signed extension #1264

Merged
merged 18 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
14 changes: 13 additions & 1 deletion subxt/examples/setup_config_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ use subxt::client::OfflineClientT;
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder};
use subxt_signer::sr25519::dev;

#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
#[subxt::subxt(
runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
derive_for_type(path = "xcm::v2::multilocation::MultiLocation", derive = "Clone"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it didn't work to derive clone for all types instead? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope :( I've raised #1268 to track this in the future.

subxt/subxt/src/lib.rs

Lines 231 to 235 in eeacf4b

/// ## `derive_for_type(path = "...", derive = "...")`
///
/// Unlike the above, which derives some trait on every generated type, this attribute allows you to derive traits only
/// for specific types. Note that any types which are used inside the specified type may also need to derive the same traits.
///

derive_for_type(path = "xcm::v2::multilocation::Junctions", derive = "Clone"),
derive_for_type(path = "xcm::v2::junction::Junction", derive = "Clone"),
derive_for_type(path = "xcm::v2::NetworkId", derive = "Clone"),
derive_for_type(path = "xcm::v2::BodyId", derive = "Clone"),
derive_for_type(path = "xcm::v2::BodyPart", derive = "Clone"),
derive_for_type(
path = "bounded_collections::weak_bounded_vec::WeakBoundedVec",
derive = "Clone"
)
)]
pub mod runtime {}
use runtime::runtime_types::xcm::v2::multilocation::MultiLocation;

Expand Down
10 changes: 8 additions & 2 deletions subxt/examples/setup_config_signed_extension.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use codec::Encode;
use scale_encode::EncodeAsType;
use subxt::client::OfflineClientT;
use subxt::config::signed_extensions;
use subxt::config::{
Expand All @@ -11,6 +12,7 @@ pub mod runtime {}

// We don't need to construct this at runtime,
// so an empty enum is appropriate:
#[derive(EncodeAsType)]
pub enum CustomConfig {}

impl Config for CustomConfig {
Expand All @@ -32,6 +34,10 @@ impl Config for CustomConfig {
signed_extensions::CheckMortality<Self>,
signed_extensions::ChargeAssetTxPayment<Self>,
signed_extensions::ChargeTransactionPayment,
signed_extensions::SkipCheckIfFeeless<
Self,
signed_extensions::ChargeAssetTxPayment<Self>,
>,
// And add a new one of our own:
CustomSignedExtension,
),
Expand Down Expand Up @@ -81,8 +87,8 @@ impl ExtrinsicParamsEncoder for CustomSignedExtension {
pub fn custom(
params: DefaultExtrinsicParamsBuilder<CustomConfig>,
) -> <<CustomConfig as Config>::ExtrinsicParams as ExtrinsicParams<CustomConfig>>::OtherParams {
let (a, b, c, d, e, f, g) = params.build();
(a, b, c, d, e, f, g, ())
let (a, b, c, d, e, f, g, h) = params.build();
(a, b, c, d, e, f, g, h, ())
}

#[tokio::main]
Expand Down
10 changes: 8 additions & 2 deletions subxt/src/blocks/extrinsic_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

use crate::config::signed_extensions::{
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce,
ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce, SkipCheckIfFeeless,
};
use crate::config::SignedExtension;
use crate::dynamic::DecodedValue;
Expand Down Expand Up @@ -685,7 +685,7 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> {
///
/// Returns `None` if `tip` was not found or decoding failed.
pub fn tip(&self) -> Option<u128> {
// Note: the overhead of iterating twice should be negligible.
// Note: the overhead of iterating multiple time should be negligible.
self.find::<ChargeTransactionPayment>()
.ok()
.flatten()
Expand All @@ -696,6 +696,12 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> {
.flatten()
.map(|e| e.tip())
})
.or_else(|| {
self.find::<SkipCheckIfFeeless<T, ChargeAssetTxPayment<T>>>()
.ok()
.flatten()
.map(|skip_check| skip_check.inner_signed_extension().tip())
})
}

/// The nonce of the account that submitted the extrinsic, extracted from the CheckNonce signed extension.
Expand Down
5 changes: 5 additions & 0 deletions subxt/src/config/default_extrinsic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub type DefaultExtrinsicParams<T> = signed_extensions::AnyOf<
signed_extensions::CheckMortality<T>,
signed_extensions::ChargeAssetTxPayment<T>,
signed_extensions::ChargeTransactionPayment,
signed_extensions::SkipCheckIfFeeless<T, signed_extensions::ChargeAssetTxPayment<T>>,
),
>;

Expand Down Expand Up @@ -131,6 +132,9 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
let charge_transaction_params =
signed_extensions::ChargeTransactionPaymentParams::tip(self.tip);

let skip_check_params =
signed_extensions::SkipCheckIfFeelessParams::from(charge_asset_tx_params.clone());

(
(),
(),
Expand All @@ -139,6 +143,7 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
check_mortality_params,
charge_asset_tx_params,
charge_transaction_params,
skip_check_params,
)
}
}
14 changes: 13 additions & 1 deletion subxt/src/config/extrinsic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ pub enum ExtrinsicParamsError {
/// A signed extension was encountered that we don't know about.
#[error("Error constructing extrinsic parameters: Unknown signed extension '{0}'")]
UnknownSignedExtension(String),
/// Some custom error.
/// Cannot find the type id of a signed extension in the metadata.
#[error("Cannot find extension's '{0}' type id '{1} in the metadata")]
MissingTypeId(String, u32),
/// User provided a different signed extension than the one expected.
#[error("Provided a different signed extension for '{0}', the metadata expect '{1}'")]
ExpectedAnotherExtension(String, String),
/// The inner type of a signed extension is not present in the metadata.
#[error("The inner type of the signed extension '{0}' is not present in the metadata")]
MissingInnerSignedExtension(String),
/// The inner type of the signed extension is not named.
#[error("The signed extension's '{0}' type id '{1}' does not have a name in the metadata")]
ExpectedNamedTypeId(String, u32),
/// Some custom error.s
#[error("Error constructing extrinsic parameters: {0}")]
Custom(CustomError),
}
Expand Down
3 changes: 2 additions & 1 deletion subxt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod substrate;
use codec::{Decode, Encode};
use core::fmt::Debug;
use scale_decode::DecodeAsType;
use scale_encode::EncodeAsType;
use serde::{de::DeserializeOwned, Serialize};

pub use default_extrinsic_params::{DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder};
Expand Down Expand Up @@ -54,7 +55,7 @@ pub trait Config: Sized + Send + Sync + 'static {
type ExtrinsicParams: ExtrinsicParams<Self>;

/// This is used to identify an asset in the `ChargeAssetTxPayment` signed extension.
type AssetId: Debug + Encode + DecodeAsType;
type AssetId: Debug + Clone + Encode + DecodeAsType + EncodeAsType;
}

/// given some [`Config`], this return the other params needed for its `ExtrinsicParams`.
Expand Down
Loading