forked from sagnik/Project_Astral
73 lines
1.9 KiB
Bash
73 lines
1.9 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
DATADIR="/chain_data"
|
|
KEYSTORE="/keystore"
|
|
PASSWORD_FILE="/password.txt"
|
|
SEALER_KEY_FILE="/keys/sealer.key"
|
|
PREFUNDED_KEY_FILE="/keys/prefunded.key"
|
|
SEALER_ADDRESS_FILE="$KEYSTORE/sealer.address"
|
|
PREFUNDED_ADDRESS_FILE="$KEYSTORE/prefunded.address"
|
|
GENESIS_FILE="/genesis.json"
|
|
|
|
mkdir -p "$DATADIR" "$KEYSTORE"
|
|
|
|
extract_address() {
|
|
sed -n 's/.*{\([0-9a-fA-F]\{40\}\)}.*/0x\1/p' | tail -n 1
|
|
}
|
|
|
|
import_key_if_needed() {
|
|
KEY_FILE="$1"
|
|
ADDRESS_FILE="$2"
|
|
|
|
if [ -f "$ADDRESS_FILE" ]; then
|
|
cat "$ADDRESS_FILE"
|
|
return 0
|
|
fi
|
|
|
|
ADDRESS="$(geth account import --keystore "$KEYSTORE" --password "$PASSWORD_FILE" "$KEY_FILE" 2>&1 | extract_address)"
|
|
|
|
if [ -z "$ADDRESS" ]; then
|
|
echo "Failed to import key from $KEY_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "$ADDRESS" > "$ADDRESS_FILE"
|
|
echo "$ADDRESS"
|
|
}
|
|
|
|
if [ ! -f "$PASSWORD_FILE" ]; then
|
|
echo "Missing password file: $PASSWORD_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SEALER_ADDRESS="$(import_key_if_needed "$SEALER_KEY_FILE" "$SEALER_ADDRESS_FILE")"
|
|
PREFUNDED_ADDRESS="$(import_key_if_needed "$PREFUNDED_KEY_FILE" "$PREFUNDED_ADDRESS_FILE")"
|
|
|
|
if [ ! -d "$DATADIR/geth" ]; then
|
|
echo "No chain state found at $DATADIR/geth; generating genesis and initializing..."
|
|
sh /generate-genesis.sh "$SEALER_ADDRESS" "$PREFUNDED_ADDRESS" "$GENESIS_FILE"
|
|
geth init --datadir "$DATADIR" "$GENESIS_FILE"
|
|
else
|
|
echo "Existing chain state detected at $DATADIR/geth; skipping genesis generation and geth init."
|
|
fi
|
|
|
|
echo "Starting Geth on network 1999"
|
|
exec geth \
|
|
--datadir "$DATADIR" \
|
|
--keystore "$KEYSTORE" \
|
|
--networkid 1999 \
|
|
--http \
|
|
--http.addr 0.0.0.0 \
|
|
--http.port 8545 \
|
|
--http.api eth,net,web3,personal,txpool,miner,clique \
|
|
--http.corsdomain "*" \
|
|
--http.vhosts "*" \
|
|
--port 30303 \
|
|
--allow-insecure-unlock \
|
|
--unlock "$SEALER_ADDRESS,$PREFUNDED_ADDRESS" \
|
|
--password "$PASSWORD_FILE" \
|
|
--mine \
|
|
--miner.etherbase "$SEALER_ADDRESS" \
|
|
--ipcdisable
|