-
Notifications
You must be signed in to change notification settings - Fork 31
ABI 1.3: Fixed sized arrays
Antelope ABI currently supports variable sized arrays via type[], add support for fixed sized arrays via type[size].
- 17 Apr 2025: Initial public release
Primary motivation is that cdt can output these ABI types already (ultimately producing an invalid ABI). Besides that, it has been an unfortunate omission that has been brought up in the past.
The new fixed size array type is defined by the name of the type followed by brackets with a well-formed positive base-10 unsigned integer within the brackets.
Valid types are, for example,
-
type[6]-- fixed size array of length 6 -
type[1]-- fixed size array of length 1 -
type[42]-- fixed size array of length 42
Invalid types are, for example,
-
type[-4]-- negative not allowed -
type[anything_containing a non-0-9 character]-- only '0' through '9' allowed within brackets -
type[0x5]-- 'x' character not allowed; must not be accepted as hexadecimal number -
type[+5]-- '+' character not allowed; must not be accepted as number -
type[0]-- zero not allowed -
type[010]-- leading zeros not allowed; must not be accepted as either 10 nor 8
Serializing or deserializing in nodeos will be limited to 1048576 items similar to variable sized arrays. So a type such as type[2000000] while allowed by the ABI specification will be unable to be effectively used in nodeos. Thus, Antelope ABI implementations may choose their own reasonable limit for the maximum number of elements when performing serialization and deserialization, but the recommendation is that all implementations should handle at least 1048576 items.
The type is simply serialized or deserialized a fixed number of times based on the size defined in the type. There is no leading size appended to the serialized data.
Represented as a JSON array similar to how variable sized arrays already are. The one difference is that when reading a fixed size array the JSON array size must match the defined length otherwise it is considered an error.
Oftentimes developers want to have a fixed size byte array. That would likely be represented by something like uint8[6]. But this would be output in JSON as value: [0, 0, 0, 0, 0, 0] which might not be what is expected for a byte array (maybe something more like value: "000000000000" would be expected). A possible "byte[size]" type is being considered.
Just like variable size arrays, optional fixed size arrays (represented by something like type[n]?) are not supported in the abi. However, binary extensions holding a fixed size array (represented by something like type[n]$) are supported.