Skip to content

Add ability to create dynamically sized abi.DynamicArrays #603

Open
@jasonpaulos

Description

@jasonpaulos

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions