Just click view .did file. If you want to retrieve it dynamically from a canister in real time it is a bit more tricky…but this should suffice for most use cases. Just save the .mo or .rs and reference it.
Edit: ahhh…this is c# …still awesome. If you wanted your motoko canister to do something like this you might be able to pull it off with some mix o @Gekctek 's canid motoko and @tomijaga 's serde. There is an endpoint endpoint that publishes the candid as text. Then use call_raw.
It does if you want to consume and deal with canisters that are deployed after your canister with new did types.
We’ve hacked together virtual reflection with serde and motoko candid. Someone has to feed in known object keys and variant names, but it kind of works. It would be great if it was supported in a more motoko-native way.
The whole point of Candid is to allow upgrade to be backward compatible, so that you can call canisters as long as the upgrade follows subtyping. If the target canister upgrade doesn’t follow the subtyping relation, even reflection won’t work. I’m curious to see an example where the Candid subtyping is not enough.
The use case is a blackholed wallet canister that needs to/wants to interact with canisters that have been deployed with types that originated after the wallet canister was blackholed.
If you want to do things like create a language that permits/blocks specific calls that meet certain thresholds, it would be nice to inspect and reason about the bytes coming over the wire to you.
If we want to add a feature to axon that lets you block function calls where a candid parameter is above a certain threshold(say ICRC-6 adds some NFT statistic parameter that I can’t know about in my wallet that I am blackholing today).
I want to tell the wallet to allow a function called where mint_nft_with_stat(record { token_id: Nat; stat: Nat}) as long as stat is <= 15…but disallow if the stat is above. It would be much easier to reason with this if I have a native way to call
let reflective_type : reflective_candid = to_reflective_candid(args, cheat_list_of_keys);
I can keep cheat_list_of keys by uploading new candid files and just holding a buffer of items that I’m concerned about in my wallet.
It is just simple reflection that many other languages have. We’re close to figuring it out on our own, but it would be nice if we had some formal guidance or support on what we’re missing/how to get there. @Gekctek and @tomijaga are the heroes that have gotten us this far.
I’ve even started messing with it in candy_library.
Let me try to rephrase your use case: The wallet canister wants to inspect the Candid arguments before forwarding the calls. In the example, you want to forward any arguments that contains the stat field with stat <= 15. Then the following should work?
do ? {
let reflective_type = from_candid(blob, ?{ stat : Nat })!;
if (reflective_type.stat <= 15) { ... }
}