substrate-api-client
substrate-api-client copied to clipboard
No hooks found for pallet metadata
Hi maintainers, I try to extract the metadata of a Substrate WASM binary using ac-node-api::Metadata::try_from. The result looks great but seems like there are no hooks included in the returned data. Am I missing anything or this is not added in the current feature yet?
{"Timestamp": ["set"], "ParachainSystem": ["sudo_send_upward_message", "set_validation_data"], "XcmpQueue": ["update_suspend_threshold", "update_resume_threshold", "update_drop_threshold", "suspend_xcm_execution", "resume_xcm_execution"], "Session": ["set_keys", "purge_keys"], "System": ["set_storage", "set_heap_pages", "set_code_without_checks", "set_code", "remark_with_event", "remark", "kill_storage", "kill_prefix", "authorize_upgrade_without_checks", "authorize_upgrade", "apply_authorized_upgrade"], "CollatorSelection": ["update_bond", "take_candidate_slot", "set_invulnerables", "set_desired_candidates", "set_candidacy_bond", "remove_invulnerable", "register_as_candidate", "leave_intent", "add_invulnerable"], "MessageQueue": ["reap_page", "execute_overweight"], "ParachainInfo": [], "Balances": ["upgrade_accounts", "transfer_keep_alive", "transfer_allow_death", "transfer_all", "force_unreserve", "force_transfer", "force_set_balance", "force_adjust_total_issuance", "burn"], "CumulusXcm": [], "PolkadotXcm": ["transfer_assets_using_type_and_then", "transfer_assets", "teleport_assets", "send", "reserve_transfer_assets", "limited_teleport_assets", "limited_reserve_transfer_assets", "force_xcm_version", "force_unsubscribe_version_notify", "force_suspension", "force_subscribe_version_notify", "force_default_xcm_version", "execute", "claim_assets"], "Sudo": ["sudo_unchecked_weight", "sudo_as", "sudo", "set_key", "remove_key"]}
As can be seen in the above returned metadata. The pallet Timestamp does no have on_finalize() which is the hook of the pallet.
Hello chungquantin
I will check this tomorrow or the day after. Just to make sure: What is your use case? I'm guessing you don't want to simply print them, but also extract the hooks to use them in your code, is that correct?
Yea that's correct @haerdib. I build a CLI feature similar to frame-benchmarking-cli that allows you to select pallets and extrinsics to benchmark. the issue with benchmarking is hooks are benchmarked as well. For example, pallet_timestamp with set and on_finalize benchmarked, see here. Hence, to implement my use case, I need to retrieve all the extrinsics, hooks for user to pick from.
I have not found any hooks exposed by the polkadot relaychain in the metadata. Though it is quite big and I may have missed something. But you can easily check yourself. If the metadata at all exposes hooks, I'll gladly help you to access it!
In general the the Metadata struct is but a simple wrapper around the original, full metadata from frame-metadata. You can access it with metadata.runtime_metadata();
E.g. to save it as a file:
use std::io::Write;
let frame_metadata = metadata.runtime_metadata();
let mut file = std::fs::File::create("metadata.txt").unwrap();
let string = format!("{:?}", runtime_metadata);
file.write_all(string.as_bytes()).unwrap();
As there has not been any activity and the original frame-metadata is fully accessible, I'm closing this issue. If you still have some questions, feel free to reopen.