Open febo opened 2 years ago
This would only work for types that have a clear max defined, i.e. Options Some
vs None
is an example.
However once you have a string or an array then the max size is potentially infinite. Do you have any ideas on how to handle those?
Would it make sense to annotate the Rust struct with the max size? Even when we use strings and arrays in programs, we know what would be the max size since we need to allocate the account space. Then solita could get the information from the annotation and be able to determine the size of the data type.
Yes that is an option. So combining these ideas we could do the following:
maxSize
getter which just returns byteSize
(since it is constant)#[derive(ShankType(max_size=<size>)]
shank would pick that up and include this info in the IDL + solita generates a getter that just returns that <size>
For the second option we need to extend shank and the types with a maxSize need to derive a ShankType(maxSize=x)
(right now they just need to be BorshSerialize/BorshDeserialize
.
Does that make sense?
Sounds good!
Solita generates a
BeetArgsStruct
that exposes a type's attributes usingbeet
types. We could also include the information of how many bytes the struct would take at most. This would help to create custom serialization/deserialization patterns. This could be either an autogenerated function or the facility to querybeet
with the attributes of the generated type.