I am working with the Motoko candid encoding package, It’s great that we have this in Motoko and it’s come in very helpful. But, i’m finding it very verbose to declare large records with multiple variants. Both the type RecordFieldType
and value RecordFieldValue
need to be declared for the encoding to work - it results in repeated code ? Is there a better / cleaner way to format this? Example:
// candid formatting:
let commandArgType : CandidType.RecordFieldType = {
tag = #name("command");
type_ = #opt(
#variant([{
tag = #name("Configure");
type_ = #record([{
tag = #name("operation");
type_ = #opt(
#variant([{
tag = #name("AddHotKey");
type_ = #record([{
tag = #name("new_hot_key");
type_ = #opt(#principal);
}]);
}])
);
}]);
}])
);
};
let commandArgValue : CandidValue.RecordFieldValue = {
tag = #name("command");
value = #opt(
#variant({
tag = #name("Configure");
value = #record([{
tag = #name("operation");
value = #opt(
#variant({
tag = #name("AddHotKey");
value = #record([{
tag = #name("new_hot_key");
value = #opt(#principal(hotkey));
}]);
})
);
}]);
})
);
};
I was thinking of expanding on this in my own project with some helper functions but maybe I am doing something wrong or there is a tool already in the package I am unaware of?
Tagging @Gekctek (creator of this particular package)