forked from zigbee-alliance/distributed-compliance-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genlocalnetconfig.sh
executable file
·224 lines (167 loc) · 7.57 KB
/
genlocalnetconfig.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
# Copyright 2020 DSR Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
MAINNET_STABLE_VERSION="${1:-""}"
DCL_OBSERVERS="${DCL_OBSERVERS:-}"
LOCALNET_DIR=".localnet"
SED_EXT=
if [ "$(uname)" == "Darwin" ]; then
# Mac OS X sed needs the file extension when -i flag is used. Keeping it empty as we don't need backupfile
SED_EXT="''"
fi
DCL_DIR="$HOME/.dcl"
KEYPASSWD=test1234 # NOTE not necessary actually since we yse 'test' keyring backend now
CHAIN_ID=dclchain
DCL_BINARY=dcld
rm -rf "$DCL_DIR"
rm -rf "$LOCALNET_DIR"
mkdir "$LOCALNET_DIR" "$LOCALNET_DIR"/{client,node0,node1,node2,node3}
if [[ -n "$DCL_OBSERVERS" ]]; then
mkdir "$LOCALNET_DIR/observer0"
fi
if [ -n "$MAINNET_STABLE_VERSION" ]; then
wget "https://github.com/zigbee-alliance/distributed-compliance-ledger/releases/download/${MAINNET_STABLE_VERSION}/dcld"
chmod ugo+x dcld
mv dcld dcld_mainnet_stable
DCL_BINARY=./dcld_mainnet_stable
fi
# client
$DCL_BINARY config chain-id "$CHAIN_ID"
$DCL_BINARY config output json
$DCL_BINARY config node "tcp://localhost:26657"
$DCL_BINARY config keyring-backend test
$DCL_BINARY config broadcast-mode sync
(echo "$KEYPASSWD"; echo "$KEYPASSWD") | $DCL_BINARY keys add jack
(echo "$KEYPASSWD"; echo "$KEYPASSWD") | $DCL_BINARY keys add alice
(echo "$KEYPASSWD"; echo "$KEYPASSWD") | $DCL_BINARY keys add bob
(echo "$KEYPASSWD"; echo "$KEYPASSWD") | $DCL_BINARY keys add anna
# common keyring (client) data for all the nodes
# TODO issue 99: do we need all the keys on all the nodes
jack_address=$(echo "$KEYPASSWD" | $DCL_BINARY keys show jack -a)
jack_pubkey=$(echo "$KEYPASSWD" | $DCL_BINARY keys show jack -p)
alice_address=$(echo "$KEYPASSWD" | $DCL_BINARY keys show alice -a)
alice_pubkey=$(echo "$KEYPASSWD" | $DCL_BINARY keys show alice -p)
bob_address=$(echo "$KEYPASSWD" | $DCL_BINARY keys show bob -a)
bob_pubkey=$(echo "$KEYPASSWD" | $DCL_BINARY keys show bob -p)
anna_address=$(echo "$KEYPASSWD" | $DCL_BINARY keys show anna -a)
anna_pubkey=$(echo "$KEYPASSWD" | $DCL_BINARY keys show anna -p)
mv "$DCL_DIR"/* $LOCALNET_DIR/client
function add_genesis_accounts {
$DCL_BINARY add-genesis-account --address="$jack_address" --pubkey="$jack_pubkey" --roles="Trustee,NodeAdmin"
$DCL_BINARY add-genesis-account --address="$alice_address" --pubkey="$alice_pubkey" --roles="Trustee,NodeAdmin"
$DCL_BINARY add-genesis-account --address="$bob_address" --pubkey="$bob_pubkey" --roles="Trustee,NodeAdmin"
$DCL_BINARY add-genesis-account --address="$anna_address" --pubkey="$anna_pubkey" --roles="NodeAdmin"
}
function gentx {
local _node_name="$1"
local _key_name="$2"
echo "$KEYPASSWD" | $DCL_BINARY gentx "$_key_name" --chain-id "$CHAIN_ID" --moniker "$_node_name"
}
function init_node {
local _node_name="$1"
local _key_name="${2:-}"
local _copy_only="${3:-}"
$DCL_BINARY init "$_node_name" --chain-id "$CHAIN_ID"
cp -R "$LOCALNET_DIR"/client/* "$DCL_DIR"
# we need to make them in an app state for each node
add_genesis_accounts
if [[ -n "$_key_name" ]]; then
gentx "$_node_name" "$_key_name"
fi
if [[ -n "$_copy_only" ]]; then
cp -r "$DCL_DIR"/* "$LOCALNET_DIR/$_node_name"
else
mv "$DCL_DIR"/* "$LOCALNET_DIR/$_node_name"
fi
}
init_node node0 jack
init_node node1 alice
init_node node2 bob
init_node node3 anna yes
if [[ -d "$LOCALNET_DIR/observer0" ]]; then
rm -rf "$DCL_DIR"/*
init_node observer0 "" yes
fi
# Collect all validator creation transactions
mkdir -p "$DCL_DIR"/config/gentx
for node_name in node0 node1 node2 node3; do
cp "$LOCALNET_DIR/$node_name"/config/gentx/* "$DCL_DIR"/config/gentx
done
# Embed them into genesis
$DCL_BINARY collect-gentxs
$DCL_BINARY validate-genesis
# Update genesis for all nodes
cp "$DCL_DIR"/config/genesis.json "$LOCALNET_DIR"
cp "$DCL_DIR"/config/genesis.json "$LOCALNET_DIR"/client/config
for node_name in node0 node1 node2 node3; do
cp "$DCL_DIR"/config/genesis.json "$LOCALNET_DIR/$node_name/config/"
done
if [[ -d "$LOCALNET_DIR/observer0" ]]; then
cp "$DCL_DIR"/config/genesis.json "$LOCALNET_DIR/observer0/config/"
fi
# Find out node ids
id0=$(ls "$LOCALNET_DIR/node0/config/gentx" | sed 's/gentx-\(.*\).json/\1/')
id1=$(ls "$LOCALNET_DIR/node1/config/gentx" | sed 's/gentx-\(.*\).json/\1/')
id2=$(ls "$LOCALNET_DIR/node2/config/gentx" | sed 's/gentx-\(.*\).json/\1/')
id3=$(ls "$LOCALNET_DIR/node3/config/gentx" | sed 's/gentx-\(.*\).json/\1/')
# Update address book of the first node
peers="[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656"
echo "$peers" >"$LOCALNET_DIR"/persistent_peers.txt
# Update address book of the first node
sed -i $SED_EXT "s/persistent_peers = \"\"/persistent_peers = \"$peers\"/g" "$LOCALNET_DIR/node0/config/config.toml"
if [[ -d "$LOCALNET_DIR/observer0" ]]; then
sed -i $SED_EXT "s/persistent_peers = \"\"/persistent_peers = \"$peers\"/g" "$LOCALNET_DIR/observer0/config/config.toml"
fi
for node_name in node0 node1 node2 node3 observer0; do
if [[ -d "$LOCALNET_DIR/${node_name}" ]]; then
# Make RPC endpoints available externally
sed -i $SED_EXT 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/g' "$LOCALNET_DIR/${node_name}/config/config.toml"
# Make REST endpoints available externally
sed -i $SED_EXT 's/address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:1317"/g' "$LOCALNET_DIR/${node_name}/config/app.toml"
# Make REST endpoints available externally
sed -i $SED_EXT 's/address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:1317"/g' "$LOCALNET_DIR/${node_name}/config/app.toml"
# Make gRPC endpoints available externally
sed -i $SED_EXT 's/address = "localhost:9090"/address = "0.0.0.0:9090"/g' "$LOCALNET_DIR/${node_name}/config/app.toml"
# sets proper moniker
sed -i $SED_EXT "s/moniker = .*/moniker = \"$node_name\"/g" "$LOCALNET_DIR/${node_name}/config/config.toml"
# enables RPC and prometheus endpoints
# FIXME issue 99: not good code
sed -i $SED_EXT '0,/^enable = false/s~enable = false~enable = true~' "$LOCALNET_DIR/${node_name}/config/app.toml"
# enables prometheus endpoints
sed -i $SED_EXT 's/prometheus = false/prometheus = true/g' "$LOCALNET_DIR/${node_name}/config/config.toml"
fi
done
# Init Light CLient Proxy if needed DCL_LIGHT_CLIENT_PROXY=1
# DCL_LIGHT_CLIENT_PROXY="${DCL_LIGHT_CLIENT_PROXY:-}"
DCL_LIGHT_CLIENT_PROXY=1
function init_light_client_proxy {
local _node_name="$1"
rm -rf "$DCL_DIR"
$DCL_BINARY config chain-id "$CHAIN_ID"
$DCL_BINARY config node "tcp://localhost:26657"
$DCL_BINARY config broadcast-mode sync
$DCL_BINARY config keyring-backend test
$DCL_BINARY config broadcast-mode sync
cp -R "$LOCALNET_DIR"/client/* "$DCL_DIR"
cp -r "$DCL_DIR"/* "$LOCALNET_DIR/$_node_name"
}
if [[ -n "$DCL_LIGHT_CLIENT_PROXY" ]]; then
mkdir "$LOCALNET_DIR/lightclient0"
init_light_client_proxy lightclient0
fi
chmod 777 -R $DCL_DIR
#if [ -n "$MAINNET_STABLE_VERSION" ]; then
# rm dcld
#fi