Motoko - check if function is called internally

Hi
I have a baic questio about Motoko.
Is there a way to check if function is called internally?
For example when a function is called by another function internally, I know that msg.caller returns canister id (for example rrkah-fqaa-aaaa-…) and I can just use and if msg.caller == hardcoded vaue to check if it is internll call.
Is there a better way to do it without hardcoding?

You can get the ‘internal’ canister id like this:

actor class X() = this {
  func y() {
    // cid is the canister id of this instance.
    cid = Principal.fromActor(this);
  };
}
4 Likes

And when and if actor t <: principal · Issue #2264 · dfinity/motoko · GitHub gets implemented you won’t even have to convert from actor to principal explicitly

2 Likes