Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

No need to entangle Signer and nonce now #702

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions subxt/src/tx/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ use sp_runtime::traits::{

/// Signing transactions requires a [`Signer`]. This is responsible for
/// providing the "from" account that the transaction is being signed by,
/// as well as actually signing a SCALE encoded payload. Optionally, a
/// signer can also provide the nonce for the transaction to use.
/// as well as actually signing a SCALE encoded payload.
pub trait Signer<T: Config> {
/// Optionally returns a nonce.
fn nonce(&self) -> Option<T::Index>;

/// Return the "from" account ID.
fn account_id(&self) -> &T::AccountId;

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

Expand All @@ -53,22 +48,7 @@ where
pub fn new(signer: P) -> Self {
let account_id =
<T::Signature as Verify>::Signer::from(signer.public()).into_account();
Self {
account_id,
nonce: None,
signer,
}
}

/// Sets the nonce to a new value. By default, the nonce will
/// be retrieved from the node. Setting one here will override that.
pub fn set_nonce(&mut self, nonce: T::Index) {
self.nonce = Some(nonce);
}

/// Increment the nonce.
pub fn increment_nonce(&mut self) {
self.nonce = self.nonce.map(|nonce| nonce + 1u32.into());
Self { account_id, signer }
}

/// Returns the [`Pair`] implementation used to construct this.
Expand All @@ -89,10 +69,6 @@ where
P: Pair + 'static,
P::Signature: Into<T::Signature> + 'static,
{
fn nonce(&self) -> Option<T::Index> {
self.nonce
}

fn account_id(&self) -> &T::AccountId {
&self.account_id
}
Expand Down
13 changes: 5 additions & 8 deletions subxt/src/tx/tx_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,11 @@ where
Call: TxPayload,
{
// Get nonce from the node.
let account_nonce = if let Some(nonce) = signer.nonce() {
nonce
} else {
self.client
.rpc()
.system_account_next_index(signer.account_id())
.await?
};
let account_nonce = self
.client
.rpc()
.system_account_next_index(signer.account_id())
.await?;

self.create_signed_with_nonce(call, signer, account_nonce, other_params)
}
Expand Down