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

[x/Programs] Dynamic Arguments #624

Merged
merged 36 commits into from
Dec 2, 2023
Merged

[x/Programs] Dynamic Arguments #624

merged 36 commits into from
Dec 2, 2023

Conversation

samliok
Copy link
Contributor

@samliok samliok commented Nov 21, 2023

Dynamic Arguments

This PR add support for non fixed length program function args. #576 .

Changes:

  • Arguments passed into #[public] functions must be prefixed with a uint32 length.
    • This does not include supported primitives and the Program type
    • after the length prefix, parameters for #[public] functions are serialized using borsh.
  • The public proc_macro was updated to call from_raw_pointer on ptrs.
    • This function unpacks the 4 byte length prefix, and converts the subsequent bytes into the specified argument.

example usage

#[public]
pub fn print_name(_: Program, name: String) {
    println!("name: {}", name);
}
/// Mints tokens to multiple recipients.
#[public]
pub fn mint_to_many(program: Program, recipients: Vec<Address>, amounts: Vec<i32>) -> bool {
    assert_eq!(recipients.len(), amounts.len(), "invalid input");

    for (recipient, amount) in recipients.iter().zip(amounts.iter()) {
        mint_to(program, *recipient, *amount as i64);
    }

    true
}

@samliok samliok self-assigned this Nov 21, 2023
Copy link
Contributor

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change requests

richardpringle
richardpringle previously approved these changes Nov 23, 2023
richardpringle
richardpringle previously approved these changes Nov 29, 2023
Copy link
Contributor

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving!

Copy link
Contributor

@hexfusion hexfusion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this a great step forward I have a few cosmetic things to review and in general would like to see the go tests moving to simulator but that can be a followup.

hexfusion
hexfusion previously approved these changes Nov 30, 2023
richardpringle
richardpringle previously approved these changes Nov 30, 2023
Copy link
Contributor

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@samliok samliok dismissed stale reviews from richardpringle and hexfusion via 31ff2c7 December 1, 2023 23:38
@patrick-ogrady patrick-ogrady merged commit 5ac878f into main Dec 2, 2023
@patrick-ogrady patrick-ogrady deleted the dynamic_args branch December 2, 2023 00:23
@samliok samliok linked an issue Dec 11, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
4 participants