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

Use of system_accountNextIndex as nonce #474

Closed
lemarier opened this issue Mar 11, 2022 · 1 comment · Fixed by #476
Closed

Use of system_accountNextIndex as nonce #474

lemarier opened this issue Mar 11, 2022 · 1 comment · Fixed by #476

Comments

@lemarier
Copy link
Contributor

lemarier commented Mar 11, 2022

Hi guys,

I'm wondering, is there any reason you are using the latest nonce instead of the rpc call system_accountNextIndexon the create_signed function?

You are currently using;

    pub async fn fetch_nonce<A: AccountData>(
        &self,
        account: &T::AccountId,
    ) -> Result<T::Index, BasicError>
    where
        <A as AccountData>::AccountId: From<<T as Config>::AccountId>,
        <A as AccountData>::Index: Into<<T as Config>::Index>,
    {
        let account_storage_entry = A::storage_entry(account.clone().into());
        let account_data = self
            .storage()
            .fetch_or_default(&account_storage_entry, None)
            .await?;
        Ok(A::nonce(&account_data).into())
    }

Something like this seems appropriate as it allows submitting multiple extrinsic for the same account id on the same block more easily, and seems more aligned with the polkadot-js ecosystem;

    /// Fetch the next nonce for the given account id.
    pub async fn fetch_next_nonce(
        &self,
        account: &T::AccountId,
    ) -> Result<T::Index, BasicError>
    where
        <T as Config>::AccountId: MaybeSerializeDeserialize,
        <T as Config>::Index: MaybeSerializeDeserialize,
    {
        Ok(self
            .rpc()
            .client
            .request("system_accountNextIndex", rpc_params![account])
            .await?)
    }

Thanks!

@ascjones
Copy link
Contributor

TBH I didn't even know this existed 🙈. This would be much better and simplify the code significantly!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants