-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_nemesis_block.sh
115 lines (93 loc) · 4.34 KB
/
prepare_nemesis_block.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
#!/bin/zsh
# generates the nemesis block properties file and nemesis block
local catapult_server_src=$1
local local_path=$PWD
local nemesis_signer_key=$2
local generation_hash=$3
local nemesis_path="/nemesis/nemesis-block.properties"
local harvester_keys_path="harvester_addresses.txt"
local currency_keys_path="currency_addresses.txt"
### From catapult-service-bootstrap
config_form() {
local split=$(echo $1 | sed 's/\(.\)/\1 /g')
local concat=$(printf "%c%c%c%c'" $(echo $split))
echo "0x$concat[1,-2]"
}
function generate_addresses() {
local network=$1
local no_of_keys=$2
local dest_path=$3
echo "generating addresses"
${catapult_server_src}/bin/catapult.tools.address -n "${network}" -g "${no_of_keys}" > "${dest_path}"
}
function run_sed() {
local filename="$1.properties"
echo "updating properties file"
for key value in ${(kv)${(P)2}}; do
sed -i "s#$key =.*#$key = $value#;" ${local_path}${nemesis_path}
done
}
function sed_keys() {
sed -i -e "/\[$1\]/,/^\[/ s/$2/$3/g" ${local_path}${nemesis_path}
}
function update_nemesis_block_file() {
cp "${catapult_server_src}/scripts/cat-config/nemgen/resources/mijin-test.properties" ${local_path}${nemesis_path}
local -A nemesis_pairs=(
"cppFile" ""
"nemesisGenerationHash" "$generation_hash"
"nemesisSignerPrivateKey" "$nemesis_signer_key"
"binDirectory" "${local_path}/seed")
run_sed "nemesis-block" nemesis_pairs
update_keys
}
function update_keys() {
generate_addresses mijin-test 23 ${currency_keys_path}
generate_addresses mijin-test 11 ${harvester_keys_path}
if [[ ! -a $harvester_keys_path ]] then;
echo "addresses file not generated"
return 0;
fi
local new_harvester_addresses=( $(grep S $harvester_keys_path | sed -e 's/address (mijin-test)://g') )
local old_harvester_addresses=( $(grep -i -A12 "\bdistribution>cat:harvest\b" "${local_path}${nemesis_path}" | grep -o -e "^S.\{40\}") )
local new_currency_addresses=( $(grep S $currency_keys_path | sed -e 's/address (mijin-test)://g') )
local old_currency_addresses=( $(grep -i -A24 "\bdistribution>cat:currency\b" "${local_path}${nemesis_path}" | grep -o -e "^S.\{40\}") )
## replace the harvester addresses
for i in {1..11}
do
sed_keys "distribution>cat:harvest" $old_harvester_addresses[$i] $new_harvester_addresses[$i]
done
## then replace the currency addresses
for i in {1..22}
do
sed_keys "distribution>cat:currency" $old_currency_addresses[$i] $new_currency_addresses[$i]
done
}
function nemgen() {
update_nemesis_block_file
######## Nemgen script from catapult-service-bootstrap@https://github.com/tech-bureau/catapult-service-bootstrap
if [ ! -d $local_path/data ]; then
echo "/data directory does not exist"
exit 1
fi
if [ ! -d $local_path/data/00000 ]; then
echo "running nemgen"
mkdir settings
mkdir -p ${local_path}/seed/00000
dd if=/dev/zero of=${local_path}/seed/00000/hashes.dat bs=1 count=64
cd settings
######## need to run twice and patch the mosaic ids
# first time to get cat.harvest and cat.currency
${catapult_server_src}/bin/catapult.tools.nemgen --resources $local_path --nemesisProperties "${local_path}${nemesis_path}" 2> $local_path/tmp/nemgen.log
local harvesting_mosaic_id=$(grep "cat.harvest" $local_path/tmp/nemgen.log | grep nonce | awk -F= '{split($0, a, / /); print a[9]}' | sort -u)
local currency_mosaic_id=$(grep "cat.currency" $local_path/tmp/nemgen.log | grep nonce | awk -F= '{split($0, a, / /); print a[9]}' | sort -u)
# second time after replacing values for currencyMosaicId and harvestingMosaicId
sed -i "s/^currencyMosaicId .*/currencyMosaicId = "$(config_form ${currency_mosaic_id})"/" ${local_path}/resources/config-network.properties
sed -i "s/^harvestingMosaicId .*/harvestingMosaicId = "$(config_form ${harvesting_mosaic_id})"/" ${local_path}/resources/config-network.properties
${catapult_server_src}/bin/catapult.tools.nemgen --resources $local_path --nemesisProperties "${local_path}${nemesis_path}" 2> $local_path/tmp/nemgen2.log
cp -r ${local_path}/seed/* ${local_path}/data/
cd ..
else
echo "no need to run nemgen"
fi
}
nemgen