blockchain/docker/tools/register-reserved.sh
Claude 56d7607754
Some checks are pending
Build & Release / Linux x86_64 (push) Waiting to run
Build & Release / macOS ARM64 (push) Waiting to run
Build & Release / Create Release (push) Blocked by required conditions
feat: mainnet name registration plan and batch tooling
90,041 names from HNS reserved list need pre-registering to prevent
squatting. Strategy: genesis seeds namereg wallets, staking funds the
rest, parallel wallets batch-register into multi-sig.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-03 14:46:52 +01:00

130 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
# Lethean Reserved Name Registrar
# Batch-registers protected aliases on the main chain to prevent squatting.
#
# Usage:
# bash register-reserved.sh [names-file] [wallet-rpc] [batch-size] [delay]
#
# Defaults:
# names-file: /tmp/protected-names-priority.txt
# wallet-rpc: http://127.0.0.1:46944/json_rpc
# batch-size: 10 (aliases per batch before checking balance)
# delay: 2 (seconds between registrations)
NAMES_FILE="${1:-/tmp/protected-names-priority.txt}"
WALLET_RPC="${2:-http://127.0.0.1:46944/json_rpc}"
BATCH_SIZE="${3:-10}"
DELAY="${4:-2}"
COMMENT="v=lthn1;type=reserved;reason=hns-protected"
LOG_FILE="/tmp/register-reserved.log"
DONE_FILE="/tmp/registered-names.txt"
touch "$DONE_FILE"
get_balance() {
curl -sf "$WALLET_RPC" -d '{"jsonrpc":"2.0","id":"0","method":"getbalance"}' \
-H 'Content-Type: application/json' | python3 -c "
import sys,json
d=json.load(sys.stdin)['result']
print(d['unlocked_balance'])
" 2>/dev/null
}
get_address() {
curl -sf "$WALLET_RPC" -d '{"jsonrpc":"2.0","id":"0","method":"getaddress"}' \
-H 'Content-Type: application/json' | python3 -c "
import sys,json
print(json.load(sys.stdin)['result']['address'])
" 2>/dev/null
}
register_alias() {
local name="$1"
local address="$2"
result=$(curl -sf "$WALLET_RPC" -d "{
\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"register_alias\",
\"params\":{
\"alias\":\"$name\",
\"address\":\"$address\",
\"comment\":\"$COMMENT\"
}
}" -H 'Content-Type: application/json' 2>/dev/null)
if echo "$result" | grep -q '"result"'; then
tx=$(echo "$result" | python3 -c "import sys,json; print(json.load(sys.stdin)['result'].get('tx_hash','ok'))" 2>/dev/null)
echo "$name" >> "$DONE_FILE"
echo "$(date +%H:%M:%S) OK @$name ($tx)" | tee -a "$LOG_FILE"
return 0
else
error=$(echo "$result" | python3 -c "import sys,json; print(json.load(sys.stdin).get('error',{}).get('message','unknown')[:80])" 2>/dev/null)
echo "$(date +%H:%M:%S) ERR @$name$error" | tee -a "$LOG_FILE"
return 1
fi
}
# Get wallet address
ADDRESS=$(get_address)
if [ -z "$ADDRESS" ]; then
echo "ERROR: Can't connect to wallet at $WALLET_RPC"
exit 1
fi
echo "Wallet: $ADDRESS"
echo "Names file: $NAMES_FILE ($(wc -l < "$NAMES_FILE") names)"
echo "Already registered: $(wc -l < "$DONE_FILE") names"
echo "Comment: $COMMENT"
echo "Batch: $BATCH_SIZE, Delay: ${DELAY}s"
echo "Log: $LOG_FILE"
echo "---"
BALANCE=$(get_balance)
BALANCE_LTHN=$(echo "scale=2; $BALANCE / 1000000000000" | bc 2>/dev/null)
echo "Balance: $BALANCE_LTHN LTHN"
echo ""
COUNT=0
REGISTERED=0
FAILED=0
SKIPPED=0
while IFS= read -r name; do
# Skip empty lines and comments
[[ -z "$name" || "$name" == \#* ]] && continue
# Skip already registered
if grep -qxF "$name" "$DONE_FILE" 2>/dev/null; then
((SKIPPED++))
continue
fi
# Check balance every batch
if (( COUNT % BATCH_SIZE == 0 && COUNT > 0 )); then
BALANCE=$(get_balance)
BALANCE_LTHN=$(echo "scale=2; $BALANCE / 1000000000000" | bc 2>/dev/null)
echo "--- Batch checkpoint: $BALANCE_LTHN LTHN, $REGISTERED registered, $FAILED failed ---"
# Stop if balance too low (need 1 LTHN + fee)
if (( BALANCE < 1100000000000 )); then
echo "Balance too low ($BALANCE_LTHN LTHN). Stopping."
break
fi
fi
register_alias "$name" "$ADDRESS"
if [ $? -eq 0 ]; then
((REGISTERED++))
else
((FAILED++))
fi
((COUNT++))
sleep "$DELAY"
done < "$NAMES_FILE"
echo ""
echo "=== Done ==="
echo "Registered: $REGISTERED"
echo "Failed: $FAILED"
echo "Skipped: $SKIPPED"
echo "Total processed: $COUNT"