Skip to content

Commit da507fa

Browse files
authored
No need to entangle Signer and nonce now (paritytech#702)
* no need to entangle Signr and nonce now * fmt
1 parent 563afda commit da507fa

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

subxt/src/tx/signer.rs

+2-26
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ use sp_runtime::traits::{
1414

1515
/// Signing transactions requires a [`Signer`]. This is responsible for
1616
/// providing the "from" account that the transaction is being signed by,
17-
/// as well as actually signing a SCALE encoded payload. Optionally, a
18-
/// signer can also provide the nonce for the transaction to use.
17+
/// as well as actually signing a SCALE encoded payload.
1918
pub trait Signer<T: Config> {
20-
/// Optionally returns a nonce.
21-
fn nonce(&self) -> Option<T::Index>;
22-
2319
/// Return the "from" account ID.
2420
fn account_id(&self) -> &T::AccountId;
2521

@@ -37,7 +33,6 @@ pub trait Signer<T: Config> {
3733
#[derive(Clone, Debug)]
3834
pub struct PairSigner<T: Config, P: Pair> {
3935
account_id: T::AccountId,
40-
nonce: Option<T::Index>,
4136
signer: P,
4237
}
4338

@@ -53,22 +48,7 @@ where
5348
pub fn new(signer: P) -> Self {
5449
let account_id =
5550
<T::Signature as Verify>::Signer::from(signer.public()).into_account();
56-
Self {
57-
account_id,
58-
nonce: None,
59-
signer,
60-
}
61-
}
62-
63-
/// Sets the nonce to a new value. By default, the nonce will
64-
/// be retrieved from the node. Setting one here will override that.
65-
pub fn set_nonce(&mut self, nonce: T::Index) {
66-
self.nonce = Some(nonce);
67-
}
68-
69-
/// Increment the nonce.
70-
pub fn increment_nonce(&mut self) {
71-
self.nonce = self.nonce.map(|nonce| nonce + 1u32.into());
51+
Self { account_id, signer }
7252
}
7353

7454
/// Returns the [`Pair`] implementation used to construct this.
@@ -89,10 +69,6 @@ where
8969
P: Pair + 'static,
9070
P::Signature: Into<T::Signature> + 'static,
9171
{
92-
fn nonce(&self) -> Option<T::Index> {
93-
self.nonce
94-
}
95-
9672
fn account_id(&self) -> &T::AccountId {
9773
&self.account_id
9874
}

subxt/src/tx/tx_client.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,11 @@ where
224224
Call: TxPayload,
225225
{
226226
// Get nonce from the node.
227-
let account_nonce = if let Some(nonce) = signer.nonce() {
228-
nonce
229-
} else {
230-
self.client
231-
.rpc()
232-
.system_account_next_index(signer.account_id())
233-
.await?
234-
};
227+
let account_nonce = self
228+
.client
229+
.rpc()
230+
.system_account_next_index(signer.account_id())
231+
.await?;
235232

236233
self.create_signed_with_nonce(call, signer, account_nonce, other_params)
237234
}

0 commit comments

Comments
 (0)