feat: integrate actual blockchain mining with PoA consensus and fix CLI wallet operations
🔗 Mining Integration: • Connect mining RPC endpoints to PoA proposer for real block production • Initialize PoA proposer in app lifespan for mining integration • Add mining status, start, stop, and stats endpoints with blockchain data • Track actual block production rate and mining statistics • Support 1-8 mining threads with proper validation 🔧 PoA Consensus Integration: • Set global PoA proposer reference for mining operations • Start
This commit is contained in:
@@ -102,9 +102,8 @@ def mining_operations(operation: str, wallet_name: str = None, threads: int = 1,
|
||||
print(f"Starting mining with wallet '{wallet_name}' using {threads} threads...")
|
||||
|
||||
mining_config = {
|
||||
"miner_address": wallet_name, # Simplified for demo
|
||||
"threads": threads,
|
||||
"enabled": True
|
||||
"proposer_address": wallet_name, # Fixed field name for PoA
|
||||
"threads": threads
|
||||
}
|
||||
|
||||
try:
|
||||
@@ -235,7 +234,7 @@ def ai_operations(operation: str, wallet_name: str = None, job_type: str = None,
|
||||
print(f" Prompt: {prompt[:50]}...")
|
||||
|
||||
job_data = {
|
||||
"client_address": wallet_name, # Simplified for demo
|
||||
"wallet_address": wallet_name, # Fixed field name
|
||||
"job_type": job_type,
|
||||
"prompt": prompt,
|
||||
"payment": payment
|
||||
|
||||
@@ -538,35 +538,35 @@ def submit_ai_job(wallet_name: str, job_type: str, prompt: str, payment: float,
|
||||
print(f"Error: {e}")
|
||||
return None
|
||||
def get_balance(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR,
|
||||
rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]:
|
||||
rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]:
|
||||
"""Get wallet balance and transaction info"""
|
||||
try:
|
||||
keystore_path = keystore_dir / f"{wallet_name}.json"
|
||||
if not keystore_path.exists():
|
||||
print(f"Error: Wallet '{wallet_name}' not found")
|
||||
try:
|
||||
keystore_path = keystore_dir / f"{wallet_name}.json"
|
||||
if not keystore_path.exists():
|
||||
print(f"Error: Wallet '{wallet_name}' not found")
|
||||
return None
|
||||
|
||||
with open(keystore_path) as f:
|
||||
wallet_data = json.load(f)
|
||||
|
||||
address = wallet_data['address']
|
||||
|
||||
# Get balance from RPC
|
||||
response = requests.get(f"{rpc_url}/rpc/getBalance/{address}")
|
||||
if response.status_code == 200:
|
||||
balance_data = response.json()
|
||||
return {
|
||||
"address": address,
|
||||
"balance": balance_data.get("balance", 0),
|
||||
"nonce": balance_data.get("nonce", 0),
|
||||
"wallet_name": wallet_name
|
||||
}
|
||||
else:
|
||||
print(f"Error getting balance: {response.text}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return None
|
||||
|
||||
with open(keystore_path) as f:
|
||||
wallet_data = json.load(f)
|
||||
|
||||
address = wallet_data['address']
|
||||
|
||||
# Get balance from RPC
|
||||
response = requests.get(f"{rpc_url}/rpc/getBalance/{address}")
|
||||
if response.status_code == 200:
|
||||
balance_data = response.json()
|
||||
return {
|
||||
"address": address,
|
||||
"balance": balance_data.get("balance", 0),
|
||||
"nonce": balance_data.get("nonce", 0),
|
||||
"wallet_name": wallet_name
|
||||
}
|
||||
else:
|
||||
print(f"Error getting balance: {response.text}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_transactions(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR,
|
||||
|
||||
Reference in New Issue
Block a user