diff --git a/subxt/examples/setup_config_custom.rs b/subxt/examples/setup_config_custom.rs index 46a3afc3a2..edc21fcb11 100644 --- a/subxt/examples/setup_config_custom.rs +++ b/subxt/examples/setup_config_custom.rs @@ -3,8 +3,9 @@ use subxt::client::OfflineClientT; use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder}; use subxt_signer::sr25519::dev; -#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")] +#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")] pub mod runtime {} +use runtime::runtime_types::xcm::v2::multilocation::MultiLocation; // We don't need to construct this at runtime, // so an empty enum is appropriate: @@ -18,6 +19,7 @@ impl Config for CustomConfig { type Hasher = subxt::config::substrate::BlakeTwo256; type Header = subxt::config::substrate::SubstrateHeader; type ExtrinsicParams = CustomExtrinsicParams; + type AssetId = MultiLocation; } // This represents some arbitrary (and nonsensical) custom parameters that diff --git a/subxt/examples/setup_config_signed_extension.rs b/subxt/examples/setup_config_signed_extension.rs index 38e871bfa1..42c278dfbd 100644 --- a/subxt/examples/setup_config_signed_extension.rs +++ b/subxt/examples/setup_config_signed_extension.rs @@ -30,12 +30,13 @@ impl Config for CustomConfig { signed_extensions::CheckNonce, signed_extensions::CheckGenesis, signed_extensions::CheckMortality, - signed_extensions::ChargeAssetTxPayment, + signed_extensions::ChargeAssetTxPayment, signed_extensions::ChargeTransactionPayment, // And add a new one of our own: CustomSignedExtension, ), >; + type AssetId = u32; } // Our custom signed extension doesn't do much: diff --git a/subxt/src/config/default_extrinsic_params.rs b/subxt/src/config/default_extrinsic_params.rs index f044574258..880591e7f0 100644 --- a/subxt/src/config/default_extrinsic_params.rs +++ b/subxt/src/config/default_extrinsic_params.rs @@ -15,7 +15,7 @@ pub type DefaultExtrinsicParams = signed_extensions::AnyOf< signed_extensions::CheckNonce, signed_extensions::CheckGenesis, signed_extensions::CheckMortality, - signed_extensions::ChargeAssetTxPayment, + signed_extensions::ChargeAssetTxPayment, signed_extensions::ChargeTransactionPayment, ), >; @@ -27,7 +27,7 @@ pub struct DefaultExtrinsicParamsBuilder { /// `None` means the tx will be immortal. mortality: Option>, /// `None` means we'll use the native token. - tip_of_asset_id: Option, + tip_of_asset_id: Option, tip: u128, tip_of: u128, } @@ -103,7 +103,7 @@ impl DefaultExtrinsicParamsBuilder { /// Provide a tip to the block auther using the token denominated by the `asset_id` provided. This /// is not applicable on chains which don't use the `ChargeAssetTxPayment` signed extension; in this /// case, no tip will be given. - pub fn tip_of(mut self, tip: u128, asset_id: u32) -> Self { + pub fn tip_of(mut self, tip: u128, asset_id: T::AssetId) -> Self { self.tip = 0; self.tip_of = tip; self.tip_of_asset_id = Some(asset_id); diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index 960c58b6d7..c52d1a029a 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -51,6 +51,9 @@ pub trait Config: Sized + Send + Sync + 'static { /// This type defines the extrinsic extra and additional parameters. type ExtrinsicParams: ExtrinsicParams; + + /// This is used to identify an asset in the `ChargeAssetTxPayment` signed extension. + type AssetId: Debug + Encode; } /// given some [`Config`], this return the other params needed for its `ExtrinsicParams`. diff --git a/subxt/src/config/polkadot.rs b/subxt/src/config/polkadot.rs index 5fb3390483..209c3b8fb6 100644 --- a/subxt/src/config/polkadot.rs +++ b/subxt/src/config/polkadot.rs @@ -21,6 +21,7 @@ impl Config for PolkadotConfig { type Hasher = ::Hasher; type Header = ::Header; type ExtrinsicParams = PolkadotExtrinsicParams; + type AssetId = u32; } /// A struct representing the signed extra and additional parameters required diff --git a/subxt/src/config/signed_extensions.rs b/subxt/src/config/signed_extensions.rs index 5b6e43d58a..13c87a6a1d 100644 --- a/subxt/src/config/signed_extensions.rs +++ b/subxt/src/config/signed_extensions.rs @@ -217,19 +217,27 @@ impl SignedExtension for CheckMortality { /// The [`ChargeAssetTxPayment`] signed extension. #[derive(Debug)] -pub struct ChargeAssetTxPayment { +pub struct ChargeAssetTxPayment { tip: Compact, - asset_id: Option, + asset_id: Option, } /// Parameters to configure the [`ChargeAssetTxPayment`] signed extension. -#[derive(Default)] -pub struct ChargeAssetTxPaymentParams { +pub struct ChargeAssetTxPaymentParams { tip: u128, - asset_id: Option, + asset_id: Option, } -impl ChargeAssetTxPaymentParams { +impl Default for ChargeAssetTxPaymentParams { + fn default() -> Self { + ChargeAssetTxPaymentParams { + tip: Default::default(), + asset_id: Default::default(), + } + } +} + +impl ChargeAssetTxPaymentParams { /// Don't provide a tip to the extrinsic author. pub fn no_tip() -> Self { ChargeAssetTxPaymentParams { @@ -245,7 +253,7 @@ impl ChargeAssetTxPaymentParams { } } /// Tip the extrinsic author using the asset ID given. - pub fn tip_of(tip: u128, asset_id: u32) -> Self { + pub fn tip_of(tip: u128, asset_id: T::AssetId) -> Self { ChargeAssetTxPaymentParams { tip, asset_id: Some(asset_id), @@ -253,8 +261,8 @@ impl ChargeAssetTxPaymentParams { } } -impl ExtrinsicParams for ChargeAssetTxPayment { - type OtherParams = ChargeAssetTxPaymentParams; +impl ExtrinsicParams for ChargeAssetTxPayment { + type OtherParams = ChargeAssetTxPaymentParams; type Error = std::convert::Infallible; fn new>( @@ -269,13 +277,13 @@ impl ExtrinsicParams for ChargeAssetTxPayment { } } -impl ExtrinsicParamsEncoder for ChargeAssetTxPayment { +impl ExtrinsicParamsEncoder for ChargeAssetTxPayment { fn encode_extra_to(&self, v: &mut Vec) { - (self.tip, self.asset_id).encode_to(v); + (self.tip, &self.asset_id).encode_to(v); } } -impl SignedExtension for ChargeAssetTxPayment { +impl SignedExtension for ChargeAssetTxPayment { const NAME: &'static str = "ChargeAssetTxPayment"; } diff --git a/subxt/src/config/substrate.rs b/subxt/src/config/substrate.rs index 609b20a778..44cfcf7b73 100644 --- a/subxt/src/config/substrate.rs +++ b/subxt/src/config/substrate.rs @@ -24,6 +24,7 @@ impl Config for SubstrateConfig { type Hasher = BlakeTwo256; type Header = SubstrateHeader; type ExtrinsicParams = SubstrateExtrinsicParams; + type AssetId = u32; } /// A struct representing the signed extra and additional parameters required