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
setMainOwnerto call the another’s actor’s (await setMainOwner) (what to do if theawaithappens to produce an error, e.g. because of overloaded network?) - Implement
onlyMainOwnerfor 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?