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

Example for decoding box state when using get_box on a struct content #10

Open
aorumbayev opened this issue Mar 2, 2023 · 2 comments
Open

Comments

@aorumbayev
Copy link
Contributor

Not entirely sure how to decode the b64 string that get_box returns when the content is a struct type

I think the title is pretty self explanatory but if examples needed lmk ;)

@aorumbayev
Copy link
Contributor Author

Super drafty helper I'm using for now for this, this assumes that tealish compiler's compile was executed outside of this util:

def decode_struct(struct_name: str, byte_string: bytes):
    struct = tealish_builtins.structs[struct_name]

    decoded = {}
    fields = struct.fields
    for name in fields:
        decoded[name] = int.from_bytes(
            byte_string[fields[name].offset : fields[name].offset + fields[name].size],
            byteorder="big",
            signed=False,
        )
    return decoded

Also i know that my struct is only int fields so this won't work for identifying the type dynamically

@aorumbayev
Copy link
Contributor Author

thanks for hints with this so far @fergalwalsh ;)

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

1 participant