algorand/pyteal

Add ability to set individual elements in ABI containers

Opened this issue · 0 comments

Problem

Right now the Tuple, StaticArray, and DynamicArray ABI type containers have set methods which can be used to set the entire container's value.

However, it's not currently possible to set the value of only a single element in that container.

Possible Solution

Perhaps the existing TupleElement and ArrayElement classes which are returned from __getitem__ for tuples and arrays, respectively, can be extended to allow modifying individual values as well.

That would make something like this possible:

def f() -> Expr:
    a = abi.make(abi.Bool)
    b = abi.make(abi.Uint64)
    c = abi.make(abi.Tuple2[abi.Bool, abi.Uint64])
    return Seq(
        a.set(True),  # a=True,  b=uninitialized, c=uninitialized
        b.set(100),   # a=True,  b=100,           c=uninitialized
        c.set(a, b),  # a=True,  b=100,           c=[True,100]
        a.set(False), # a=False, b=100,           c=[True,100]
        c[0].set(a)   # a=False, b=100,           c=[False,100]
        # the above line would be the proposed change
    )

Follow-up Concerns

If a way to set individual elements in a container is adopted, that doesn't change the fact that a container must be fully populated with all elements before any other operation can happen. Should we instead allow containers to be partially initialized, or initialized with default values?