I am working on a pallet in which there is storage in which I am using a tuple. Can we use a struct instead of a tuple in the storage of pallet? if yes is there any reference to how we can use it?
1 Answer
If you use FRAME and the corresponding macros to define storage, then in that case the values stored will be serialized using the SCALE encoding.
SCALE encoding is equivalent between structs and tuples as long as they have the equal number of fields, with the same types.
For example, those structs
type A = (u32, bool);
#[derive(Encode, Decode)]
struct B {
number: u32,
flag: bool,
}
should be encoded the same way, so the following assertion will always be held:
// for each a of type A and each b of type B
fn test(a: A, b: B) {
// the SCALE encoding will be equal
assert_eq!(
a.encode(),
b.encode(),
);
}