-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathlocalnet.sh
More file actions
126 lines (105 loc) · 4.51 KB
/
Copy pathlocalnet.sh
File metadata and controls
126 lines (105 loc) · 4.51 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
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
#!/bin/bash
echo_info () {
echo "${blue}"
echo "$1"
echo "${reset}"
}
echo_error () {
echo "${red}"
echo "$1"
echo "${reset}"
}
echo_success () {
echo "${green}"
echo "$1"
echo "${reset}"
}
# Set localnet settings
if [[ -f "build/archwayd" ]] ;then
BINARY=build/archwayd
# Console log text colour
red=`tput setaf 9`
green=`tput setaf 10`
blue=`tput setaf 12`
reset=`tput sgr0`
else
BINARY=archwayd
fi
CHAIN_ID=localnet-1
CHAIN_DIR=./data
VALIDATOR_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
DEVELOPER_MNEMONIC="friend excite rough reopen cover wheel spoon convince island path clean monkey play snow number walnut pull lock shoot hurry dream divide concert discover"
USER_MNEMONIC="any giant turtle pioneer frequent frown harvest ancient episode junior vocal rent shrimp icon idle echo suspect clean cage eternal sample post heavy enough"
GENESIS_COINS=1000000000000000000000000000000000000stake
setup_chain () {
# Stop archwayd if it is already running
if pgrep -x "$BINARY" >/dev/null; then
echo_error "Terminating $BINARY..."
killall archwayd
fi
# Remove previous data
echo_info "Removing previous chain data from $CHAIN_DIR/$CHAIN_ID..."
rm -rf $CHAIN_DIR/$CHAIN_ID
# Initialize archwayd with "localnet-1" chain id
echo_info "Initializing $CHAIN_ID..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID init test --chain-id=$CHAIN_ID; then
echo_success "Successfully initialized $CHAIN_ID"
else
echo_error "Failed to initialize $CHAIN_ID"
fi
# Modify config for development
config="$CHAIN_DIR/$CHAIN_ID/config/config.toml"
if [ "$(uname)" = "Linux" ]; then
sed -i "s/127.0.0.1/0.0.0.0/g" $config
sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config
else
sed -i '' "s/127.0.0.1/0.0.0.0/g" $config
sed -i '' "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config
fi
# modify genesis params for localnet ease of use
genesis="$CHAIN_DIR/$CHAIN_ID/config/genesis.json"
# x/gov params change
# reduce voting period to 2 minutes
contents="$(jq '.app_state.gov.voting_params.voting_period = "120s"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov voting period to 120 seconds"
# reduce minimum deposit amount to 10stake
contents="$(jq '.app_state.gov.deposit_params.min_deposit[0].amount = "10"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov proposal min deposit amount to 10 stake"
# reduce deposit period to 20seconds
contents="$(jq '.app_state.gov.deposit_params.max_deposit_period = "20s"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov proposal max deposit period to 20 seconds"
# Adding users
echo_info "Adding genesis accounts..."
echo_info "1. validator"
echo $VALIDATOR_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add validator --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show validator --keyring-backend test -a) $GENESIS_COINS
echo_info "2. developer"
echo $DEVELOPER_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add developer --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show developer --keyring-backend test -a) $GENESIS_COINS
echo_info "3. user"
echo $USER_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add user --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show user --keyring-backend test -a) $GENESIS_COINS
# Creating gentx
echo_info "Creating gentx for validator..."
$BINARY --home $CHAIN_DIR/$CHAIN_ID gentx validator 100000000000000000000000stake --chain-id $CHAIN_ID --fees 950000000000000000000stake --keyring-backend test
# Collecting gentx
echo_info "Collecting gentx..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi
# Validating genesis
echo_info "Validating genesis..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID validate-genesis; then
echo_success "Successfully validated genesis"
else
echo_error "Failed to validate genesis"
fi
}
if [ "$1" != "continue" ] ;then
setup_chain
fi
# Starting chain
echo_info "Starting chain..."
$BINARY --home $CHAIN_DIR/$CHAIN_ID start