chore: enhance .gitignore and remove obsolete documentation files

- Reorganize .gitignore with categorized sections for better maintainability
- Add comprehensive ignore patterns for Python, Node.js, databases, logs, and build artifacts
- Add project-specific ignore rules for coordinator, explorer, and deployment files
- Remove outdated documentation: BITCOIN-WALLET-SETUP.md, LOCAL_ASSETS_SUMMARY.md, README-CONTAINER-DEPLOYMENT.md, README-DOMAIN-DEPLOYMENT.md
```
This commit is contained in:
oib
2026-01-24 14:44:51 +01:00
parent 99bf335970
commit 9b9c5beb23
214 changed files with 25558 additions and 171 deletions

View File

@@ -0,0 +1,164 @@
#!/usr/bin/env python3
"""Migration script for Wallet Daemon from SQLite to PostgreSQL"""
import os
import sys
from pathlib import Path
import sqlite3
import psycopg2
from psycopg2.extras import RealDictCursor
from datetime import datetime
import json
# Database configurations
SQLITE_DB = "data/wallet_ledger.db"
PG_CONFIG = {
"host": "localhost",
"database": "aitbc_wallet",
"user": "aitbc_user",
"password": "aitbc_password",
"port": 5432
}
def create_pg_schema():
"""Create PostgreSQL schema with optimized types"""
conn = psycopg2.connect(**PG_CONFIG)
cursor = conn.cursor()
print("Creating PostgreSQL schema...")
# Drop existing tables
cursor.execute("DROP TABLE IF EXISTS wallet_events CASCADE")
cursor.execute("DROP TABLE IF EXISTS wallets CASCADE")
# Create wallets table
cursor.execute("""
CREATE TABLE wallets (
wallet_id VARCHAR(255) PRIMARY KEY,
public_key TEXT,
metadata JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
)
""")
# Create wallet_events table
cursor.execute("""
CREATE TABLE wallet_events (
id SERIAL PRIMARY KEY,
wallet_id VARCHAR(255) REFERENCES wallets(wallet_id) ON DELETE CASCADE,
event_type VARCHAR(100) NOT NULL,
payload JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
)
""")
# Create indexes for performance
print("Creating indexes...")
cursor.execute("CREATE INDEX idx_wallet_events_wallet_id ON wallet_events(wallet_id)")
cursor.execute("CREATE INDEX idx_wallet_events_type ON wallet_events(event_type)")
cursor.execute("CREATE INDEX idx_wallet_events_created ON wallet_events(created_at DESC)")
conn.commit()
conn.close()
print("✅ PostgreSQL schema created successfully!")
def migrate_data():
"""Migrate data from SQLite to PostgreSQL"""
print("\nStarting data migration...")
# Connect to SQLite
sqlite_conn = sqlite3.connect(SQLITE_DB)
sqlite_conn.row_factory = sqlite3.Row
sqlite_cursor = sqlite_conn.cursor()
# Connect to PostgreSQL
pg_conn = psycopg2.connect(**PG_CONFIG)
pg_cursor = pg_conn.cursor()
# Migrate wallets
print("Migrating wallets...")
sqlite_cursor.execute("SELECT * FROM wallets")
wallets = sqlite_cursor.fetchall()
wallets_count = 0
for wallet in wallets:
metadata = wallet['metadata']
if isinstance(metadata, str):
try:
metadata = json.loads(metadata)
except:
metadata = {}
pg_cursor.execute("""
INSERT INTO wallets (wallet_id, public_key, metadata)
VALUES (%s, %s, %s)
ON CONFLICT (wallet_id) DO NOTHING
""", (wallet['wallet_id'], wallet['public_key'], json.dumps(metadata)))
wallets_count += 1
# Migrate wallet events
print("Migrating wallet events...")
sqlite_cursor.execute("SELECT * FROM wallet_events")
events = sqlite_cursor.fetchall()
events_count = 0
for event in events:
payload = event['payload']
if isinstance(payload, str):
try:
payload = json.loads(payload)
except:
payload = {}
pg_cursor.execute("""
INSERT INTO wallet_events (wallet_id, event_type, payload, created_at)
VALUES (%s, %s, %s, %s)
""", (event['wallet_id'], event['event_type'], json.dumps(payload), event['created_at']))
events_count += 1
pg_conn.commit()
print(f"\n✅ Migration complete!")
print(f" - Migrated {wallets_count} wallets")
print(f" - Migrated {events_count} wallet events")
sqlite_conn.close()
pg_conn.close()
def main():
"""Main migration process"""
print("=" * 60)
print("AITBC Wallet Daemon SQLite to PostgreSQL Migration")
print("=" * 60)
# Check if SQLite DB exists
if not Path(SQLITE_DB).exists():
print(f"❌ SQLite database '{SQLITE_DB}' not found!")
print("Looking for wallet databases...")
# Find any wallet databases
for db in Path(".").glob("**/*wallet*.db"):
print(f"Found: {db}")
return
# Create PostgreSQL schema
create_pg_schema()
# Migrate data
migrate_data()
print("\n" + "=" * 60)
print("Migration completed successfully!")
print("=" * 60)
print("\nNext steps:")
print("1. Update wallet daemon configuration")
print("2. Install PostgreSQL dependencies")
print("3. Restart the wallet daemon service")
print("4. Verify wallet operations")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,29 @@
#!/bin/bash
echo "=== PostgreSQL Setup for AITBC Wallet Daemon ==="
echo ""
# Create database and user
echo "Creating wallet database..."
sudo -u postgres psql -c "CREATE DATABASE aitbc_wallet;"
sudo -u postgres psql -c "CREATE USER aitbc_user WITH PASSWORD 'aitbc_password';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE aitbc_wallet TO aitbc_user;"
# Grant schema permissions
sudo -u postgres psql -d aitbc_wallet -c 'ALTER SCHEMA public OWNER TO aitbc_user;'
sudo -u postgres psql -d aitbc_wallet -c 'GRANT CREATE ON SCHEMA public TO aitbc_user;'
# Test connection
echo "Testing connection..."
sudo -u postgres psql -c "\l" | grep aitbc_wallet
echo ""
echo "✅ PostgreSQL setup complete for Wallet Daemon!"
echo ""
echo "Connection details:"
echo " Database: aitbc_wallet"
echo " User: aitbc_user"
echo " Host: localhost"
echo " Port: 5432"
echo ""
echo "You can now run the migration script."

View File

@@ -0,0 +1,197 @@
"""PostgreSQL adapter for Wallet Daemon"""
import psycopg2
from psycopg2.extras import RealDictCursor
from typing import Optional, Dict, Any, List
from datetime import datetime
import json
import logging
logger = logging.getLogger(__name__)
class PostgreSQLLedgerAdapter:
"""PostgreSQL implementation of the wallet ledger"""
def __init__(self, db_config: Dict[str, Any]):
self.db_config = db_config
self.connection = None
self._connect()
def _connect(self):
"""Establish database connection"""
try:
self.connection = psycopg2.connect(
cursor_factory=RealDictCursor,
**self.db_config
)
logger.info("Connected to PostgreSQL wallet ledger")
except Exception as e:
logger.error(f"Failed to connect to PostgreSQL: {e}")
raise
def create_wallet(self, wallet_id: str, public_key: str, metadata: Dict[str, Any] = None) -> bool:
"""Create a new wallet"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
INSERT INTO wallets (wallet_id, public_key, metadata)
VALUES (%s, %s, %s)
ON CONFLICT (wallet_id) DO UPDATE
SET public_key = EXCLUDED.public_key,
metadata = EXCLUDED.metadata,
updated_at = NOW()
""", (wallet_id, public_key, json.dumps(metadata or {})))
self.connection.commit()
logger.info(f"Created wallet: {wallet_id}")
return True
except Exception as e:
logger.error(f"Failed to create wallet {wallet_id}: {e}")
self.connection.rollback()
return False
def get_wallet(self, wallet_id: str) -> Optional[Dict[str, Any]]:
"""Get wallet information"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
SELECT wallet_id, public_key, metadata, created_at, updated_at
FROM wallets
WHERE wallet_id = %s
""", (wallet_id,))
result = cursor.fetchone()
if result:
return dict(result)
return None
except Exception as e:
logger.error(f"Failed to get wallet {wallet_id}: {e}")
return None
def list_wallets(self, limit: int = 100, offset: int = 0) -> List[Dict[str, Any]]:
"""List all wallets"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
SELECT wallet_id, public_key, metadata, created_at, updated_at
FROM wallets
ORDER BY created_at DESC
LIMIT %s OFFSET %s
""", (limit, offset))
return [dict(row) for row in cursor.fetchall()]
except Exception as e:
logger.error(f"Failed to list wallets: {e}")
return []
def add_wallet_event(self, wallet_id: str, event_type: str, payload: Dict[str, Any]) -> bool:
"""Add an event to the wallet"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
INSERT INTO wallet_events (wallet_id, event_type, payload)
VALUES (%s, %s, %s)
""", (wallet_id, event_type, json.dumps(payload)))
self.connection.commit()
logger.debug(f"Added event {event_type} to wallet {wallet_id}")
return True
except Exception as e:
logger.error(f"Failed to add event to wallet {wallet_id}: {e}")
self.connection.rollback()
return False
def get_wallet_events(self, wallet_id: str, limit: int = 100) -> List[Dict[str, Any]]:
"""Get events for a wallet"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
SELECT id, event_type, payload, created_at
FROM wallet_events
WHERE wallet_id = %s
ORDER BY created_at DESC
LIMIT %s
""", (wallet_id, limit))
return [dict(row) for row in cursor.fetchall()]
except Exception as e:
logger.error(f"Failed to get events for wallet {wallet_id}: {e}")
return []
def update_wallet_metadata(self, wallet_id: str, metadata: Dict[str, Any]) -> bool:
"""Update wallet metadata"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
UPDATE wallets
SET metadata = %s, updated_at = NOW()
WHERE wallet_id = %s
""", (json.dumps(metadata), wallet_id))
self.connection.commit()
return cursor.rowcount > 0
except Exception as e:
logger.error(f"Failed to update metadata for wallet {wallet_id}: {e}")
self.connection.rollback()
return False
def delete_wallet(self, wallet_id: str) -> bool:
"""Delete a wallet and all its events"""
try:
with self.connection.cursor() as cursor:
cursor.execute("""
DELETE FROM wallets
WHERE wallet_id = %s
""", (wallet_id,))
self.connection.commit()
return cursor.rowcount > 0
except Exception as e:
logger.error(f"Failed to delete wallet {wallet_id}: {e}")
self.connection.rollback()
return False
def get_wallet_stats(self) -> Dict[str, Any]:
"""Get wallet statistics"""
try:
with self.connection.cursor() as cursor:
cursor.execute("SELECT COUNT(*) as total_wallets FROM wallets")
total_wallets = cursor.fetchone()['total_wallets']
cursor.execute("SELECT COUNT(*) as total_events FROM wallet_events")
total_events = cursor.fetchone()['total_events']
cursor.execute("""
SELECT event_type, COUNT(*) as count
FROM wallet_events
GROUP BY event_type
ORDER BY count DESC
""")
event_types = {row['event_type']: row['count'] for row in cursor.fetchall()}
return {
"total_wallets": total_wallets,
"total_events": total_events,
"event_types": event_types
}
except Exception as e:
logger.error(f"Failed to get wallet stats: {e}")
return {}
def close(self):
"""Close the database connection"""
if self.connection:
self.connection.close()
logger.info("PostgreSQL connection closed")
# Factory function
def create_postgresql_adapter() -> PostgreSQLLedgerAdapter:
"""Create a PostgreSQL ledger adapter"""
config = {
"host": "localhost",
"database": "aitbc_wallet",
"user": "aitbc_user",
"password": "aitbc_password",
"port": 5432
}
return PostgreSQLLedgerAdapter(config)