mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
No need to entangle Signer and nonce now (#702)
* no need to entangle Signr and nonce now * fmt
This commit is contained in:
+2
-26
@@ -14,12 +14,8 @@ use sp_runtime::traits::{
|
|||||||
|
|
||||||
/// Signing transactions requires a [`Signer`]. This is responsible for
|
/// Signing transactions requires a [`Signer`]. This is responsible for
|
||||||
/// providing the "from" account that the transaction is being signed by,
|
/// providing the "from" account that the transaction is being signed by,
|
||||||
/// as well as actually signing a SCALE encoded payload. Optionally, a
|
/// as well as actually signing a SCALE encoded payload.
|
||||||
/// signer can also provide the nonce for the transaction to use.
|
|
||||||
pub trait Signer<T: Config> {
|
pub trait Signer<T: Config> {
|
||||||
/// Optionally returns a nonce.
|
|
||||||
fn nonce(&self) -> Option<T::Index>;
|
|
||||||
|
|
||||||
/// Return the "from" account ID.
|
/// Return the "from" account ID.
|
||||||
fn account_id(&self) -> &T::AccountId;
|
fn account_id(&self) -> &T::AccountId;
|
||||||
|
|
||||||
@@ -37,7 +33,6 @@ pub trait Signer<T: Config> {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct PairSigner<T: Config, P: Pair> {
|
pub struct PairSigner<T: Config, P: Pair> {
|
||||||
account_id: T::AccountId,
|
account_id: T::AccountId,
|
||||||
nonce: Option<T::Index>,
|
|
||||||
signer: P,
|
signer: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,22 +48,7 @@ where
|
|||||||
pub fn new(signer: P) -> Self {
|
pub fn new(signer: P) -> Self {
|
||||||
let account_id =
|
let account_id =
|
||||||
<T::Signature as Verify>::Signer::from(signer.public()).into_account();
|
<T::Signature as Verify>::Signer::from(signer.public()).into_account();
|
||||||
Self {
|
Self { account_id, signer }
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`Pair`] implementation used to construct this.
|
/// Returns the [`Pair`] implementation used to construct this.
|
||||||
@@ -89,10 +69,6 @@ where
|
|||||||
P: Pair + 'static,
|
P: Pair + 'static,
|
||||||
P::Signature: Into<T::Signature> + 'static,
|
P::Signature: Into<T::Signature> + 'static,
|
||||||
{
|
{
|
||||||
fn nonce(&self) -> Option<T::Index> {
|
|
||||||
self.nonce
|
|
||||||
}
|
|
||||||
|
|
||||||
fn account_id(&self) -> &T::AccountId {
|
fn account_id(&self) -> &T::AccountId {
|
||||||
&self.account_id
|
&self.account_id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,14 +224,11 @@ where
|
|||||||
Call: TxPayload,
|
Call: TxPayload,
|
||||||
{
|
{
|
||||||
// Get nonce from the node.
|
// Get nonce from the node.
|
||||||
let account_nonce = if let Some(nonce) = signer.nonce() {
|
let account_nonce = self
|
||||||
nonce
|
.client
|
||||||
} else {
|
.rpc()
|
||||||
self.client
|
.system_account_next_index(signer.account_id())
|
||||||
.rpc()
|
.await?;
|
||||||
.system_account_next_index(signer.account_id())
|
|
||||||
.await?
|
|
||||||
};
|
|
||||||
|
|
||||||
self.create_signed_with_nonce(call, signer, account_nonce, other_params)
|
self.create_signed_with_nonce(call, signer, account_nonce, other_params)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user