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

Use structs as args for purchase #13457

Open
clemsos opened this issue Mar 12, 2024 · 1 comment
Open

Use structs as args for purchase #13457

clemsos opened this issue Mar 12, 2024 · 1 comment
Assignees
Labels
smart contract Smart contract related issue or task

Comments

@clemsos
Copy link
Member

clemsos commented Mar 12, 2024

The current models for the purchase function args is to pass several arrays of identical length - one for each required param of a purchase.

Current signature

function purchase(
    uint256[] calldata _values,
    address[] calldata _recipients,
    address[] calldata _referrers,
    address[] calldata _keyManagers,
    bytes[] calldata _data
  ) external payable returns (uint256[] memory tokenIds);

This makes unpacking encoding args difficult as array can be of arbitrary length.

Possible improvement

A more elegant solution could be to have a single array of Struct containing each the param for a single purchase.

Struct PurchaseArgs {
  uint price
  address recipient 
  address referrers 
  address keyManager
  bytes memory data
}

function purchase(PurchaseArgs[]) external payable returns (uint256[] memory tokenIds);

Not sure what will be the downsides, but it sure improves readability as well as the ability to loop and decode an encoded array of Structs.

Any thoughts?

@clemsos clemsos added the smart contract Smart contract related issue or task label Mar 12, 2024
@julien51
Copy link
Member

I think this is an interesting idea... BUT also a breaking change and we should be really careful with these changes. Could we just add another signature and show a deprecation warning for the old one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smart contract Smart contract related issue or task
Projects
None yet
Development

No branches or pull requests

2 participants