From 124bd9c24bb1c57833638fda63b85e1bbbe0750d Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo.trentesaux@lilo.org> Date: Sat, 17 Feb 2024 21:02:23 +0100 Subject: [PATCH] Resolve "fix outdated transaction" (clients/rust/gcli-v2s!23) * review poka +fmt * use custom nonce --- src/commands.rs | 2 +- src/utils.rs | 42 +++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index f5bce93..15f96ba 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,7 +6,6 @@ pub mod collective; pub mod distance; pub mod expire; pub mod identity; -pub mod vault; pub mod net_test; pub mod oneshot; pub mod publish; @@ -16,3 +15,4 @@ pub mod smith; pub mod sudo; pub mod transfer; pub mod ud; +pub mod vault; diff --git a/src/utils.rs b/src/utils.rs index 91c0796..f9d5037 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -48,28 +48,32 @@ pub async fn submit_call<Payload: TxPayload>( data: &Data, payload: &Payload, ) -> Result<TxProgress, subxt::Error> { + // get account nonce manually to be based on last block and not last finalized + let nonce = data + .legacy_rpc_methods() // see issue #32 + .await + .system_account_next_index(&data.address()) + .await?; + + // sign and submit match data.keypair() { // sr25519 key pair - KeyPair::Sr25519(keypair) => { - data.client() - .tx() - .sign_and_submit_then_watch_default( - payload, - &PairSigner::<Runtime, sp_core::sr25519::Pair>::new(keypair), - ) - .await - } + KeyPair::Sr25519(keypair) => data.client().tx().create_signed_with_nonce( + payload, + &PairSigner::<Runtime, sp_core::sr25519::Pair>::new(keypair), + nonce, + Default::default(), + ), // nacl key pair - KeyPair::Nacl(keypair) => { - data.client() - .tx() - .sign_and_submit_then_watch_default( - payload, - &commands::cesium::CesiumSigner::new(keypair), - ) - .await - } - } + KeyPair::Nacl(keypair) => data.client().tx().create_signed_with_nonce( + payload, + &commands::cesium::CesiumSigner::new(keypair), + nonce, + Default::default(), + ), + }? + .submit_and_watch() + .await } /// look event -- GitLab