I came up with another case where I need some Candid/Cbor love inside of Motoko.
I have an on-chain wallet. It provides multi-sig functionality. Users can call a function via call(principal, function, data) and a proposal is created. I’d like to support showing the incoming data as readable text. The problem is that I don’t want to have to upgrade my canister each time a new service comes online. I’d like to let a service provider, user, or app to give me the candid. Then I can use this candid to parse the incoming blob. For example:
This is a call to “send_dfx” on the canister zzzzz with value:
SendArgs = {
to : “kdkfkdjfdj”;
fee : 20000;
memo : 1;
from_subaccount : null;
created_at_time : null;
amount : 100000000;}
I can’t do this right now because all I’ll have is a Blob. But even if I had the candid definition I can’t do it because I don’t have a cbor → candid conversion library.
I’m not asking to coerce the blob to an unknown type or anything, I just want a library that lets me do it if I want. Maybe I want to construct a known type, convert it to a binary representation, hash it, and keep an eye out for that particular function signature in the future.
I feel like I can come up with a lot of reasons why I’d want some kind of reflection/conversion. Maybe they aren’t good reasons.