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

Support decoding signed extensions #1209

Merged
merged 16 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add signed extensions to block subscribing example
tadeohepperle committed Oct 30, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
haxscramper haxscramper
commit fe1db8c154f1e051c85c2d58a0da560f95ab2e4f
11 changes: 11 additions & 0 deletions subxt/examples/blocks_subscribing.rs
Original file line number Diff line number Diff line change
@@ -34,6 +34,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let decoded_ext = ext.as_root_extrinsic::<polkadot::Call>();

println!(" Extrinsic #{idx}:");
if let Some(signed_extensions) = ext.signed_extensions() {
println!(" Signed Extensions:");
for signed_extension in signed_extensions.iter() {
let signed_extension = signed_extension?;
let name = signed_extension.name();
let value = signed_extension.value()?.to_string();
println!(" {name}: {value}");
}
} else {
println!(" No Signed Extensions");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because this is an example, I wonder whether we could make this a bit less ugly, ie removing the else branch and moving it after the other println's or something?

println!(" Bytes: {bytes_hex}");
println!(" Decoded: {decoded_ext:?}");
println!(" Events:");
17 changes: 8 additions & 9 deletions subxt/src/blocks/extrinsic_types.rs
Original file line number Diff line number Diff line change
@@ -346,11 +346,7 @@ where
.map(|e| &self.bytes[e.address_start_idx..e.address_end_idx])
}

/// Return only the bytes of the signature for this signed extrinsic.
///
/// # Note
///
/// Returns `None` if the extrinsic is not signed.
/// Returns Some(signature_bytes) if the extrinsic was signed otherwise None is returned.
pub fn signature_bytes(&self) -> Option<&[u8]> {
self.signed_details
.as_ref()
@@ -657,8 +653,10 @@ impl<'a> ExtrinsicSignedExtensions<'a> {
})
}

/// The tip of an extrinsic, extracted from the `ChargeTransactionPayment` or
/// `ChargeAssetTxPayment` signed extension, depending on which is present.
/// The tip of an extrinsic, extracted from the ChargeTransactionPayment or ChargeAssetTxPayment
/// signed extension, depending on which is present.
///
/// Returns `None` if `tip` was not found or decoding failed.
pub fn tip(&self) -> Option<u128> {
jsdw marked this conversation as resolved.
Show resolved Hide resolved
let tip = self.iter().find_map(|e| {
e.ok().filter(|e| {
@@ -672,8 +670,9 @@ impl<'a> ExtrinsicSignedExtensions<'a> {
Some(tip)
}

/// The nonce of the account that submitted the extrinsic, extracted from the
/// CheckNonce signed extension.
/// The nonce of the account that submitted the extrinsic, extracted from the CheckNonce signed extension.
///
/// Returns `None` if `nonce` was not found or decoding failed.
pub fn nonce(&self) -> Option<u64> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail on certain runtimes if the CheckNonce isn't part of the SignedExtra.

Might worth a comment for it and advise to use the dynamic API then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be nice to have for the general usecase...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just for a common case that will most likely work, and should fail gracefully and return None if the relevant extension isn't found :)

let nonce = self
.iter()