-
Notifications
You must be signed in to change notification settings - Fork 0
/
mine.sh
71 lines (60 loc) · 1.71 KB
/
mine.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
#!/usr/bin/env bash
set -euo pipefail
# Configuration
DEFAULT_TIME=2
RPC_URL=("https://api.mainnet-beta.solana.com" "")
DEFAULT_KEY="$HOME/.config/solana/id.json"
# Function to log messages
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Function to trim whitespace
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}"
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
# Function to check if a command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Function to get a random URL from a list
get_random_rpc_url() {
if command_exists shuf; then
shuf -n1 -e "$@"
else
local urls=("$@")
echo "${urls[RANDOM % ${#urls[@]}]}"
fi
}
# Function to execute command and handle failures
execute_command() {
local rpc_url="$1" key="$2" time="$3"
local command=(ore --rpc "$rpc_url" --keypair "$key" mine --buffer-time "$time")
while true; do
log "Starting the process with RPC: $rpc_url"
log "Executing command: ${command[*]}"
if "${command[@]}"; then
log "Process completed."
break
else
log "Process exited with error $?; retrying in 5 seconds..."
sleep 5
fi
done
}
# Check for ore command
command_exists ore || { log "ore not found."; exit 1; }
# Remove empty RPC URLs
RPC_URLs=()
for url in "${RPC_URL[@]}"; do
[[ -n "$url" ]] && RPC_URLs+=("$url")
done
[[ ${#RPC_URLs[@]} -gt 0 ]] || { log "No valid RPC_URL found in config."; exit 1; }
# Parse command line arguments
RPC_URL=${1:-$(get_random_rpc_url "${RPC_URLs[@]}")}
KEY=${2:-$DEFAULT_KEY}
TIME=${3:-$DEFAULT_TIME}
# Execute the main function
execute_command "$RPC_URL" "$KEY" "$TIME"