Improving Motoko's programmability

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.

1 Like

How would reflection help here? I think you’d need a CBOR parser.

Again, this sounds like you’d need a CBOR codec instead of reflection.

I think you’re suggesting that reflection could be used in conjunction with some codec to generically provide implementations for those types, rather than writing them manually.

I still think that’s more of a convenience though, and otherwise the encoding/decoding is doable today if someone were to write the relevant codecs.

Yes on both accounts. For this application it is more of a parsing issue. But it would be cool.if there were a native interface and data type to do this since it is such an integral part of how everything works.

Check it! ICDevs.org - Bounty #18 - CBOR and Candid Motoko Parser - $3,000+ - #30 by skilesare. h/t @Gekctek