
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)
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text, Float, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
|
|
from app.db.base import Base
|
|
|
|
class CarbonOffset(Base):
|
|
__tablename__ = "carbon_offsets"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
serial_number = Column(String, unique=True, nullable=False)
|
|
vintage_year = Column(Integer, nullable=False)
|
|
quantity = Column(Integer, nullable=False) # Number of credits
|
|
status = Column(String, default="available") # "available", "sold", "retired"
|
|
|
|
# Blockchain information
|
|
token_id = Column(String, unique=True, nullable=True)
|
|
blockchain_hash = Column(String, nullable=True)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Foreign keys
|
|
project_id = Column(Integer, ForeignKey("carbon_projects.id"), nullable=False)
|
|
|
|
# Relationships
|
|
project = relationship("CarbonProject", back_populates="offsets")
|
|
transactions = relationship("Transaction", back_populates="offset") |