This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
wallet.sh
executable file
·161 lines (128 loc) · 5.09 KB
/
wallet.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Usage:
# wallet (create | restore) [options] MNEMONICS...
# wallet create-account <wallet_id>
# wallet delete <wallet_id>
# wallet get [<wallet_id>]
# wallet get-accounts <wallet_id>
# wallet get-addresses <wallet_id>
# wallet update <wallet_id> [options]
# wallet utxo <wallet_id>
#
# The script allows for basic interaction with wallet.
# Please note that you can easily generate mnemonics for the script at https://iancoleman.io/bip39/.
#
# Arguments:
# <wallet_id> A wallet's root id
#
# Options:
# -h --help
# -a --assuranceLevel=STRING Assurance level [default: normal]
# -n --name=STRING Name of the wallet [default: TestWallet]
# -i --accountIndex=INT An optional parent account index [default: 2147483648]
# -p --port=INT Port the server is listening to [default: 8090]
# -c --client=FILEPATH TLS client certificate expected by the server [default: ../../../state-staging/tls/client/client.pem]
#
# Examples:
# ./wallet.sh restore parrot ugly lock symbol sibling display bright border yellow pencil area dawn
# ./wallet.sh create rival visa comfort stamp garbage trim cross awake hold aerobic bid glare
# ./wallet.sh get
# ./wallet.sh get Ae2tdPwUPEZKJycNa3AD1mBWThdXpJoyvdEksYBaJUUMoMN4XAfJ3h18Lib
# ./wallet.sh delete Ae2tdPwUPEZKJycNa3AD1mBWThdXpJoyvdEksYBaJUUMoMN4XAfJ3h18Lib
# ./wallet.sh create-account Ae2tdPwUPEZKyifkHShCKCbzzPbi7DBV7XuyTPEd13KRES4v8Ut3PmKebLy
# ./wallet.sh get-accounts Ae2tdPwUPEZKyifkHShCKCbzzPbi7DBV7XuyTPEd13KRES4v8Ut3PmKebLy
# ./wallet.sh get-addresses Ae2tdPwUPEZKyifkHShCKCbzzPbi7DBV7XuyTPEd13KRES4v8Ut3PmKebLy
# ./wallet.sh update Ae2tdPwUPEZKyifkHShCKCbzzPbi7DBV7XuyTPEd13KRES4v8Ut3PmKebLy -n "new name" -a "normal"
#
PATH=.:$PATH; source docopts.sh --auto "$@"
if [ ${ARGS[MNEMONICS,#]} -ne 0 ]; then
mnemonics_num=`expr ${ARGS[MNEMONICS,#]} - 1`
mnemonics="\"${ARGS[MNEMONICS,0]}\""
for i in $(seq 1 $mnemonics_num)
do
mnemonics+=",\"${ARGS[MNEMONICS,${i}]}\""
done
fi
# create
if [ "${ARGS[create]}" == "true" ]; then
curl -kX POST https://localhost:${ARGS[--port]}/api/v1/wallets \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} \
-d "{
\"operation\": \"create\",
\"backupPhrase\":[${mnemonics}],
\"assuranceLevel\": \"${ARGS[--assuranceLevel]}\",
\"name\": \"${ARGS[--name]}\"
}" | jq
fi
# restore
if [ "${ARGS[restore]}" == "true" ]; then
curl -kX POST https://localhost:${ARGS[--port]}/api/v1/wallets \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} \
-d "{
\"operation\": \"restore\",
\"backupPhrase\":[${mnemonics}],
\"assuranceLevel\": \"${ARGS[--assuranceLevel]}\",
\"name\": \"${ARGS[--name]}\"
}" | jq
fi
# delete
if [ "${ARGS[delete]}" == "true" ]; then
curl -kX DELETE https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]} \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} | jq
fi
# get
if [ "${ARGS[get]}" == "true" ]; then
curl -skX GET https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]} \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} | jq
fi
# create-account
if [ "${ARGS[create-account]}" == "true" ]; then
curl -kX POST https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]}/accounts \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} \
-d "{
\"name\": \"${ARGS[--name]}\"
}" | jq
fi
# get-accounts
if [ "${ARGS[get-accounts]}" == "true" ]; then
curl -kX GET https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]}/accounts \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} | jq
fi
# get-addresses
if [ "${ARGS[get-addresses]}" == "true" ]; then
curl -kX GET https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]}/accounts/${ARGS[--accountIndex]}/addresses \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} | jq
fi
# update
if [ "${ARGS[update]}" == "true" ]; then
curl -kX PUT https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]} \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} \
-d "{
\"assuranceLevel\": \"${ARGS[--assuranceLevel]}\",
\"name\": \"${ARGS[--name]}\"
}" | jq
fi
# utxo
if [ "${ARGS[utxo]}" == "true" ]; then
curl -skX GET https://localhost:${ARGS[--port]}/api/v1/wallets/${ARGS[<wallet_id>]}/statistics/utxos \
-H "Accept: application/json; charset=utf-8" \
-H "Content-Type: application/json; charset=utf-8" \
--cert ${ARGS[--client]} | jq
fi