unlock icon indicating copy to clipboard operation
unlock copied to clipboard

Use structs as args for purchase

Open clemsos opened this issue 2 years ago • 2 comments

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 avatar Mar 12 '24 21:03 clemsos

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?

julien51 avatar Mar 13 '24 14:03 julien51

If we did this ^^ we could easily emit an event for each "purchase" and use that to construct receipts.

julien51 avatar May 09 '24 17:05 julien51