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

Support dynamic dispatch on Payload? #1670

Closed
SangyunOck opened this issue Jul 6, 2024 · 1 comment · Fixed by #1690
Closed

Support dynamic dispatch on Payload? #1670

SangyunOck opened this issue Jul 6, 2024 · 1 comment · Fixed by #1690

Comments

@SangyunOck
Copy link

SangyunOck commented Jul 6, 2024

// https://github.com/paritytech/subxt/blob/v0.37.0/subxt/src/tx/tx_client.rs#L90
pub fn create_partial_signed_offline<Call>(
    &self,
    call: &Call,
    params: <T::ExtrinsicParams as ExtrinsicParams<T>>::Params,
) -> Result<PartialExtrinsic<T, C>, Error>
where
    Call: Payload,

create_signed_offline method of TxClient accepts reference of call as generic Call which impls Payload trait.
There might be some use cases building some payloads(including issue #1241), ignoring the actual types and collect them in a vector to sign at once.

for example,

pub fn payout_stakers() -> Box<dyn Payload> {
    Box::new(tx().staking().payout_stakers())
}
pub fn bond() -> Box<dyn Payload> {
    Box::new(tx().staking().bond())
} 
pub fn sign_payloads(payloads: &[Box<dyn Payload>]) -> Result<Vec<u8>, Error> {
    Ok(payloads
        .into_iter()
        .map(|p| client.create_partial_signed_offline(p)?.into_encoded())
        .collect::<Result<Vec<_>, _>>()?)
}

It might be great if some smart pointers implements Payload trait as well as its original type.

// https://github.com/paritytech/subxt/blob/v0.37.0/core/src/tx/payload.rs#L21
#[auto_impl(&, Box, Rc, Arc)]
pub trait Payload { .. }

thank you :)

@jsdw
Copy link
Collaborator

jsdw commented Jul 23, 2024

I hesitated with this a bit because IIRC we used to have a way to box payloads, but it had some issues and was removed. However, I had a go in #1690 and it all worked out ok so def a nice thing to have :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants