//===---------------- print.rs --------------------------------------------===// // Copyright 2021, Tesseract Systems, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //===----------------------------------------------------------------------===// use anyhow::Error; use subxt::ext::codec::Decode; use subxt::ext::frame_metadata::v14::ExtrinsicMetadata; use subxt::ext::scale_value::scale::{decode_as_type, PortableRegistry}; use subxt::ext::sp_runtime::scale_info::form::PortableForm; pub fn print_extrinsic_data( extrinsic_data: &[u8], extrinsic_metadata: &[u8], extrinsic_types: &[u8], ) -> Result<(), Error> { let types: PortableRegistry = Decode::decode(&mut &extrinsic_types[..])?; let meta: ExtrinsicMetadata = Decode::decode(&mut &extrinsic_metadata[..])?; let data = &mut &extrinsic_data[1..]; let call = decode_as_type(data, meta.ty, &types)?; let extra: Vec<_> = meta .signed_extensions .iter() .map(|ext| decode_as_type(data, ext.ty, &types).map(|val| (ext.identifier.clone(), val))) .collect::>()?; let additional: Vec<_> = meta .signed_extensions .iter() .map(|ext| { decode_as_type(data, ext.additional_signed, &types) .map(|val| (ext.identifier.clone(), val)) }) .collect::>()?; println!("=================== Signing Extrinsic ==================="); println!("======== Call ========\n{}", call); println!("======== Extension Extras ========"); for (name, val) in extra { println!("{}: {}", name, val); } println!("======== Extension Additional Signed ========"); for (name, val) in additional { println!("{}: {}", name, val); } println!("==================="); Ok(()) }