Skip to content

Commit 4e4a00d

Browse files
committed
feat: handle legacy compact prefix in signing payload parser
BTC-3197
1 parent 9872edf commit 4e4a00d

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

packages/wasm-dot/src/transaction.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,40 @@ fn parse_signing_payload(
630630
)
631631
})?;
632632

633-
// Use the RuntimeCall type from metadata to skip over call_data
633+
// Use the RuntimeCall type from metadata to skip over call_data.
634+
// Try wasm-dot format first (no compact prefix), then legacy polkadot-js format
635+
// which prepends compact(call_data_len) before the call_data.
634636
let call_ty_id = md.outer_enums().call_enum_ty();
635-
let call_data_size = skip_type_bytes(bytes, call_ty_id, md)?;
636-
let call_data = bytes[..call_data_size].to_vec();
637+
638+
let (call_data, ext_start) = match skip_type_bytes(bytes, call_ty_id, md) {
639+
Ok(size) => (bytes[..size].to_vec(), size),
640+
Err(_) => {
641+
// Try legacy format: compact(call_data_len) | call_data | ...
642+
use parity_scale_codec::{Compact, Decode};
643+
let mut cursor = bytes;
644+
let _len = <Compact<u32>>::decode(&mut cursor).map_err(|e| {
645+
WasmDotError::InvalidTransaction(format!(
646+
"Failed to parse signing payload (tried both formats): {}",
647+
e
648+
))
649+
})?;
650+
let prefix_size = bytes.len() - cursor.len();
651+
let call_data_size =
652+
skip_type_bytes(&bytes[prefix_size..], call_ty_id, md).map_err(|e| {
653+
WasmDotError::InvalidTransaction(format!(
654+
"Failed to parse signing payload (tried both formats): {}",
655+
e
656+
))
657+
})?;
658+
(
659+
bytes[prefix_size..prefix_size + call_data_size].to_vec(),
660+
prefix_size + call_data_size,
661+
)
662+
}
663+
};
637664

638665
// Parse signed extensions after call_data
639-
let ext_bytes = &bytes[call_data_size..];
666+
let ext_bytes = &bytes[ext_start..];
640667
let (era, nonce, tip, _ext_size) = parse_signed_extensions(ext_bytes, Some(md))?;
641668

642669
// Remaining bytes after extensions are additional_signed (spec_version, tx_version,

0 commit comments

Comments
 (0)