docs: add structure.md, update files.md, rewrite README for GitHub, add favicon, replace debug prints with logging, remove stale src/ copy and empty dirs

This commit is contained in:
oib
2026-02-11 21:14:56 +01:00
parent 6fcc573db7
commit 5773156ce1
15 changed files with 523 additions and 739 deletions

View File

@@ -1 +0,0 @@
1529925 1529926 1529927 1529928

View File

@@ -8,6 +8,9 @@ import uuid
import time
import json
import os
import logging
logger = logging.getLogger(__name__)
from ..schemas import ExchangePaymentRequest, ExchangePaymentResponse
from ..services.bitcoin_wallet import get_wallet_balance, get_wallet_info
@@ -109,7 +112,7 @@ async def confirm_payment(
from ..services.blockchain import mint_tokens
mint_tokens(payment['user_id'], payment['aitbc_amount'])
except Exception as e:
print(f"Error minting tokens: {e}")
logger.error("Error minting tokens: %s", e)
# In production, handle this error properly
return {

View File

@@ -7,6 +7,9 @@ from pydantic import BaseModel, Field
from typing import Optional, Dict, Any, List
from datetime import datetime, timedelta
import json
import logging
logger = logging.getLogger(__name__)
from ..schemas import UserProfile
from ..storage import SessionDep
@@ -349,7 +352,7 @@ async def execute_parameter_change(target: Dict[str, Any], background_tasks):
"""Execute a parameter change proposal"""
# This would update system parameters
print(f"Executing parameter change: {target}")
logger.info("Executing parameter change: %s", target)
# Implementation would depend on the specific parameters
@@ -357,7 +360,7 @@ async def execute_protocol_upgrade(target: Dict[str, Any], background_tasks):
"""Execute a protocol upgrade proposal"""
# This would trigger a protocol upgrade
print(f"Executing protocol upgrade: {target}")
logger.info("Executing protocol upgrade: %s", target)
# Implementation would involve coordinating with nodes
@@ -365,7 +368,7 @@ async def execute_fund_allocation(target: Dict[str, Any], background_tasks):
"""Execute a fund allocation proposal"""
# This would transfer funds from treasury
print(f"Executing fund allocation: {target}")
logger.info("Executing fund allocation: %s", target)
# Implementation would involve treasury management
@@ -373,7 +376,7 @@ async def execute_policy_change(target: Dict[str, Any], background_tasks):
"""Execute a policy change proposal"""
# This would update system policies
print(f"Executing policy change: {target}")
logger.info("Executing policy change: %s", target)
# Implementation would depend on the specific policy

View File

@@ -6,9 +6,12 @@ Uses RPC to connect to Bitcoin Core (or alternative like Block.io)
import os
import json
import logging
import requests
from typing import Dict, Optional
logger = logging.getLogger(__name__)
# Bitcoin wallet configuration
WALLET_CONFIG = {
# For development, we'll use testnet
@@ -31,11 +34,11 @@ class BitcoinWallet:
try:
result = self._rpc_call('getbalance', ["*", 0, False])
if result.get('error') is not None:
print(f"Bitcoin RPC error: {result['error']}")
logger.error("Bitcoin RPC error: %s", result['error'])
return 0.0
return result.get('result', 0.0)
except Exception as e:
print(f"Failed to get balance: {e}")
logger.error("Failed to get balance: %s", e)
return 0.0
def get_new_address(self) -> str:
@@ -43,11 +46,11 @@ class BitcoinWallet:
try:
result = self._rpc_call('getnewaddress', ["", "bech32"])
if result.get('error') is not None:
print(f"Bitcoin RPC error: {result['error']}")
logger.error("Bitcoin RPC error: %s", result['error'])
return self.config['fallback_address']
return result.get('result', self.config['fallback_address'])
except Exception as e:
print(f"Failed to get new address: {e}")
logger.error("Failed to get new address: %s", e)
return self.config['fallback_address']
def list_transactions(self, count: int = 10) -> list:
@@ -55,11 +58,11 @@ class BitcoinWallet:
try:
result = self._rpc_call('listtransactions', ["*", count, 0, True])
if result.get('error') is not None:
print(f"Bitcoin RPC error: {result['error']}")
logger.error("Bitcoin RPC error: %s", result['error'])
return []
return result.get('result', [])
except Exception as e:
print(f"Failed to list transactions: {e}")
logger.error("Failed to list transactions: %s", e)
return []
def _rpc_call(self, method: str, params: list = None) -> Dict:
@@ -83,7 +86,7 @@ class BitcoinWallet:
response.raise_for_status()
return response.json()
except Exception as e:
print(f"RPC call failed: {e}")
logger.error("RPC call failed: %s", e)
return {"error": str(e)}
# Create a wallet instance
@@ -117,7 +120,7 @@ def get_wallet_info() -> Dict[str, any]:
"blocks": blockchain_info.get('result', {}).get('blocks', 0) if is_connected else 0
}
except Exception as e:
print(f"Error getting wallet info: {e}")
logger.error("Error getting wallet info: %s", e)
return {
"balance": 0.0,
"address": "tb1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",

View File

@@ -4,10 +4,13 @@ Blockchain service for AITBC token operations
import httpx
import asyncio
import logging
from typing import Optional
from ..config import settings
logger = logging.getLogger(__name__)
BLOCKCHAIN_RPC = f"http://127.0.0.1:9080/rpc"
async def mint_tokens(address: str, amount: float) -> dict:
@@ -44,6 +47,6 @@ def get_balance(address: str) -> Optional[float]:
return float(data.get("balance", 0))
except Exception as e:
print(f"Error getting balance: {e}")
logger.error("Error getting balance: %s", e)
return None

View File

@@ -1,9 +1,12 @@
from __future__ import annotations
import logging
from typing import Any, Dict, Optional
from secrets import token_hex
from datetime import datetime
logger = logging.getLogger(__name__)
from aitbc_crypto.signing import ReceiptSigner
from sqlmodel import Session
@@ -129,7 +132,7 @@ class ReceiptService:
except Exception as e:
# Log error but don't fail receipt creation
print(f"Failed to generate ZK proof: {e}")
logger.warning("Failed to generate ZK proof: %s", e)
receipt_row = JobReceipt(job_id=job.id, receipt_id=payload["receipt_id"], payload=payload)
self.session.add(receipt_row)

View File

@@ -8,9 +8,12 @@ import psycopg2
from psycopg2.extras import RealDictCursor
from typing import Generator, Optional, Dict, Any, List
import json
import logging
from datetime import datetime
from decimal import Decimal
logger = logging.getLogger(__name__)
from .config_pg import settings
# SQLAlchemy setup for complex queries
@@ -203,7 +206,7 @@ def init_db():
# Create all tables
Base.metadata.create_all(bind=engine)
print("PostgreSQL database initialized successfully!")
logger.info("PostgreSQL database initialized successfully")
# Health check
def check_db_health() -> Dict[str, Any]: