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

Blob interface can be simpler and consistent between inherited classes #137

Open
CiottiGiorgio opened this issue Dec 5, 2022 · 2 comments

Comments

@CiottiGiorgio
Copy link
Member

CiottiGiorgio commented Dec 5, 2022

class StateBlob(ABC):
    def __init__(self, num_keys: int):
        self.num_keys = num_keys

while

class AccountStateBlob(StateBlob):
    def __init__(self, keys: Optional[int | list[int]] = None):

and

class ApplicationStateBlob(StateBlob):
    def __init__(self, keys: Optional[int | list[int]] = None):

makes it hard to use StateBlob in an abstract way and then substitute with whatever implementation (signature on the abstract should match signatures on the concrete).

Furthermore, I think

class Blob(ABC):
    def __init__(self, key_limit: int, /, *, keys: Optional[int | list[int]] = None):

could be much simpler. Maybe always accepting just a int | Tuple[int, int] is enough?
I'm thinking of the case where a single global/local space could be storing multiple blobs so it makes sense to either specify the size or a range of slots.

@barnjamin
Copy link
Contributor

I thing in the proposed constructor, the key_limit and the keys passed an int could end up conflicting since they represent the same setting?

I'm thinking of the case where a single global/local space could be storing multiple blobs

can you say more about this?

@CiottiGiorgio
Copy link
Member Author

CiottiGiorgio commented Dec 5, 2022

I thing in the proposed constructor, the key_limit and the keys passed an int could end up conflicting since they represent the same setting?

I agree, to me the keys with the proposed signature should be enough for all use cases?

can you say more about this?

I'm writing data structures like lists, vectors and maps using Beaker Blob as a parent class and so the user should make sure on its own that the slots used to represent the DS(s) do not overlap. In my plan, a global state should hold at the very least a list and a couple of maps.
This possibly plays out with the same algorithm used in PyTeal for allocating ScratchSlot to ScratchVar in such a way that they don't overlap. It could also play out with ReservedState but in the interest of keeping things simple, explicit slot numbers can be provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants