I found myself, while splitting my too big codebase (WASM code became greater than allowed) into two separate actors, writing the following in both halves after the split.
func onlyMainOwner(caller: Principal) {
if (?caller != founder) {
Debug.trap("not the main owner");
}
};
Now, the question is how to (re)implement
public shared({caller}) func setMainOwner(_founder: Principal) {
onlyMainOwner(caller);
founder := ?_founder;
};
for it to work for both actors?
Variants that come to my mind:
- The “main” actor’s
setMainOwner
to call the another’s actor’s (await setMainOwner
) (what to do if theawait
happens to produce an error, e.g. because of overloaded network?) - Implement
onlyMainOwner
for one of the two actors as calling another one? (Bad variant, at least, in terms of efficiency.) - Set owners for both actors separately. If an owner transfer ever happens, then it is not too much work to make two function calls instead of one.
“3” seems the best. How do you think?