candid
candid copied to clipboard
Omitting optional type in vec breaks
I have this Candid type taken as an argument to the initialization of a canister:
type InitArgs = record {
"decimals": nat8;
"fee": nat;
"initial_account_balances": vec InitialAccountBalance;
"metadata": vec Metadatum;
"minting_account": opt Account;
"name": text;
"permitted_drift_nanos": opt nat64;
"supported_standards": vec SupportedStandard;
"symbol": text;
"transaction_window_nanos": opt nat64;
};
If I try to deploy my canister with this Candid value:
record {
decimals = 8 : nat8;
fee = 0 : nat;
initial_account_balances = vec {
record {
account = record {
owner = principal "jm5gm-r5btc-kor5h-mkrva-sbubi-z2krh-3flug-4xr2v-bnkhf-w23cq-dae";
subaccount = null;
};
balance = 100_000_000 : nat;
};
record {
account = record {
owner = principal "jm5gm-r5btc-kor5h-mkrva-sbubi-z2krh-3flug-4xr2v-bnkhf-w23cq-dae";
subaccount = opt vec { 0 : nat8; 0 : nat8; 0 : nat8; 1 : nat8 };
};
balance = 200_000_000 : nat;
};
};
metadata = vec {};
minting_account = record {
owner = principal "jkpmw-aav35-wxvb3-lanyp-62lqw-fmtwc-cvqc3-jcn7p-6jtrt-x7csr-rae";
};
name = "Azle";
supported_standards = vec {};
symbol = "AZLE";
}
then I receive this error:
Installing code for canister icrc_1, with canister ID rrkah-fqaaa-aaaaa-aaaaq-cai
Error: Failed to install wasm in canister 'rrkah-fqaaa-aaaaa-aaaaq-cai'.
Caused by: Failed to install wasm in canister 'rrkah-fqaaa-aaaaa-aaaaq-cai'.
Failed to install wasm.
The Replica returned an error: code 5, message: "Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Custom(Trailing value after finishing deserialization
Caused by:
input: 4449444c066c08c6fcb6027dc295a993017befcee7800401aecbeb880402cbe4fdc7047185ccbc9c0e01d8def6f60e71c4c4f1810f036d6f6c01b3b0dac303686d046c029cbab69c027dadf9e78a0a056c02b3b0dac30368ad86ca83057f0100000800011d15df6d7a876b0370ff6970b1593b085580b69137eff26719dfe294620204417a6c650004415a4c450280c2d72f011da19894e8f4ec546a0906814674a89f655d0dcbc7550b5472db5b1406028084af5f011da19894e8f4ec546a0906814674a89f655d0dcbc7550b5472db5b140602_010400000001
table: type table0 = record {
5_094_982 : nat;
308_955_842 : nat8;
1_075_439_471 : table1;
1_092_281_774 : table2;
1_224_700_491 : text;
3_817_809_413 : table1;
4_007_505_752 : text;
4_030_489_156 : table3;
}
type table1 = vec empty
type table2 = record { 947_296_307 : principal }
type table3 = vec table4
type table4 = record { 596_483_356 : nat; 2_707_029_165 : table5 }
type table5 = record { 947_296_307 : principal; 1_349_681_965 : null }
wire_type: null, expect_type: opt vec nat8)"
If I instead omit subaccount in the first record in the initial_account_balances vec, I get this error:
Installing code for canister icrc_1, with canister ID rrkah-fqaaa-aaaaa-aaaaq-cai
Error: Failed to install wasm in canister 'rrkah-fqaaa-aaaaa-aaaaq-cai'.
Caused by: Failed to install wasm in canister 'rrkah-fqaaa-aaaaa-aaaaq-cai'.
Failed to install wasm.
The Replica returned an error: code 5, message: "Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Custom(Trailing value after finishing deserialization
Caused by:
input: 4449444c056c08c6fcb6027dc295a993017befcee7800401aecbeb880402cbe4fdc7047185ccbc9c0e01d8def6f60e71c4c4f1810f036d6f6c01b3b0dac303686d046c029cbab69c027dadf9e78a0a020100000800011d15df6d7a876b0370ff6970b1593b085580b69137eff26719dfe294620204417a6c650004415a4c450280c2d72f011da19894e8f4ec546a0906814674a89f655d0dcbc7550b5472db5b1406028084af5f011da19894e8f4ec546a0906814674a89f655d0dcbc7550b5472db5b140602_010400000001
table: type table0 = record {
5_094_982 : nat;
308_955_842 : nat8;
1_075_439_471 : table1;
1_092_281_774 : table2;
1_224_700_491 : text;
3_817_809_413 : table1;
4_007_505_752 : text;
4_030_489_156 : table3;
}
type table1 = vec empty
type table2 = record { 947_296_307 : principal }
type table3 = vec table4
type table4 = record { 596_483_356 : nat; 2_707_029_165 : table2 }
wire_type: reserved, expect_type: opt vec nat8)"
It's as if I can't have a null or omitted subaccount in one record while having an actual value in another. This seems like a bug.
How do you pass in the init args, via --argument in dfx? Is the init args type specified in the .did file? Something like service : (InitArgs) -> {...}. It looks like the type information is lost in the encoding somehow.