forked from dfinity/cycles-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.sh
executable file
·72 lines (51 loc) · 2.25 KB
/
demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# The roles here are:
# Both Alice and Bob have their own wallet
# Charlie is a custodian of Alice (but Alice is the owner of her own wallet).
set -e
npm install
dfx start --background --clean
dfx identity new id_alice || true
dfx identity new id_bob || true
dfx identity new id_charlie || true
dfx --identity id_alice canister create alice --with-cycles=5000000000000
dfx --identity id_bob canister create bob --with-cycles=2000000000000
dfx --identity default canister create wallet --with-cycles=3000000000000
dfx build
dfx --identity id_alice canister install alice
dfx --identity id_bob canister install bob
dfx --identity default canister install wallet
echo
echo == Initial cycle balances for Alice and Bob.
echo
echo Alice = $(dfx --identity id_alice canister call alice wallet_balance)
echo Bob = $(dfx --identity id_bob canister call bob wallet_balance)
echo
echo == Create a new canister with Alice as controller using 1000000000001 cycles.
echo
echo New canister id = $(dfx --identity id_alice canister call alice wallet_create_canister "(record { cycles = 1000000000001; controller = null })")
echo
echo == Transfer 1000000000000 cycles from Alice to Bob.
echo
eval dfx --identity id_alice canister call alice wallet_send "'(record { canister = principal \"$(dfx canister id bob)\"; amount = 1000000000000 })'"
echo
echo == Final cycle balances for Alice and Bob.
echo
echo Alice = $(dfx --identity id_alice canister call alice wallet_balance)
echo Bob = $(dfx --identity id_bob canister call bob wallet_balance)
echo
echo == Setting custodian of Alices wallet to Charlie
echo
dfx --identity id_alice canister call alice authorize "(principal \"$(dfx --identity id_charlie identity get-principal)\")"
echo
echo == Upgrading...
echo
dfx --identity id_alice canister install alice --mode=upgrade
echo
echo == Using Charlie to send cycles...
echo
eval dfx --identity id_charlie canister --no-wallet call alice wallet_send "'(record { canister = principal \"$(dfx canister id bob)\"; amount = 1000000000000 })'"
echo Alice = $(dfx --identity id_alice canister call alice wallet_balance)
echo Alice^ = $(dfx --identity id_charlie canister --no-wallet call alice wallet_balance)
echo Bob = $(dfx --identity id_bob canister call bob wallet_balance)
dfx stop