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 set individual elements in ABI containers #602

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

Add ability to set individual elements in ABI containers #602

jasonpaulos opened this issue Nov 14, 2022 · 0 comments

Comments

@jasonpaulos
Copy link
Contributor

jasonpaulos commented Nov 14, 2022

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?

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