forked from Psychedelic/dank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dank.sh
executable file
·146 lines (122 loc) · 3.7 KB
/
dank.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
dfxDir="/home/dan/.config/dfx"
candidDir="/home/dan/dev/psy/dank/candid"
xtcID=$(dfx canister id xtc)
piggyID=$(dfx canister id piggy-bank)
AlicePem="${dfxDir}/identity/Alice/identity.pem"
BobPem="${dfxDir}/identity/Bob/identity.pem"
CharliePem="${dfxDir}/identity/Charlie/identity.pem"
xtcCandidFile="${candidDir}/xtc.did"
piggyCandidFile="${candidDir}/piggy-bank.did"
AlicePrincipalId=$(dfx identity use Alice 2>/dev/null;dfx identity get-principal)
BobPrincipalId=$(dfx identity use Bob 2>/dev/null;dfx identity get-principal)
CharliePrincipalId=$(dfx identity use Charlie 2>/dev/null;dfx identity get-principal)
icxPrologueXtc="--candid=${xtcCandidFile}"
icxProloguePiggy="--candid=${piggyCandidFile}"
dfx identity use default 2>/dev/null
declare -A nameToPrincipal=( ["Alice"]="$AlicePrincipalId" ["Bob"]="$BobPrincipalId" ["Charlie"]="$CharliePrincipalId")
declare -A nameToPem=( ["Alice"]="$AlicePem" ["Bob"]="$BobPem" ["Charlie"]="$CharliePem")
burn(){
fromPem="${nameToPem[$1]}"
amount=$2
icx --pem=$fromPem update $xtcID burn "record { canister_id= principal \"$piggyID\"; amount = $amount:nat64}" $icxPrologueXtc
}
allowance(){
pem=$AlicePem
from="${nameToPrincipal[$1]}"
to="${nameToPrincipal[$2]}"
icx --pem=$pem query $xtcID allowance "(principal \"$from\", principal \"$to\")" $icxPrologueXtc
}
decimals(){
pem=$AlicePem
icx --pem=$pem query $xtcID decimals "()" $icxPrologueXtc
}
getMetadata(){
pem=$AlicePem
icx --pem=$pem query $xtcID getMetadata "()" $icxPrologueXtc
}
historySize(){
pem=$AlicePem
icx --pem=$pem query $xtcID historySize "()" $icxPrologueXtc
}
logo(){
pem=$AlicePem
icx --pem=$pem query $xtcID logo "()" $icxPrologueXtc
}
name(){
pem=$AlicePem
icx --pem=$pem query $xtcID nameErc20 "()" $icxPrologueXtc
}
nameLegacy(){
pem=$AlicePem
icx --pem=$pem query $xtcID name "()" $icxPrologueXtc
}
symbol(){
pem=$AlicePem
icx --pem=$pem query $xtcID symbol "()" $icxPrologueXtc
}
totalSupply(){
pem=$AlicePem
icx --pem=$pem query $xtcID totalSupply "()" $icxPrologueXtc
}
stats(){
pem=$AlicePem
icx --pem=$pem query $xtcID stats $icxPrologueXtc
}
getTransaction(){
txId=$1
pem=$AlicePem
icx --pem=$pem update $xtcID getTransaction "($txId:nat)" $icxPrologueXtc
}
getTransactions(){
txId=$1
limit=$2
pem=$AlicePem
icx --pem=$pem update $xtcID getTransactions "($txId:nat, $limit:nat)" $icxPrologueXtc
}
getTransactionLegacy(){
from=$1
pem=$AlicePem
icx --pem=$pem update $xtcID get_transaction "($from:nat64)" $icxPrologueXtc
}
approve(){
pem="${nameToPem[$1]}"
to="${nameToPrincipal[$2]}"
amount=$3
icx --pem=$pem update $xtcID approve "(principal \"$to\", $amount:nat)" $icxPrologueXtc
}
transfer(){
fromPem="${nameToPem[$1]}"
to="${nameToPrincipal[$2]}"
amount=$3
icx --pem=$fromPem update $xtcID transferErc20 "(principal \"$to\", $amount:nat)" $icxPrologueXtc
}
transferFrom(){
from="${nameToPrincipal[$1]}"
to="${nameToPrincipal[$2]}"
amount=$3
callerPem="${nameToPem[$1]}"
if [ "$#" -eq 4 ]; then
callerPem="${nameToPem[$4]}"
fi
icx --pem=$callerPem update $xtcID transferFrom "(principal \"$from\",principal \"$to\", $amount:nat)" $icxPrologueXtc
}
balanceOf(){
pem=$AlicePem
account="${nameToPrincipal[$1]}"
icx --pem=$pem query $xtcID balanceOf "(principal \"$account\")" $icxPrologueXtc
}
mint(){
pem="${nameToPem[$1]}"
amount="${2:-10_000_000_000_000}"
icx --pem=$pem update $piggyID perform_mint "(record { canister= principal \"$xtcID\"; account=null; cycles=10_000_000_000_000 })" $icxProloguePiggy
}
topup(){
dfx canister deposit-cycles 10000000000000 ryjl3-tyaaa-aaaaa-aaaba-cai
}
setup(){
topup
mint Alice
transfer Alice Bob 10
approve Alice Bob 1000
}