Skip to content

Commit

Permalink
Expose the SCALE encoded call data of an extrinsic (#573)
Browse files Browse the repository at this point in the history
* Expose SCALE encoded call data of an extrinsic

* Update subxt/src/client.rs

Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>

Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
  • Loading branch information
jsdw and lexnv authored Jun 22, 2022
1 parent 1e8d095 commit 6d7a6c9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions subxt/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ where
.await
}

/// Return the SCALE encoded bytes representing the call data of the transaction.
pub fn call_data(&self) -> Result<Vec<u8>, BasicError> {
let mut bytes = Vec::new();
let locked_metadata = self.client.metadata();
let metadata = locked_metadata.read();
let pallet = metadata.pallet(C::PALLET)?;
bytes.push(pallet.index());
bytes.push(pallet.call_index::<C>()?);
self.call.encode_to(&mut bytes);
Ok(bytes)
}

/// Creates a returns a raw signed extrinsic, without submitting it.
pub async fn create_signed(
&self,
Expand All @@ -371,16 +383,7 @@ where
};

// 2. SCALE encode call data to bytes (pallet u8, call u8, call params).
let call_data = {
let mut bytes = Vec::new();
let locked_metadata = self.client.metadata();
let metadata = locked_metadata.read();
let pallet = metadata.pallet(C::PALLET)?;
bytes.push(pallet.index());
bytes.push(pallet.call_index::<C>()?);
self.call.encode_to(&mut bytes);
Encoded(bytes)
};
let call_data = Encoded(self.call_data()?);

// 3. Construct our custom additional/extra params.
let additional_and_extra_params = {
Expand Down

0 comments on commit 6d7a6c9

Please sign in to comment.