Canister Whitelist error, Help, Please!I

my project have multiple canister.
token canister: deal with balance, deposit and withdraw;
game canister: deal with the game logic and dependent to token canister.

and I want some of my function can only be called by game canister in order to prevent hijack.
since I can not import game canister in token canister , for it invoke cycling dependency.
I coding below:

let whiteList = Buffer.Buffer<Principal>(1);
 public shared (msg) func addBalance(user : Principal, amount : Nat) : async () {
        assert (Buffer.contains(whiteList, msg.caller, Principal.equal));
        book.addTokens(user, amount);
    public shared (msg) func reduceBalance(user : Principal, amount : Nat) : async () {
        assert (Buffer.contains(whiteList, msg.caller, Principal.equal));
        switch (book.removeTokens(user, amount)) {
            case (null) {
                Debug.print("not enough ICP!");
            case _ {};

aovwi-4maaa-aaaaa-qaagq-cai is game canister ID.
there is the error message:

Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed while trying to install all canisters.
    Failed to install wasm module to canister 'token'.
      Failed during wasm installation call: The Replica returned an error: code 5, message: "Canister aax3a-h4aaa-aaaaa-qaahq-cai trapped explicitly: RTS error: blob_of_principal: principal too short"

when I delete the code:


it works fine!
even I replace the aovwi-4maaa-aaaaa-qaagq-cai with


it still has the same error message!
what should I do!
is there any thing functions as whitelist?

I played with a cut down version here and can’t reproduce the error unless I call Principal.fromText("") (passing an empty string).

Are you sure you aren’t passing an empty string instead of a textual Principal somewhere?

thanks very!!!
I had Principal.fromText(“”) somewhere in my canister and now it works fine!
Loved you guys!

1 Like