motoko
motoko copied to clipboard
Obtain actor principal without going through async methods
There is currently no way of passing 'this' - the current actor to a library inside the body during installation. Can we add a system function similar to postupgrade that will trigger on new install only. https://forum.dfinity.org/t/devefi-ledger-icrc-ledger-client-library/27274/3
When writing libraries - middleware, we have to do something like this:
public shared({caller}) func start() {
assert(Principal.isController(caller));
config.canister := Principal.fromActor(this);
ledgerOne.setOwner(this);
};
c.f https://github.com/dfinity/motoko/issues/3718
@crusso In our libraries we have a lot of code trying to distribute the current actor principal ~ 30 places. It feels like 5% of the code is about that, which is a bit strange. If we had Principal.currentActorPrincipal() it would be even better than when you added Principal.isController(..)
Do you think we can have this feature soon? If not I could make our libraries/middleware create a new canister with whoami and call it to obtain their principal. Like - the worst solution on the planet, but it will be tucked in a library, so nobody will see it, or have to call 'start'. It is the only solution that works in local and mainnet.
and a lot more. All 4 libraries (middleware) all using timers a lot - devefi-icrc-ledger, devefi-icp-ledger, devefi, rechain
And all the pocket ic tests testing the libraries