The upgrader canister allows the creation of polls to approve upgrade of other canisters. This is achieved by allowing registered voters to approve or reject upgrades identified by unique hashes.
Thee different types of polls can be created:
ProjectHash
: a poll to approve a specific project hashAddPermission
: a poll to grant permissions to a PrincipalRemovePermission
: a poll to remove permissions from a Principal
For each new poll, the creator has to provide the following informations:
description
: The description of the poll,poll_type
: The type of poll as discussed above,start_timestamp_secs
: The timestamp in seconds of when the poll opensend_timestamp_secs
: The timestamp in seconds of when the poll closes
The access to the canister features is restricted by a set of permissions that allow selected Pricipals to operate on the canister. The available permissions are:
Admin
: this permission grants admin rights to the principal. An admin can directy grant or remove permissions to other principalsCreateProject
: Allows calling the endpoints to create a project (e.g. evm, bridge, etc.)CreatePoll
: Allows calling the endpoints to create a pollVotePoll
: Allows calling the endpoints to vote in a poll
Build the canister wasm:
./scripts/build.sh
(Optional) If you don't have one yet, create a local dfx identity
dfx identity new --storage-mode=plaintext alice
dfx identity use alice
Get current IC identity pricipal
IDENTITY_PRICIPAL=$(dfx identity get-principal)
echo $IDENTITY_PRICIPAL
Start dfx in background
dfx start --clean --background --artificial-delay 0
Install the upgrader-canister and set the current IC identity as administrator
dfx canister install --mode=install --yes --network=local upgrader_canister --argument="(record { admin = principal \"$IDENTITY_PRICIPAL\" })"
UPGRADER_CANISTER_ID=$(dfx canister id upgrader_canister)
Verify that the canister is working, this should return information about the canister build
dfx canister call $UPGRADER_CANISTER_ID canister_build_data --network local
Before a user attempts to create a project or a poll, the administrator should grant him the required permissions. For simplicity, in this example we use the admin account itself to perform every operation.
Grant the permissions to create a project, create a poll and vote
dfx canister call $UPGRADER_CANISTER_ID admin_permissions_add --network local "(principal \"$IDENTITY_PRICIPAL\", vec {variant { CreateProject }; variant { CreatePoll }; variant { VotePoll }})"
Create a project
dfx canister call $UPGRADER_CANISTER_ID project_create --network local "(record { key = \"test_project\" ; name = \"test_project_name\"; description = \"test_project_description\" })"
Create a poll for the test_project
dfx canister call $UPGRADER_CANISTER_ID poll_create --network local '(record { description = "A new hash"; end_timestamp_secs = 999_999_999_999 : nat64; poll_type = variant { ProjectHash = record { hash = "hash"; project = "test_project" } }; start_timestamp_secs = 0 : nat64; }, )'
the previous call returns the ID of the new poll, for example, here the poll ID is 1
:
(variant { Ok = 1 : nat64 })
POLL_ID=1
Now let's vote by approving for the poll (use false
to reject instead)
dfx canister call $UPGRADER_CANISTER_ID poll_vote --network local "($POLL_ID: nat64, true)"
We can now verify that the vote is registered
dfx canister call $UPGRADER_CANISTER_ID poll_get --network local "($POLL_ID: nat64)"