refactor: organize scripts/, remove stale root dirs, clean up structure

scripts/ reorganization:
- Sort 14 loose root scripts into subfolders:
  blockchain/ (genesis, proposer, mock chain, testnet BTC)
  dev/ (CLI wrapper, dev services, OpenAPI gen, systemd setup, domain proxy)
  ops/ (coordinator proxy, remote tunnel)
  gpu/ (miner workflow)
- Merge scripts/testing/ into scripts/test/ (eliminate duplicate folder)
- Create scripts/examples/ for usage demos and simulations

Root-level cleanup:
- Move home/ (12 simulation scripts) → scripts/examples/
- Move dev-utils/ (2 files) → scripts/dev/
- Move protocols/receipts/sample → tests/fixtures/
- Delete stale src/ (duplicate of apps/blockchain-node/src/)
- Remove empty home/, dev-utils/, protocols/ directories

Documentation updates:
- Update docs/6_architecture/8_codebase-structure.md tree and table
- Update root README.md tree to reflect new structure
This commit is contained in:
oib
2026-02-13 23:26:53 +01:00
parent 76078221cb
commit 3b4cc69179
47 changed files with 20 additions and 417 deletions

View File

@@ -0,0 +1,43 @@
#!/bin/bash
echo "=== AITBC Bootstrap Genesis Setup ==="
echo ""
# Stop the blockchain node
echo "1. Stopping blockchain node..."
sudo systemctl stop aitbc-node
# Backup current data
echo "2. Backing up current blockchain data..."
sudo mv /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite.backup.$(date +%s) 2>/dev/null || true
# Copy new genesis
echo "3. Applying bootstrap genesis..."
sudo cp /root/aitbc/apps/blockchain-node/data/genesis_with_bootstrap.json /root/aitbc/apps/blockchain-node/data/devnet/genesis.json
# Reset database
echo "4. Resetting blockchain database..."
sudo rm -f /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite
# Restart blockchain node
echo "5. Restarting blockchain node..."
sudo systemctl start aitbc-node
# Wait for node to start
echo "6. Waiting for node to initialize..."
sleep 5
# Verify treasury balance
echo "7. Verifying treasury balance..."
curl -s http://localhost:9080/rpc/getBalance/aitbcexchange00000000000000000000000000000000 | jq
echo ""
echo "=== Bootstrap Complete! ==="
echo "Treasury should now have 10,000,000 AITBC"
echo ""
echo "Initial Distribution:"
echo "- Exchange Treasury: 10,000,000 AITBC (47.6%)"
echo "- Community Faucet: 1,000,000 AITBC (4.8%)"
echo "- Team Fund: 2,000,000 AITBC (9.5%)"
echo "- Early Investors: 5,000,000 AITBC (23.8%)"
echo "- Ecosystem Fund: 3,000,000 AITBC (14.3%)"

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""
Script to assign a proposer to a block by polling for it
"""
import httpx
import json
# Configuration
COORDINATOR_URL = "http://localhost:8001"
MINER_API_KEY = "${MINER_API_KEY}"
MINER_ID = "localhost-gpu-miner"
def assign_proposer_to_latest_block():
"""Poll for the latest unassigned job to become the proposer"""
# First register the miner
print("📝 Registering miner...")
register_response = httpx.post(
f"{COORDINATOR_URL}/v1/miners/register?miner_id={MINER_ID}",
headers={
"Content-Type": "application/json",
"X-Api-Key": MINER_API_KEY
},
json={
"capabilities": {
"gpu": {"model": "RTX 4060 Ti", "memory_gb": 16}
}
}
)
if register_response.status_code != 200:
print(f"❌ Registration failed: {register_response.text}")
return
print("✅ Miner registered")
# Poll for a job
print("\n🔍 Polling for jobs...")
poll_response = httpx.post(
f"{COORDINATOR_URL}/v1/miners/poll",
headers={
"Content-Type": "application/json",
"X-Api-Key": MINER_API_KEY
},
json={"max_wait_seconds": 1}
)
if poll_response.status_code == 200:
job = poll_response.json()
print(f"✅ Received job: {job['job_id']}")
print(f" This job is now assigned to miner: {MINER_ID}")
# Check the block
print("\n📦 Checking block...")
blocks_response = httpx.get(f"{COORDINATOR_URL}/v1/explorer/blocks")
if blocks_response.status_code == 200:
blocks = blocks_response.json()
for block in blocks['items']:
if block['hash'] == job['job_id']:
print(f"✅ Block updated!")
print(f" Height: {block['height']}")
print(f" Hash: {block['hash']}")
print(f" Proposer: {block['proposer']}")
break
elif poll_response.status_code == 204:
print(" No jobs available to poll")
else:
print(f"❌ Poll failed: {poll_response.text}")
if __name__ == "__main__":
print("🎯 Assign Proposer to Latest Block")
print("=" * 40)
assign_proposer_to_latest_block()

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Script to return testnet Bitcoin
RETURN_ADDRESS="tb1qerzrlxcfu24davlur5sqmgzzgsal6wusda40er"
echo "Checking balance..."
BALANCE=$(bitcoin-cli -testnet -rpcwallet=aitbc_exchange getbalance)
if [ "$(echo "$BALANCE > 0" | bc)" -eq 1 ]; then
echo "Current balance: $BALANCE BTC"
echo "Sending to return address: $RETURN_ADDRESS"
# Calculate amount to send (balance minus small fee)
SEND_AMOUNT=$(echo "$BALANCE - 0.00001" | bc)
TXID=$(bitcoin-cli -testnet -rpcwallet=aitbc_exchange sendtoaddress "$RETURN_ADDRESS" "$SEND_AMOUNT")
echo "Transaction sent! TXID: $TXID"
echo "Explorer: https://blockstream.info/testnet/tx/$TXID"
else
echo "No Bitcoin to return. Current balance: $BALANCE BTC"
fi

View File

@@ -0,0 +1,87 @@
#!/bin/bash
# Start mock blockchain nodes for testing
# This script sets up the required mock servers on ports 8081 and 8082
set -e
echo "🚀 Starting Mock Blockchain Nodes for Testing"
echo "============================================="
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
# Check if required ports are available
check_port() {
local port=$1
if curl -s "http://127.0.0.1:$port/health" >/dev/null 2>&1; then
print_warning "Port $port is already in use"
return 1
fi
return 0
}
# Stop any existing mock servers
stop_existing_servers() {
print_status "Stopping existing mock servers..."
pkill -f "mock_blockchain_node.py" 2>/dev/null || true
sleep 1
}
# Start mock servers
start_mock_servers() {
print_status "Starting mock blockchain node on port 8081..."
cd "$(dirname "$0")/.."
python3 tests/mock_blockchain_node.py 8081 > /tmp/mock_node_8081.log 2>&1 &
local pid1=$!
print_status "Starting mock blockchain node on port 8082..."
python3 tests/mock_blockchain_node.py 8082 > /tmp/mock_node_8082.log 2>&1 &
local pid2=$!
# Wait for servers to start
sleep 2
# Verify servers are running
if curl -s "http://127.0.0.1:8081/health" >/dev/null 2>&1 && \
curl -s "http://127.0.0.1:8082/health" >/dev/null 2>&1; then
print_status "✅ Mock blockchain nodes are running!"
echo ""
echo "Node 1: http://127.0.0.1:8082"
echo "Node 2: http://127.0.0.1:8081"
echo ""
echo "To run tests:"
echo " python -m pytest tests/test_blockchain_nodes.py -v"
echo ""
echo "To stop servers:"
echo " pkill -f 'mock_blockchain_node.py'"
echo ""
echo "Log files:"
echo " Node 1: /tmp/mock_node_8082.log"
echo " Node 2: /tmp/mock_node_8081.log"
else
print_warning "❌ Failed to start mock servers"
echo "Check log files:"
echo " Node 1: /tmp/mock_node_8082.log"
echo " Node 2: /tmp/mock_node_8081.log"
exit 1
fi
}
# Main execution
main() {
stop_existing_servers
start_mock_servers
}
# Run main function
main "$@"