Description
An Array type for CashScript have been a long-standing idea.
Rosco in Sept 2019 discussion:
This is my thought. I guess I'll want to support arrays at some point in the future, but semantically bytes32 is usually one variable rather than an array of independent values
Then you could have an array of bytes32 as bytes32[32] or something
Spedn does have array types but it has not seen any real use I think:
https://spedn.readthedocs.io/en/latest/types.html#arrays
Support for a fixed size array type in CashScript would enable syntax like this:
contract Multisig(
pubkey[3] signers // 3 pre-defined signers
) {
function verifyMultisig(sig[3] signatures) {
require(checkSig(signatures[0], signers[0]));
require(checkSig(signatures[1], signers[1]));
require(checkSig(signatures[2], signers[2]));
}
}
or using checkMultiSig(sig[] sigs, pubkey[] pks)
it would look like this:
contract Multisig(
pubkey[3] signers // 3 pre-defined signers
) {
function verifyMultisig(sig[3] signatures) {
require(checkMultiSig(signatures, signers));
}
}
The fixed size arrays could already support variable-length items like bytes[3]
but the number of array items would still be fixed (3)
It's only when the VM gets looping support and we can implement loops with #246 that arrays become really useful as you'd be able to do operations for/on each element of the array! 👀
This also enables dynamic (Variable-Length) arrays, so there would be 2 types of arrays which would function differently under the hood.