172 lines
5.3 KiB
Bash
172 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
# RinCoin Solo Mining using Built-in Core Mining
|
|
# Uses RinCoin Core's generatetoaddress command
|
|
|
|
# Default address (can be overridden with command line parameter)
|
|
DEFAULT_ADDRESS="rin1qahvvv9d5f3443wtckeqavwp9950wacxfmwv20q"
|
|
|
|
# Get total CPU cores for default thread count
|
|
TOTAL_CORES=$(nproc)
|
|
DEFAULT_THREADS=$TOTAL_CORES
|
|
|
|
# Parse command line arguments
|
|
RIN_ADDRESS=""
|
|
THREAD_COUNT=""
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-a|--address)
|
|
RIN_ADDRESS="$2"
|
|
shift 2
|
|
;;
|
|
-t|--threads)
|
|
THREAD_COUNT="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -a, --address ADDRESS RinCoin address to mine to (default: $DEFAULT_ADDRESS)"
|
|
echo " -t, --threads COUNT Number of threads to use (default: $DEFAULT_THREADS)"
|
|
echo " -h, --help Show this help message"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 # Use defaults (all cores, default address)"
|
|
echo " $0 -a rin1q... -t 16 # Custom address and 16 threads"
|
|
echo " $0 --address rin1q... --threads 8 # Custom address and 8 threads"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Use -h or --help for usage information"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Set defaults if not provided
|
|
if [ -z "$RIN_ADDRESS" ]; then
|
|
RIN_ADDRESS="$DEFAULT_ADDRESS"
|
|
echo "No address provided, using default: $RIN_ADDRESS"
|
|
fi
|
|
|
|
if [ -z "$THREAD_COUNT" ]; then
|
|
THREAD_COUNT="$DEFAULT_THREADS"
|
|
echo "No thread count provided, using all cores: $THREAD_COUNT"
|
|
fi
|
|
|
|
# Validate thread count
|
|
if ! [[ "$THREAD_COUNT" =~ ^[0-9]+$ ]] || [ "$THREAD_COUNT" -lt 1 ] || [ "$THREAD_COUNT" -gt "$TOTAL_CORES" ]; then
|
|
echo "❌ Error: Invalid thread count: $THREAD_COUNT"
|
|
echo "Thread count must be between 1 and $TOTAL_CORES"
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== RinCoin Solo Mining (Built-in Core Mining) ==="
|
|
echo "CPU Cores Available: $TOTAL_CORES"
|
|
echo "Threads to Use: $THREAD_COUNT"
|
|
echo "Target Address: $RIN_ADDRESS"
|
|
echo ""
|
|
echo ""
|
|
|
|
# Configuration
|
|
RPC_HOST="127.0.0.1"
|
|
RPC_PORT="9556"
|
|
RPC_USER="rinrpc"
|
|
RPC_PASS="745ce784d5d537fc06105a1b935b7657903cfc71a5fb3b90"
|
|
|
|
# Function to call RPC
|
|
call_rpc() {
|
|
local method="$1"
|
|
local params="$2"
|
|
|
|
curl -s --user "$RPC_USER:$RPC_PASS" \
|
|
-H 'content-type: text/plain' \
|
|
--data "{\"jsonrpc\":\"1.0\",\"id\":\"curl\",\"method\":\"$method\",\"params\":$params}" \
|
|
"http://$RPC_HOST:$RPC_PORT/"
|
|
}
|
|
|
|
# Wait for node to be ready
|
|
echo "Waiting for RinCoin node to be ready..."
|
|
while true; do
|
|
response=$(call_rpc "getblockchaininfo" "[]")
|
|
if [[ $response != *"Loading block index"* ]]; then
|
|
break
|
|
fi
|
|
echo "Node still loading... waiting 10 seconds"
|
|
sleep 10
|
|
done
|
|
|
|
echo "✅ Node is ready!"
|
|
echo ""
|
|
|
|
# Load wallet if not already loaded
|
|
echo "Loading wallet..."
|
|
wallet_response=$(call_rpc "loadwallet" "[\"main\"]")
|
|
if [[ $wallet_response == *"error"* ]] && [[ $wallet_response == *"already loaded"* ]]; then
|
|
echo "✅ Wallet already loaded"
|
|
else
|
|
echo "✅ Wallet loaded successfully"
|
|
fi
|
|
echo ""
|
|
|
|
# Validate the provided address (basic check)
|
|
if [[ ! "$RIN_ADDRESS" =~ ^rin1[a-zA-Z0-9]{25,}$ ]]; then
|
|
echo "❌ Error: Invalid RinCoin address format: $RIN_ADDRESS"
|
|
echo "RinCoin addresses should start with 'rin1' and be ~30 characters long"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Using RinCoin Address: $RIN_ADDRESS"
|
|
echo ""
|
|
|
|
# Get blockchain info
|
|
echo "Blockchain Status:"
|
|
blockchain_info=$(call_rpc "getblockchaininfo" "[]")
|
|
blocks=$(echo "$blockchain_info" | grep -o '"blocks":[^,]*' | cut -d':' -f2)
|
|
headers=$(echo "$blockchain_info" | grep -o '"headers":[^,]*' | cut -d':' -f2)
|
|
difficulty=$(echo "$blockchain_info" | grep -o '"difficulty":[^,]*' | cut -d':' -f2)
|
|
|
|
echo "Blocks: $blocks"
|
|
echo "Headers: $headers"
|
|
echo "Difficulty: $difficulty"
|
|
echo ""
|
|
|
|
echo "⚠️ IMPORTANT: Built-in Core Mining Limitations:"
|
|
echo "1. Uses CPU only (not GPU)"
|
|
echo "2. Very low hashpower compared to specialized miners"
|
|
echo "3. Extremely low chance of finding blocks solo"
|
|
echo "4. Best for testing, not profitable mining"
|
|
echo "5. Thread count affects mining attempts per cycle"
|
|
echo ""
|
|
|
|
echo "🚀 Starting Built-in Solo Mining..."
|
|
echo "Target Address: $RIN_ADDRESS"
|
|
echo "Threads: $THREAD_COUNT"
|
|
echo "Press Ctrl+C to stop mining"
|
|
echo ""
|
|
|
|
# Start built-in mining with specified thread count
|
|
# Note: RinCoin Core's generatetoaddress doesn't directly support thread count
|
|
# but we can run multiple instances or adjust the maxtries parameter
|
|
while true; do
|
|
echo "Attempting to mine 1 block with $THREAD_COUNT threads..."
|
|
|
|
# Adjust maxtries based on thread count for better distribution
|
|
adjusted_tries=$((1000000 * THREAD_COUNT / TOTAL_CORES))
|
|
|
|
mining_result=$(call_rpc "generatetoaddress" "[1, \"$RIN_ADDRESS\", $adjusted_tries]")
|
|
|
|
if [[ $mining_result == *"result"* ]] && [[ $mining_result != *"[]"* ]]; then
|
|
echo "🎉 BLOCK FOUND!"
|
|
echo "Result: $mining_result"
|
|
break
|
|
else
|
|
echo "No block found in this attempt (tries: $adjusted_tries). Retrying..."
|
|
sleep 5
|
|
fi
|
|
done
|