Open rkalis opened 5 years ago
You could probably have destructured assignment like this:
{ bytes4 blockheight, bytes4 price } = message;
Or direct access llike this:
message.price
this is no longer only handy for datamessages used with checkDataSig
but also for nft state kept by contracts, or to defined the commitments the contract interacts with!
for example:
struct LoanCommitment{
bytes8 blockheight;
bytes20 loanerPubKeyHash;
bytes8 borrowedTokenAmount;
}
inspired by https://bitcoincashresearch.org/t/stable-asset-token-incentivized-floating-peg/1206
the idea that you could destructured borrowedTokenAmount
is quite powerful
Structs can be defined by the implementer of a contract like this:
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.