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

Add ability to create dynamically sized abi.DynamicArrays #603

Open
jasonpaulos opened this issue Nov 14, 2022 · 0 comments
Open

Add ability to create dynamically sized abi.DynamicArrays #603

jasonpaulos opened this issue Nov 14, 2022 · 0 comments

Comments

@jasonpaulos
Copy link
Contributor

jasonpaulos commented Nov 14, 2022

Problem

Contract methods which return dynamic arrays likely do not know the size of the array they need to return at compile time.

Unfortunately, the only way to initialize/modify an abi.DynamicArray value is with the set method:

def set(
self,
values: Union[Sequence[T], "DynamicArray[T]", ComputedValue["DynamicArray[T]"]],
) -> Expr:

This method only allows values to be a compile-time sequence of values, or to be another dynamic array. As a consequence of this, it's not currently possible to create an array of arbitrary length at runtime in PyTeal.

Possible Solutions

There are two possible solutions that could address this problem.

  1. Add the ability to append new elements to an existing dynamic array. Add ability to append to abi.DynamicArray #604 is the start of a PR to do this.
  2. If implemented in conjunction with Add ability to set individual elements in ABI containers #602, add the ability to create an arbitrary-sized dynamic array at runtime, perhaps with a default value to fill the array with. This would be similar in spirit to languages like Go or C, where you can dynamically allocate an array of a certain size and then set its elements individually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants