-
Notifications
You must be signed in to change notification settings - Fork 4
/
validator.sh
executable file
·67 lines (53 loc) · 1.68 KB
/
validator.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
#!/bin/bash
# Initialize variables
PRIVATE_KEY=""
ETH_RPC_ENDPOINT=""
EVIL_MODE=false
CONFIG_FILE="validator_config.json" # Specify your JSON config file name
# Function to show usage
usage() {
echo "Usage: $0 --private-key <private-key> --eth-rpc-endpoint <eth-rpc-endpoint> [--evil]"
exit 1
}
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--private-key) PRIVATE_KEY="$2"; shift ;;
--eth-rpc-endpoint) ETH_RPC_ENDPOINT="$2"; shift ;;
--evil) EVIL_MODE=true ;;
*) usage ;;
esac
shift
done
# Check required arguments
if [[ -z "$PRIVATE_KEY" ]] || [[ -z "$ETH_RPC_ENDPOINT" ]]; then
usage
fi
# Define the directory based on mode
VALIDATOR_DIR="honest-validator"
if [ "$EVIL_MODE" = true ]; then
VALIDATOR_DIR="evil-validator"
CONFIG_FILE="evil_validator_config.json"
fi
# Change to the validator directory
cd "$VALIDATOR_DIR"
# Edit the JSON configuration file
jq --arg pk "$PRIVATE_KEY" --arg ep "$ETH_RPC_ENDPOINT" \
'.node.staker.["parent-chain-wallet"]."private-key" = $pk |
.["parent-chain"].connection.url = $ep' "$CONFIG_FILE" > tmp.$$ && mv tmp.$$ "$CONFIG_FILE"
# Verify that the JSON file was edited
if [ $? -ne 0 ]; then
echo "Error: Failed to update $CONFIG_FILE"
exit 1
fi
# Stop all running containers before deleting volumes
docker-compose down
# docker volume rm $(docker volume ls -q | grep "${VALIDATOR_DIR}") 2>/dev/null
# Start up the services with docker-compose
echo "Validator ($VALIDATOR_DIR) is now starting."
docker-compose up -d && docker-compose logs -f
# Check if docker-compose started correctly
if [ $? -ne 0 ]; then
echo "Error: docker-compose up failed"
exit 1
fi