
Features implemented: - User authentication with JWT tokens and role-based access (developer/buyer) - Blockchain wallet linking and management with Ethereum integration - Carbon project creation and management for developers - Marketplace for browsing and purchasing carbon offsets - Transaction tracking with blockchain integration - Database models for users, projects, offsets, and transactions - Comprehensive API with authentication, wallet, project, and trading endpoints - Health check endpoint and platform information - SQLite database with Alembic migrations - Full API documentation with OpenAPI/Swagger Technical stack: - FastAPI with Python - SQLAlchemy ORM with SQLite - Web3.py for blockchain integration - JWT authentication with bcrypt - CORS enabled for frontend integration - Comprehensive error handling and validation Environment variables required: - SECRET_KEY (JWT secret) - BLOCKCHAIN_RPC_URL (optional, defaults to localhost)
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Float, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
|
|
from app.db.base import Base
|
|
|
|
class Transaction(Base):
|
|
__tablename__ = "transactions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
transaction_hash = Column(String, unique=True, nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
price_per_credit = Column(Float, nullable=False)
|
|
total_amount = Column(Float, nullable=False)
|
|
|
|
# Transaction status
|
|
status = Column(String, default="pending") # "pending", "confirmed", "failed"
|
|
|
|
# Blockchain information
|
|
block_number = Column(Integer, nullable=True)
|
|
gas_used = Column(Integer, nullable=True)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
confirmed_at = Column(DateTime, nullable=True)
|
|
|
|
# Foreign keys
|
|
buyer_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
offset_id = Column(Integer, ForeignKey("carbon_offsets.id"), nullable=False)
|
|
|
|
# Relationships
|
|
buyer = relationship("User", back_populates="transactions")
|
|
offset = relationship("CarbonOffset", back_populates="transactions") |