Skip to content

Commit

Permalink
Update to subxt 0.32.1, use account_nonce API (#1934)
Browse files Browse the repository at this point in the history
* Update to subxt 0.32.1, use account_nonce API

* Comment
  • Loading branch information
ascjones authored Oct 6, 2023
1 parent 1b84f8a commit 15742f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ serde_json = { version = "1.0.81" }
sha2 = { version = "0.10" }
sha3 = { version = "0.10" }
static_assertions = { version = "1.1" }
subxt = { version = "0.32.0" }
subxt-metadata = { version = "0.32.0" }
subxt-signer = { version = "0.32.0" }
subxt = { version = "0.32.1" }
subxt-metadata = { version = "0.32.1" }
subxt-signer = { version = "0.32.1" }
syn = { version = "2" }
synstructure = { version = "0.13.0" }
tokio = { version = "1.18.2" }
Expand Down
26 changes: 5 additions & 21 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,34 +373,18 @@ 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(
&self,
account_id: &C::AccountId,
) -> Result<u64, subxt::Error> {
let best_block = self.best_block().await;

let account_nonce_bytes = self
let account_nonce = self
.client
.backend()
.call(
"AccountNonceApi_account_nonce",
Some(&scale::Encode::encode(&account_id)),
best_block,
)
.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
2 changes: 1 addition & 1 deletion integration-tests/e2e-call-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ink = { path = "../../crates/ink", default-features = false }

[dev-dependencies]
ink_e2e = { path = "../../crates/e2e" }
subxt = { version = "0.32.0", default-features = false }
subxt = { version = "0.32.1", default-features = false }

[lib]
path = "lib.rs"
Expand Down

0 comments on commit 15742f0

Please sign in to comment.