forked from clams-tech/clams-app-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_rune.sh
executable file
·153 lines (131 loc) · 3.47 KB
/
get_rune.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
#!/bin/bash
set -eu
cd "$(dirname "$0")"
NODE_ID=
SESSION_ID=
READ_PERMISSIONS=false
PAY_PERMISSIONS=false
RECEIVE_PERMISSIONS=false
LIST_PAYS_PERMISSIONS=false
LIST_PRISMS_PERMISSIONS=false
CREATE_PRISM_PERMISSIONS=false
BKPR_PERMISSIONS=false
ADMIN_RUNE=false
RATE_LIMIT=60
# grab any modifications from the command line.
for i in "$@"; do
case $i in
--id=*)
NODE_ID="${i#*=}"
shift
;;
--session-id=*)
SESSION_ID="${i#*=}"
shift
;;
--read)
READ_PERMISSIONS=true
LIST_PAYS_PERMISSIONS=true
shift
;;
--list-pays)
LIST_PAYS_PERMISSIONS=true
shift
;;
--receive)
READ_PERMISSIONS=true
RECEIVE_PERMISSIONS=true
shift
;;
--bkpr)
BKPR_PERMISSIONS=true
shift
;;
--pay)
READ_PERMISSIONS=true
PAY_PERMISSIONS=true
shift
;;
--list-prisms)
LIST_PRISMS_PERMISSIONS=true
shift
;;
--create-prism)
LIST_PRISMS_PERMISSIONS=true
CREATE_PRISM_PERMISSIONS=true
shift
;;
--admin)
ADMIN_RUNE=true
shift
;;
*)
echo "Unexpected option: $1"
exit 1
;;
esac
done
. ./defaults.env
. ./load_env.sh
if [ -z "$NODE_ID" ]; then
echo "ERROR: You MUST specify a --node-id="
exit 1
fi
if [ "$BTC_CHAIN" = mainnet ]; then
RESPONSE=
read -r -p "WARNING: You are on mainnet. Are you sure you want to issue a new rune? " RESPONSE
if [ "$RESPONSE" != "y" ]; then
echo "STOPPING."
exit 1
fi
fi
RUNE_JSON=
# TODO fix this logic here.
if [ "$READ_PERMISSIONS" = false ] && \
[ "$PAY_PERMISSIONS" = false ] && \
[ "$LIST_PRISMS_PERMISSIONS" = false ] && \
[ "$LIST_PAYS_PERMISSIONS" = false ] && \
[ "$CREATE_PRISM_PERMISSIONS" = false ] && \
[ "$RECEIVE_PERMISSIONS" = false ] && \
[ "$BKPR_PERMISSIONS" = false ] && \
[ "$ADMIN_RUNE" = false ]; then
echo "ERROR: You MUST specify at least one permission."
exit 1
fi
CMD="./lightning-cli.sh --id=${NODE_ID} createrune"
if [ "$ADMIN_RUNE" = false ]; then
CMD="${CMD} restrictions='["
if [ -n "$SESSION_ID" ]; then
CMD="${CMD}[\"id=$SESSION_ID\"],"
fi
if [ "$READ_PERMISSIONS" = true ]; then
CMD="${CMD}[\"method/listdatastore\"],[\"method^list\",\"method^get\",\"method=waitanyinvoice\",\"method=waitinvoice\""
fi
if [ "$LIST_PAYS_PERMISSIONS" = true ]; then
CMD="${CMD},\"method=listpays\""
fi
if [ "$RECEIVE_PERMISSIONS" = true ]; then
CMD="${CMD},\"method=waitanyinvoice\",\"method=waitinvoice\",\"method=invoice\",\"method^offer\""
fi
if [ "$PAY_PERMISSIONS" = true ]; then
CMD="${CMD},\"method=pay\",\"method=fetchinvoice\",\"method=createinvoice\""
fi
if [ "$BKPR_PERMISSIONS" = true ]; then
CMD="${CMD},\"method~bkpr\""
fi
if [ "$LIST_PRISMS_PERMISSIONS" = true ]; then
CMD="${CMD},\"method=prism-listall\""
fi
if [ "$CREATE_PRISM_PERMISSIONS" = true ]; then
CMD="${CMD},\"method=prism-create\""
fi
CMD="${CMD}],[\"rate=$RATE_LIMIT\"]]'"
fi
CMD="${CMD//[,/[[}"
RUNE_JSON=$(eval "$CMD")
if [ -n "$RUNE_JSON" ]; then
echo "$RUNE_JSON" | jq -r '.rune'
else
echo "ERROR: the command did not complete."
exit 1
fi