forked from nxtmeta/go-nxtmeta
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathgen-config.sh
More file actions
executable file
·79 lines (67 loc) · 2.44 KB
/
gen-config.sh
File metadata and controls
executable file
·79 lines (67 loc) · 2.44 KB
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
#!/bin/bash
# Check required arguments
if [ "$#" -ne 4 ]; then
echo "Usage: $0 -a <node_num> -f <output_config_file>"
exit 1
fi
# Option parsing
while getopts "a:f:" opt; do
case ${opt} in
a)
NODE_NUM=$OPTARG
;;
f)
OUTPUT_CONFIG_FILE=$OPTARG
;;
\?)
echo "Usage: $0 -a <node_num> -f <output_config_file>"
exit 1
;;
esac
done
# Check required arguments
if [ -z "$NODE_NUM" ] || [ -z "$OUTPUT_CONFIG_FILE" ]; then
exit 1
fi
# Initialize
echo '{"members":[], "accounts":[]}' >"$OUTPUT_CONFIG_FILE"
# Load file as JSON
json_content=$(cat "$OUTPUT_CONFIG_FILE")
# JSON object with fixed env values
ENV_JSON='{
"ballotDurationMin": 86400,
"ballotDurationMax": 604800,
"stakingMin": 1500000000000000000000000,
"stakingMax": 1500000000000000000000000,
"MaxIdleBlockInterval": 100,
"blockCreationTime": 5000,
"blockRewardAmount": 1000000000000000000,
"maxPriorityFeePerGas": 100000000000,
"rewardDistributionMethod": [4000, 1000, 2500, 2500],
"maxBaseFee": 50000000000000,
"blockGasLimit": 105000000,
"baseFeeMaxChangeRate": 55,
"gasTargetPercentage": 30
}'
json_content=$(echo "$json_content" | jq --argjson env "$ENV_JSON" \
'.env = $env| .extraData = "chain for local test"')
# Generate JSON config file
for ((i = 1; i <= NODE_NUM; i++)); do
ids=$(gwemix wemix nodeid local-docker-env/nodekey/nodekey$i) || { echo "Failed to get node ID"; exit 1; }
idv5=$(echo "$ids" | awk '/idv5:/ {print $2}')
idv5="0x$idv5"
ip="172.16.237.$((i+10))"
address=$(jq -r '.address' "local-docker-env/keystore/account$i") || { echo "Failed to get address"; exit 1; }
address="0x$address"
name="localtest$i"
json_content=$(echo "$json_content" | jq --arg addr "$address" --arg name "$name" --arg id "$idv5" --arg ip "$ip" --argjson index $((i - 1)) \
'.members += [{"addr": $addr, "stake": 1500000000000000000000000, "name": $name, "id": $id, "ip": $ip, "port": 8589, "bootnode": false}]
| .accounts += [{"addr": $addr, "balance": 2000000000000000000000000}]') || { echo "Failed to update JSON content"; exit 1; }
if [ $i -eq 1 ]; then
json_content=$(echo "$json_content" | jq --arg addr "$address" \
'.staker = $addr | .ecosystem = $addr | .maintanence = $addr | .feecollector = $addr | .members[0].bootnode = true') || { echo "Failed to update JSON content"; exit 1; }
fi
done
# Save modified content to file
echo "$json_content" >"$OUTPUT_CONFIG_FILE"
echo "Updated config saved to $OUTPUT_CONFIG_FILE"