mirror of
https://github.com/pezkuwichain/pezkuwi-mobile-app.git
synced 2026-06-12 13:31:16 +00:00
auto-commit for 22800351-11eb-4f9c-a616-718cc34d7f41
This commit is contained in:
+113
-3
@@ -1,4 +1,4 @@
|
||||
from fastapi import FastAPI, APIRouter
|
||||
from fastapi import FastAPI, APIRouter, HTTPException
|
||||
from dotenv import load_dotenv
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
@@ -6,9 +6,11 @@ import os
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List
|
||||
from typing import List, Optional, Dict, Any
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
import httpx
|
||||
import json
|
||||
|
||||
|
||||
ROOT_DIR = Path(__file__).parent
|
||||
@@ -19,6 +21,9 @@ mongo_url = os.environ['MONGO_URL']
|
||||
client = AsyncIOMotorClient(mongo_url)
|
||||
db = client[os.environ['DB_NAME']]
|
||||
|
||||
# Polkadot RPC endpoint (DKSweb's blockchain)
|
||||
POLKADOT_RPC = "wss://beta-rpc.pezkuwi.art"
|
||||
|
||||
# Create the main app without a prefix
|
||||
app = FastAPI()
|
||||
|
||||
@@ -35,10 +40,21 @@ class StatusCheck(BaseModel):
|
||||
class StatusCheckCreate(BaseModel):
|
||||
client_name: str
|
||||
|
||||
class WalletBalanceRequest(BaseModel):
|
||||
address: str
|
||||
|
||||
class WalletBalanceResponse(BaseModel):
|
||||
address: str
|
||||
hez: str
|
||||
pez: str
|
||||
transferrable: str
|
||||
reserved: str
|
||||
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
# Add your routes to the router instead of directly to app
|
||||
@api_router.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello World"}
|
||||
return {"message": "PezkuwiChain Mobile API"}
|
||||
|
||||
@api_router.post("/status", response_model=StatusCheck)
|
||||
async def create_status_check(input: StatusCheckCreate):
|
||||
@@ -52,6 +68,100 @@ async def get_status_checks():
|
||||
status_checks = await db.status_checks.find().to_list(1000)
|
||||
return [StatusCheck(**status_check) for status_check in status_checks]
|
||||
|
||||
# ========================================
|
||||
# BLOCKCHAIN API PROXY
|
||||
# ========================================
|
||||
|
||||
@api_router.post("/blockchain/balance")
|
||||
async def get_balance(request: WalletBalanceRequest):
|
||||
"""
|
||||
Get wallet balance from blockchain
|
||||
This is a proxy to avoid Polkadot.js issues in React Native
|
||||
"""
|
||||
try:
|
||||
# For now, return mock data
|
||||
# TODO: Implement actual RPC call to blockchain
|
||||
return WalletBalanceResponse(
|
||||
address=request.address,
|
||||
hez="1000.0000",
|
||||
pez="5000.0000",
|
||||
transferrable="800.0000",
|
||||
reserved="200.0000"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching balance: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@api_router.get("/blockchain/transactions/{address}")
|
||||
async def get_transactions(address: str):
|
||||
"""
|
||||
Get transaction history for an address
|
||||
"""
|
||||
try:
|
||||
# Mock data for now
|
||||
return {
|
||||
"address": address,
|
||||
"transactions": [
|
||||
{
|
||||
"hash": "0x123...",
|
||||
"from": address,
|
||||
"to": "5GrwvaEF5zXb26Fz9rc...",
|
||||
"amount": "100.0000",
|
||||
"asset": "HEZ",
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"status": "success"
|
||||
}
|
||||
]
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching transactions: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@api_router.get("/citizenship/status/{address}")
|
||||
async def get_citizenship_status(address: str):
|
||||
"""
|
||||
Get citizenship status for an address
|
||||
"""
|
||||
try:
|
||||
# Mock data
|
||||
return {
|
||||
"address": address,
|
||||
"hasApplied": False,
|
||||
"isApproved": False,
|
||||
"hasTiki": False,
|
||||
"tikiNumber": None,
|
||||
"region": None,
|
||||
"nextAction": "APPLY_KYC"
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching citizenship status: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@api_router.get("/governance/proposals")
|
||||
async def get_proposals():
|
||||
"""
|
||||
Get active governance proposals
|
||||
"""
|
||||
try:
|
||||
# Mock data
|
||||
return {
|
||||
"proposals": [
|
||||
{
|
||||
"id": "1",
|
||||
"title": "Increase PEZ Rewards",
|
||||
"description": "Proposal to increase monthly PEZ rewards by 10%",
|
||||
"proposer": "5GrwvaEF5zXb26Fz9rc...",
|
||||
"votesYes": 150,
|
||||
"votesNo": 30,
|
||||
"deadline": datetime.utcnow().isoformat(),
|
||||
"status": "active"
|
||||
}
|
||||
]
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching proposals: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
# Include the router in the main app
|
||||
app.include_router(api_router)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user