cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Add struct functionality

Open rkalis opened this issue 5 years ago • 2 comments

Structs can be defined by the implementer of a contract like this:

struct PriceMessage {
    bytes4 blockheight;
    bytes4 price;
}

The CashScript SDK can automatically serialise JSON data into a byte array containing these concatenated struct members. This serialised struct can then be passed into a contract function and the compiled script can use OP_SPLIT and OP_BIN2NUM to extract the correct struct members where needed.

To make sure the components can be extracted, they should use sized bytes types, so the usefulness of these structs is dependent on issue #20.

rkalis avatar Sep 15 '19 09:09 rkalis

You could probably have destructured assignment like this:

{ bytes4 blockheight, bytes4 price } = message;

Or direct access llike this:

message.price

rkalis avatar May 27 '20 07:05 rkalis

The destructured assignment is a similar to tuples so I don't think adding structs also is really necessary.

mr-zwets avatar Mar 15 '23 08:03 mr-zwets