i have a pallet that prints extrinsic data (bytes and hex) of every extrinsic inside every block, how can i print it like an human readable object ("from", "to" ecc..)?
that's my pallet code:
#[frame_support::pallet]
pub mod pallet_custom {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_runtime::generic::UncheckedExtrinsic;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {
// Aggiungi le funzioni di chiamata qui
}
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(block_number: BlockNumberFor<T>) {
log::info!("🇮🇹 on_finalize | Block number is {:?}", block_number);
let total_block_transactions_count = frame_system::Pallet::<T>::extrinsic_count();
log::info!("🇮🇹 on_finalize | Extrinsic count is {:?}", total_block_transactions_count);
for i in 0..total_block_transactions_count {
let transactions_data = frame_system::Pallet::<T>::extrinsic_data(i);
log::info!("🇮🇹 on_finalize | Extrinsic data {:?} is {:?}", i, transactions_data);
// convert the transaction data to hex string
let transactions_data_hex = hex::encode(transactions_data.clone());
log::info!("🇮🇹 on_finalize | Extrinsic data hex {:?} is {:?}", i, transactions_data_hex);
}
}
fn offchain_worker(block_number: BlockNumberFor<T>) {
log::info!("🇮🇹 offchain_worker | Block number is {:?}", block_number);
}
}
}
I hope to read something like:
{from: "0x94..", to: "0x4a9...", value: 0, data: "0x39c...."}
i receive something like:
0xe50184f24ff3a9cf04c71dbc94d0b566f7a27b94566cac48ddbb2036e1a0b045ce62ce71741ef06493cc58a03056adc3026a04ecb471dd3cd433087417721f1d4f716acc03d2cfda9b5cde20dbefaeafa6ce79ef25fbdf00350000000403798d4ba9baf0064ec19eb4f0a1a45785ae9d6dfc130000e8890423c78a