Store arbitrary number of uint64 in Application

Ciao everyone,

upon creation of an Application, I need to store an arbitrary number of uint64 data elements that will be used to unlock a defined amount of funds at predetermined times in the future. They don’t need to be an infinite number, up to 10 could be enough for now, but their number is not predefined (e.g. could be either 0, 3, or 10) similar to using a variable size array.

I’m currently using PyTeal w/Beaker.

In your opinion, which is the best way to address this problem? Both for providing these inputs to the Application (e.g. how to overload the create method for this case) and for storing/accessing them.

Do you have any useful resources to read about?

Thanks,
elia

Are you using PyTeal, Reach, TEAL, or something else?

Assuming 10 different numbers, I would include them as separate arguments to the application and then loop through each once and store the value in global state under some predetermined key. You could definitely do it in more advanced ways, but it’s simple enough to just iterate through them using txn NumAppArgs.

Ciao @nullun

Sorry, I forgot to include this information, I’m currently using PyTeal and Beaker.

Is it possible to add an arbitrary amount of arguments to an application call implementing ABI interfaces?
Something like:

create(uint64,address,uint64,uint64,string,uint64,uint64,uint64, <arbitrary number, up to 10, of uint64 >)void

The first 8 arguments are necessary to initialize the application’s global states, then I have to manage the up to 10 “amount of funds” arguments.
Given the high number of arguments (exceeding 16), I guess it is better to split this operation into two phases:

  1. create the application,
  2. update the “amount of funds” global states, if possible as a grouped txn with the first one.

Even in this case, it is not clear to me which would be the best way to manage an arbitrary number of states similar to using a variable-size array using Beaker/PyTeal and the ABI methods.

Hey @elia, my apologies for the late response.

Regarding your arbitrary number of arguments, I’d consider using an dynamic length array, then in your code you could loop through that individual argument which is roughly the length divided by the size of a uint64, giving you the number of values you’ve been passed.

If you’re going to exhaust your opcode budget processing such a large number of segments in an arg, then you may want to perform opcode budget pooling, but submitting an additional application call which does nothing but provides you with an extra ~700 opcodes.