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 query and params attributes to be of type Pubkey #60

Open
danmt opened this issue Jul 5, 2024 · 0 comments
Open

Support query and params attributes to be of type Pubkey #60

danmt opened this issue Jul 5, 2024 · 0 comments
Labels
core This issue is related to the core functionality enhancement New feature or request

Comments

@danmt
Copy link
Contributor

danmt commented Jul 5, 2024

Using the type Pubkey in the query and params attributes from a derive Action should be validated and parsed before reaching the context.

Assuming there's a case like this:

#[derive(Action)]
#[params(receiver: Pubkey)]
pub struct SendDonationAction;

Then the handler of this action gets access to the receiver already parsed and the validation happens behind the scenes. A handler could look like this:

#[collection]
pub mod my_actions {
    use super::*;

    pub fn send_donation(ctx: Context<SendDonationAction>) -> Result<Transaction> {
        let account_pubkey = &ctx.payload.account; // payload.account should be parsed too
        let receiver_pubkey = &ctx.params.receiver; // receiver is already a pubkey
       // ...
    }
}

Note that the account and receiver come from the HTTP request as strings. Look into extractors with custom types.

@danmt danmt added enhancement New feature or request core This issue is related to the core functionality labels Jul 5, 2024
@danmt danmt assigned danmt and unassigned danmt Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core This issue is related to the core functionality enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant