mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Add DefaultParams to allow more transaction extensions to be used when calling _default() methods (#1979)
* Add DefaultParams to allow more transaction extensions to be used when calling _default() methods * More imple for AnyOf/DefaultParams * Prevent T param being used twice in macro * clippy
This commit is contained in:
@@ -81,12 +81,11 @@ impl<T: Config> Params<T> for () {}
|
|||||||
|
|
||||||
macro_rules! impl_tuples {
|
macro_rules! impl_tuples {
|
||||||
($($ident:ident $index:tt),+) => {
|
($($ident:ident $index:tt),+) => {
|
||||||
|
impl <Conf: Config, $($ident : Params<Conf>),+> Params<Conf> for ($($ident,)+){
|
||||||
impl <T: Config, $($ident : Params<T>),+> Params<T> for ($($ident,)+){
|
|
||||||
fn inject_account_nonce(&mut self, nonce: u64) {
|
fn inject_account_nonce(&mut self, nonce: u64) {
|
||||||
$(self.$index.inject_account_nonce(nonce);)+
|
$(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);)+
|
$(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);
|
||||||
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);
|
||||||
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);
|
||||||
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, 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, 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, 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);
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ mod tx_progress;
|
|||||||
pub use subxt_core::tx::payload::{dynamic, DefaultPayload, DynamicPayload, Payload};
|
pub use subxt_core::tx::payload::{dynamic, DefaultPayload, DynamicPayload, Payload};
|
||||||
pub use subxt_core::tx::signer::{self, Signer};
|
pub use subxt_core::tx::signer::{self, Signer};
|
||||||
pub use tx_client::{
|
pub use tx_client::{
|
||||||
PartialTransaction, SubmittableTransaction, TransactionInvalid, TransactionUnknown, TxClient,
|
DefaultParams, PartialTransaction, SubmittableTransaction, TransactionInvalid,
|
||||||
ValidationResult,
|
TransactionUnknown, TxClient, ValidationResult,
|
||||||
};
|
};
|
||||||
pub use tx_progress::{TxInBlock, TxProgress, TxStatus};
|
pub use tx_progress::{TxInBlock, TxProgress, TxStatus};
|
||||||
|
|||||||
@@ -281,9 +281,9 @@ where
|
|||||||
where
|
where
|
||||||
Call: Payload,
|
Call: Payload,
|
||||||
Signer: SignerT<T>,
|
Signer: SignerT<T>,
|
||||||
<T::ExtrinsicParams as ExtrinsicParams<T>>::Params: Default,
|
<T::ExtrinsicParams as ExtrinsicParams<T>>::Params: DefaultParams,
|
||||||
{
|
{
|
||||||
self.sign_and_submit_then_watch(call, signer, Default::default())
|
self.sign_and_submit_then_watch(call, signer, DefaultParams::default_params())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,9 +325,10 @@ where
|
|||||||
where
|
where
|
||||||
Call: Payload,
|
Call: Payload,
|
||||||
Signer: SignerT<T>,
|
Signer: SignerT<T>,
|
||||||
<T::ExtrinsicParams as ExtrinsicParams<T>>::Params: Default,
|
<T::ExtrinsicParams as ExtrinsicParams<T>>::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.
|
/// Creates and signs an transaction and submits to the chain for block inclusion.
|
||||||
@@ -514,7 +515,7 @@ where
|
|||||||
match sub.next().await {
|
match sub.next().await {
|
||||||
Some(Ok(status)) => match status {
|
Some(Ok(status)) => match status {
|
||||||
TransactionStatus::Validated
|
TransactionStatus::Validated
|
||||||
| TransactionStatus::Broadcasted { .. }
|
| TransactionStatus::Broadcasted
|
||||||
| TransactionStatus::InBestBlock { .. }
|
| TransactionStatus::InBestBlock { .. }
|
||||||
| TransactionStatus::NoLongerInBestBlock
|
| TransactionStatus::NoLongerInBestBlock
|
||||||
| TransactionStatus::InFinalizedBlock { .. } => Ok(ext_hash),
|
| TransactionStatus::InFinalizedBlock { .. } => Ok(ext_hash),
|
||||||
@@ -754,6 +755,67 @@ pub enum TransactionInvalid {
|
|||||||
BadSigner,
|
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<const N: usize, P: Default> 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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user