From b0f6d8fa39e61ff46a6799d5b524a816ffc759c6 Mon Sep 17 00:00:00 2001 From: guigou Date: Fri, 30 Aug 2024 16:10:38 +0200 Subject: [PATCH] add new fields (mode + metadata_hash) when submitting a transaction. These fields have been included by RFC78 for signed extension --- crates/pink-libs/subrpc/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/pink-libs/subrpc/src/lib.rs b/crates/pink-libs/subrpc/src/lib.rs index 35bfd49b7..64270f52a 100644 --- a/crates/pink-libs/subrpc/src/lib.rs +++ b/crates/pink-libs/subrpc/src/lib.rs @@ -209,7 +209,7 @@ fn compute_era(block_number: u64) -> core::result::Result { /// /// An extended version of `create_transaction`, fine-grain #[allow(clippy::too_many_arguments)] -pub fn create_transaction_ext( +pub fn create_transaction_ext( signer: &[u8; 32], public_key: &[u8; 32], nonce: u64, @@ -220,14 +220,17 @@ pub fn create_transaction_ext( call_data: UnsignedExtrinsic, era: Era, tip: u128, + mode: u8, + metadata_hash: Option<[u8;32]>, ) -> core::result::Result, Error> { let additional_params = ( spec_version, transaction_version, genesis_hash, era_checkpoint, + metadata_hash, ); - let extra = (era, Compact(nonce), Compact(tip)); + let extra = (era, Compact(nonce), Compact(tip), mode); let mut bytes = Vec::new(); call_data.encode_to(&mut bytes); @@ -309,6 +312,12 @@ pub fn create_transaction( Some(n) => n, _ => get_next_nonce(rpc_node, &addr)?, }; + // new fields added by RFC78 for the signed extension. + // more information here: https://polkadot-fellows.github.io/RFCs/approved/0078-merkleized-metadata.html#inclusion-in-an-extrinsic + // the mode is either 0 which means to not include the metadata hash in the signed data or the mode is 1 to include the metadata hash in V1. + let mode = 0; + // Included in the signed data is an Option<[u8; 32]>. Depending on the mode the value is either None or Some(metadata_hash). + let metadata_hash = None; let call_data = UnsignedExtrinsic { pallet_id, @@ -326,6 +335,8 @@ pub fn create_transaction( call_data, era, tip, + mode, + metadata_hash, ) }