Skip to content

Split compose_call into two functions #598

@haerdib

Description

@haerdib

The current compose_call! macro expects the full metadata and the pallet name as input. But in case multiple calls for one pallet are created, the current code is forced to get the PalletMetada each time for each call. That's not necessary.

Therefore I'm proposing to split it into two functions:

/// Generates the extrinsic's call field for a given module and call passed as &str
/// # Arguments
///
/// * 'node_metadata' - This crate's parsed node metadata as field of the API.
/// * 'pallet' - Pallet name as &str for which the call is composed.
/// * 'call_name' - Call name as &str
/// * 'args' - Optional sequence of arguments of the call. They are not checked against the metadata.
/// As of now the user needs to check himself that the correct arguments are supplied.
#[macro_export]
macro_rules! compose_call {
($node_metadata: expr, $pallet: expr, $call_name: expr $(, $args: expr) *) => {
        {
            let pallet_metadata = $node_metadata.pallet_by_name($pallet).unwrap();
            $crate::compose_call_for_pallet_metadata !(pallet_metadata, $call $(, ($args)) *);
        }
    };
}

/// Generates the extrinsic's call field for the given PalletMetadata
/// # Arguments
///
/// * 'pallet_metadata' - This crate's parsed pallet metadata as field of the API.
/// * 'call_name' - Call name as &str
/// * 'args' - Optional sequence of arguments of the call. They are not checked against the metadata.
/// As of now the user needs to check himself that the correct arguments are supplied.
#[macro_export]
macro_rules! compose_call_for_pallet_metadata {
($pallet_metadata: expr, $call_name: expr $(, $args: expr) *) => {
        {
            let call_index = pallet.call_variant_by_name($call_name).unwrap().index;
            ([pallet.index(), call_index as u8] $(, ($args)) *)
        }
    };
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions