Skip to content

Consider allowing auto-decoding numbers from split() #330

@rkalis

Description

@rkalis

I really miss the following syntax I stumbled upon in my app:

   int a, int b = tx.inputs[0].nftCommitment.split(8);

Instead I need to express it as:

    bytes aBytes, bytes bBytes = tx.inputs[0].nftCommitment.split(8);
    int a = int(aBytes);
    int b = int(bBytes);

Originally posted by @mainnet-pat in #178

Some thoughts on this:

This would likely add 2 OP_BIN2NUM to convert the bytes to int. So it would add some "magic" to the operation / it would overload the .split() operator to have different functioning depending on what it is assigning to. I don't know if that is something we want to introduce. Especially since we're also critically looking at our current type-casting implementation, which also has some overloading that we want to get rid of.

I think if we're adding "magic" then I'd prefer to take it one step further and go for a full magic struct decoding, where you could specify the structure of the encoded data, and decode any part of that magically. See #27.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions