Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use new account_nonce API from subxt 0.32.1 #1359

Merged
merged 2 commits into from
Oct 6, 2023
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/extrinsics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sp-weights = "21.0.0"
pallet-contracts-primitives = "25.0.0"
scale-info = "2.8.0"
subxt = "0.32.1"
subxt-signer = { version = "0.32.0", features = ["subxt", "sr25519"] }
subxt-signer = { version = "0.32.1", features = ["subxt", "sr25519"] }
hex = "0.4.3"

[dev-dependencies]
Expand Down
25 changes: 5 additions & 20 deletions crates/extrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ where
}

/// Return the account nonce at the *best* block for an account ID.
///
/// Replace this with the new `account_id` query available in the next `subxt`
/// release.
async fn get_account_nonce<T>(
client: &OnlineClient<T>,
rpc: &LegacyRpcMethods<T>,
Expand All @@ -304,24 +301,12 @@ where
.chain_get_block_hash(None)
.await?
.ok_or(subxt::Error::Other("Best block not found".into()))?;
let account_nonce_bytes = client
.backend()
.call(
"AccountNonceApi_account_nonce",
Some(&scale::Encode::encode(&account_id)),
best_block,
)
let account_nonce = client
.blocks()
.at(best_block)
.await?
.account_nonce(account_id)
.await?;

// custom decoding from a u16/u32/u64 into a u64, based on the number of bytes we
// got back.
let cursor = &mut &account_nonce_bytes[..];
let account_nonce: u64 = match account_nonce_bytes.len() {
2 => <u16 as scale::Decode>::decode(cursor)?.into(),
4 => <u32 as scale::Decode>::decode(cursor)?.into(),
8 => <u64 as scale::Decode>::decode(cursor)?,
_ => return Err(subxt::Error::Decode(subxt::error::DecodeError::custom_string(format!("state call AccountNonceApi_account_nonce returned an unexpected number of bytes: {} (expected 2, 4 or 8)", account_nonce_bytes.len()))))
};
Ok(account_nonce)
}

Expand Down