Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split compose_call into two functions #598

Closed
haerdib opened this issue Jun 28, 2023 · 0 comments · Fixed by #706
Closed

Split compose_call into two functions #598

haerdib opened this issue Jun 28, 2023 · 0 comments · Fixed by #706
Assignees
Labels
F7-enhancement Enhances an already existing functionality Q0-trivial

Comments

@haerdib
Copy link
Contributor

haerdib commented Jun 28, 2023

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)) *)
        }
    };
}
@haerdib haerdib added F7-enhancement Enhances an already existing functionality Q0-trivial labels Jun 28, 2023
@haerdib haerdib changed the title Split compose_call into two function Split compose_call into two functions Jun 28, 2023
@haerdib haerdib self-assigned this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F7-enhancement Enhances an already existing functionality Q0-trivial
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant