-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add canister method to store imported tokens (#5210)
# Motivation We want to allow users to import custom tokens in NNS dapp by specifying a ledger canister ID and optional index canister ID. The imported tokens should be persisted with the account so we need to store them in the nns-dapp backend canister. We need to limit the number of tokens per user to have a bound on the amount of storage used. We arbitrarily set the limit to 10 and can increase it later if we want. We store the tokens in the user account which is stored in stable structures. To keep things simple we just support setting and getting the full list of tokens. # Changes Add `set_imported_tokens` and `get_imported_tokens` canister methods. # Tests 1. Unit tests added. 2. Tested manually with dfx: ``` $ dfx canister call nns-dapp get_imported_tokens --candid rs/backend/nns-dapp.did (variant { AccountNotFound }) $ dfx canister call nns-dapp --candid rs/backend/nns-dapp.did add_account ("a6e3ccdf7ede8e4b95c522d990a7be4d9d970b1f7bdcedf3baec857b65f7d8bd") $ dfx canister call nns-dapp --candid rs/backend/nns-dapp.did get_imported_tokens (variant { Ok = record { imported_tokens = vec {} } }) $ dfx canister call nns-dapp --candid rs/backend/nns-dapp.did set_imported_tokens '(record{imported_tokens = vec{ record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"} }})' (variant { Ok }) $ dfx canister call nns-dapp --candid rs/backend/nns-dapp.did get_imported_tokens ( variant { Ok = record { imported_tokens = vec { record { index_canister_id = null; ledger_canister_id = principal "xnjld-hqaaa-aaaal-qb56q-cai"; }; }; } }, ) $ dfx canister call nns-dapp --candid rs/backend/nns-dapp.did set_imported_tokens '(record{imported_tokens = vec{ record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"};record{ledger_canister_id=principal"xnjld-hqaaa-aaaal-qb56q-cai"}; }})' (variant { TooManyImportedTokens = record { limit = 10 : int32 } }) ``` 3. Max tested it in his branch with the frontend code. # Todos - [x] Add entry to changelog (if necessary).
- Loading branch information
Showing
9 changed files
with
255 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters