diff --git a/core/src/config/extrinsic_params.rs b/core/src/config/extrinsic_params.rs index 89b926aa06f..45f1c17489d 100644 --- a/core/src/config/extrinsic_params.rs +++ b/core/src/config/extrinsic_params.rs @@ -81,12 +81,11 @@ impl Params for () {} macro_rules! impl_tuples { ($($ident:ident $index:tt),+) => { - - impl ),+> Params for ($($ident,)+){ + impl ),+> Params for ($($ident,)+){ fn inject_account_nonce(&mut self, nonce: u64) { $(self.$index.inject_account_nonce(nonce);)+ } - fn inject_block(&mut self, number: u64, hash: T::Hash) { + fn inject_block(&mut self, number: u64, hash: Conf::Hash) { $(self.$index.inject_block(number, hash);)+ } } @@ -114,6 +113,11 @@ const _: () = { impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16); impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17); impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18); - impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, U 19); - impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, U 19, V 20); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20, V 21); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20, V 21, W 22); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20, V 21, W 22, X 23); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20, V 21, W 22, X 23, Y 24); + impl_tuples!(A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9, K 10, L 11, M 12, N 13, O 14, P 15, Q 16, R 17, S 18, T 19, U 20, V 21, W 22, X 23, Y 24, Z 25); }; diff --git a/subxt/src/tx/mod.rs b/subxt/src/tx/mod.rs index a920e644c2e..98f5bd59515 100644 --- a/subxt/src/tx/mod.rs +++ b/subxt/src/tx/mod.rs @@ -15,7 +15,7 @@ mod tx_progress; pub use subxt_core::tx::payload::{dynamic, DefaultPayload, DynamicPayload, Payload}; pub use subxt_core::tx::signer::{self, Signer}; pub use tx_client::{ - PartialTransaction, SubmittableTransaction, TransactionInvalid, TransactionUnknown, TxClient, - ValidationResult, + DefaultParams, PartialTransaction, SubmittableTransaction, TransactionInvalid, + TransactionUnknown, TxClient, ValidationResult, }; pub use tx_progress::{TxInBlock, TxProgress, TxStatus}; diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index 41ddc0ae956..1dbf0aa82d9 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -281,9 +281,9 @@ where where Call: Payload, Signer: SignerT, - >::Params: Default, + >::Params: DefaultParams, { - self.sign_and_submit_then_watch(call, signer, Default::default()) + self.sign_and_submit_then_watch(call, signer, DefaultParams::default_params()) .await } @@ -325,9 +325,10 @@ where where Call: Payload, Signer: SignerT, - >::Params: Default, + >::Params: DefaultParams, { - self.sign_and_submit(call, signer, Default::default()).await + self.sign_and_submit(call, signer, DefaultParams::default_params()) + .await } /// Creates and signs an transaction and submits to the chain for block inclusion. @@ -514,7 +515,7 @@ where match sub.next().await { Some(Ok(status)) => match status { TransactionStatus::Validated - | TransactionStatus::Broadcasted { .. } + | TransactionStatus::Broadcasted | TransactionStatus::InBestBlock { .. } | TransactionStatus::NoLongerInBestBlock | TransactionStatus::InFinalizedBlock { .. } => Ok(ext_hash), @@ -754,6 +755,67 @@ pub enum TransactionInvalid { BadSigner, } +/// This trait is used to create default values for extrinsic params. We use this instead of +/// [`Default`] because we want to be able to support params which are tuples of more than 12 +/// entries (which is the maximum tuple size Rust currently implements [`Default`] for on tuples), +/// given that we aren't far off having more than 12 transaction extensions already. +/// +/// If you have params which are _not_ a tuple and which you'd like to be instantiated automatically +/// when calling [`TxClient::sign_and_submit_default()`] or [`TxClient::sign_and_submit_then_watch_default()`], +/// then you'll need to implement this trait for them. +pub trait DefaultParams: Sized { + /// Instantiate a default instance of the parameters. + fn default_params() -> Self; +} + +impl DefaultParams for [P; N] { + fn default_params() -> Self { + core::array::from_fn(|_| P::default()) + } +} + +macro_rules! impl_default_params_for_tuple { + ($($ident:ident),+) => { + impl <$($ident : Default),+> DefaultParams for ($($ident,)+){ + fn default_params() -> Self { + ( + $($ident::default(),)+ + ) + } + } + } +} + +#[rustfmt::skip] +const _: () = { + impl_default_params_for_tuple!(A); + impl_default_params_for_tuple!(A, B); + impl_default_params_for_tuple!(A, B, C); + impl_default_params_for_tuple!(A, B, C, D); + impl_default_params_for_tuple!(A, B, C, D, E); + impl_default_params_for_tuple!(A, B, C, D, E, F); + impl_default_params_for_tuple!(A, B, C, D, E, F, G); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y); + impl_default_params_for_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z); +}; + #[cfg(test)] mod test { use super::*;