Expands substrate pallet crates and turns the pallet::Call
enum generated by the substrate macros into a generic
version.
The generated "pallet::Call" enum is bound to the "T:Config" property. For each dispatchable call in the pallet
the pallet::Call
enum has a variant that contains the function parameters, which can be types declared by T
such as T::Balance
.
This crate can parse the generated pallet::Call
and convert it to a generic version in which any
unique type bound to the T:Config
trait of pallet::Call
(like T::Balance
) is replaced by a generic type:
Let this be an excerpt of the generated pallet::Call
pub enum Call<T: Config> {
set_balance(
<T::Lookup as StaticLookup>::Source,
#[codec(compact)] T::Balance,
#[codec(compact)] T::Balance,
),
}
then the converted generic version will be
pub enum Call<Source, Balance> {
SetBalance(Source, #[codec(compact)] Balance, #[codec(compact)] Balance),
}
This can potentially be useful for transacting cross chain message calls to various runtimes.
Plug substrate-pallet-call-extract
to generate generic Calls types for pallets.
// this expands the `pallet-balances` crate that should be present as dependency in the crate's `Cargo.toml` file and parses the generated `pallet::Call`
let expanded_pallet_call = PalletCallConfig::default()
.parse_pallet("pallet-balances")
.unwrap();
// returns the tokenstream that contains the generic version of the call
let generic_call = expanded_pallet_call.expand().unwrap();
std::fs::write("<some path>.rs", generic_call.to_string()).unwrap();
Licensed under either of these:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)