-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Zondax/dev
New Release
- Loading branch information
Showing
9 changed files
with
293 additions
and
141 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { ChainProps } from '../src/types' | ||
import { ChainProps } from "../src/types"; | ||
|
||
export interface RootHashParams { | ||
metadata: string | ||
props: ChainProps | ||
metadata: string; | ||
props: ChainProps; | ||
} | ||
|
||
export interface MetadataParams extends RootHashParams { | ||
callData: string | ||
signedExtensions: string | ||
callData: string; | ||
seIncludedInExtrinsic: string; | ||
seIncludedInSignedData: string; | ||
} | ||
export interface MetadataParamsTxBlob extends RootHashParams { | ||
txBlob: string; | ||
} | ||
|
||
export declare function getShortMetadata(params: MetadataParams): string | ||
export declare function getMetadataDigest(params: RootHashParams): string | ||
export declare function getShortMetadataFromTxBlob(params: MetadataParamsTxBlob): string; | ||
export declare function getShortMetadata(params: MetadataParams): string; | ||
export declare function getMetadataDigest(params: RootHashParams): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use frame_metadata::RuntimeMetadata; | ||
use merkleized_metadata::{FrameMetadataPrepared, SignedExtrinsicData,TypeResolver,CollectAccessedTypes}; | ||
use scale_decode::visitor::decode_with_visitor; | ||
|
||
pub fn get_parts_len_from_tx_blob( | ||
mut tx_blob: &[u8], | ||
metadata: &RuntimeMetadata, | ||
) -> Result<Vec<usize>, String> { | ||
let mut call_data_len:usize = 0; | ||
let mut signed_extensions_in_extrinsic_len:usize = 0; | ||
|
||
let prepared = FrameMetadataPrepared::prepare(metadata)?; | ||
let type_information = prepared.as_type_information()?; | ||
|
||
let tx_blob_ptr = &mut tx_blob; | ||
let tx_blob_ptr_init_len = tx_blob_ptr.len(); | ||
|
||
let type_resolver = TypeResolver::new(type_information.types.values()); | ||
|
||
let visitor = CollectAccessedTypes::default(); | ||
|
||
let mut visitor = decode_with_visitor( | ||
tx_blob_ptr, | ||
type_information.extrinsic_metadata.call_ty, | ||
&type_resolver, | ||
visitor, | ||
) | ||
.map_err(|e| format!("Failed to decode call: {e}"))?; | ||
|
||
call_data_len = tx_blob_ptr_init_len - tx_blob_ptr.len(); | ||
|
||
if !tx_blob_ptr.is_empty() { | ||
let included_in_extrinsic = &tx_blob_ptr.to_vec(); | ||
let signed_ext_data:Option<SignedExtrinsicData> = Some(SignedExtrinsicData{ | ||
included_in_extrinsic, | ||
included_in_signed_data: &[], | ||
}); | ||
|
||
let visitor = signed_ext_data | ||
.map(|mut signed_ext_data| { | ||
visitor.collect_all_types( | ||
&type_information.extrinsic_metadata.address_ty, | ||
&type_information, | ||
); | ||
visitor.collect_all_types( | ||
&type_information.extrinsic_metadata.signature_ty, | ||
&type_information, | ||
); | ||
|
||
let included_in_extrinsic_ptr = &mut signed_ext_data.included_in_extrinsic; | ||
let initial_len = included_in_extrinsic_ptr.len(); | ||
|
||
let fold_result = type_information | ||
.extrinsic_metadata | ||
.signed_extensions | ||
.iter() | ||
.try_fold(visitor.clone(), |visitor, se| { | ||
decode_with_visitor( | ||
included_in_extrinsic_ptr, | ||
se.included_in_extrinsic, | ||
&type_resolver, | ||
visitor, | ||
) | ||
.map_err(|e| format!("Failed to decode data in extrinsic ({}): {e}", se.identifier)) | ||
}); | ||
|
||
// Handle the fold result and calculate the length | ||
fold_result.map(|final_visitor| { | ||
signed_extensions_in_extrinsic_len = initial_len - included_in_extrinsic_ptr.len(); | ||
final_visitor | ||
}) | ||
}) | ||
.unwrap_or_else(|| Ok(visitor))?; // Handle error case or provide default | ||
} | ||
|
||
return Ok(Vec::from([call_data_len, signed_extensions_in_extrinsic_len])) | ||
} |
Oops, something went wrong.