Ic_cdk::api::call::method_name()

如何用rust 使用这个方法,当我使用时,他给我返回The Replica returned an error: code 5, message: “Canister ryjl3-tyaaa-aaaaa-aaaba-cai violated contract: “ic0_msg_method_name_size” cannot be executed in update mode”

2 Likes

@kpeacock @chenyan Do you know when we are allowed to call method_name? It doesn’t seem to work in query or update calls, and I can’t find documentation on it.

According to the spec, it’s only callable from #[inspect_message]

1 Like

Great to know, do you have a link to where it says this in the documentation?

We should document this in the cdk docs, but from the interface spec, you can find
The Internet Computer Interface Specification | Internet Computer Home, see the line ic0.msg_method_name_size : () -> i32 // F

1 Like

I would like to bring this subject back up. Why can’t we get the method_name from query and update calls? This would be useful to us in the Azle and Kybra CDKs. Right now to get the method name, we are walking the stack/callframe to the first frame in our interpreter (in JS), and using another language feature in Python, to get the top-level function’s name. If we could just ask the IC for the method name at any time I believe we could remove these messier solutions.

It may just be because the method name is statically known for normal methods and assumed to be redundant.

@nomeata might be able to shed some light on this.


@lastmjs can you provide an example where you need to access the method name?

I think at some point you statically know what the method name is (don’t you generate candid, etc?) and can probably make it available to the method somehow.

We worked around this by storing the name globally and ensuring to set it appropriately across await boundaries.