cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Consider allowing auto-decoding numbers from split()

Open rkalis opened this issue 5 months ago • 0 comments

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 https://github.com/CashScript/cashscript/issues/27.

rkalis avatar Jul 23 '25 12:07 rkalis