Skip to content

Commit

Permalink
add new fields (mode + metadata_hash) when submitting a transaction. …
Browse files Browse the repository at this point in the history
…These fields have been included by RFC78 for signed extension
  • Loading branch information
GuiGou12358 committed Aug 30, 2024
1 parent ff9d2f6 commit b0f6d8f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/pink-libs/subrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn compute_era(block_number: u64) -> core::result::Result<Era, Error> {
///
/// An extended version of `create_transaction`, fine-grain
#[allow(clippy::too_many_arguments)]
pub fn create_transaction_ext<T: Encode>(
pub fn create_transaction_ext<T: Encode>(
signer: &[u8; 32],
public_key: &[u8; 32],
nonce: u64,
Expand All @@ -220,14 +220,17 @@ pub fn create_transaction_ext<T: Encode>(
call_data: UnsignedExtrinsic<T>,
era: Era,
tip: u128,
mode: u8,
metadata_hash: Option<[u8;32]>,
) -> core::result::Result<Vec<u8>, 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);
Expand Down Expand Up @@ -309,6 +312,12 @@ pub fn create_transaction<T: Encode>(
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,
Expand All @@ -326,6 +335,8 @@ pub fn create_transaction<T: Encode>(
call_data,
era,
tip,
mode,
metadata_hash,
)
}

Expand Down

0 comments on commit b0f6d8f

Please sign in to comment.