cashscript
cashscript copied to clipboard
Add struct functionality
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.
You could probably have destructured assignment like this:
{ bytes4 blockheight, bytes4 price } = message;
Or direct access llike this:
message.price
The destructured assignment is a similar to tuples so I don't think adding structs also is really necessary.