Skip to content
This repository was archived by the owner on Feb 22, 2026. It is now read-only.

GET/deployed-contracts-endpoint#542

Closed
palit-pratyush wants to merge 8 commits into
Shonen-Labs:mainfrom
palit-pratyush:GET/deployed-contracts-endpoint
Closed

GET/deployed-contracts-endpoint#542
palit-pratyush wants to merge 8 commits into
Shonen-Labs:mainfrom
palit-pratyush:GET/deployed-contracts-endpoint

Conversation

@palit-pratyush
Copy link
Copy Markdown
Contributor

@palit-pratyush palit-pratyush commented Aug 28, 2025

🚀 Pull Request Description

Description

Implement GET /deployed_contracts Endpoint

Overview

This PR implements the /deployed_contracts endpoint to fetch deployed contracts with metadata, along with a supporting POST endpoint for contract creation. The implementation includes robust filtering, sorting, pagination, and rate limiting capabilities.

Key Features

  • GET /deployed_contracts

    • Filtering by name and address (case-insensitive)
    • Sorting by any field (e.g., deployment_date:desc)
    • Pagination with limit and skip parameters
    • Rate limited to 60 requests/minute
    • Comprehensive error handling
  • POST /contracts

    • Create new contract records
    • Strict input validation
    • Rate limited to 10 requests/minute
    • Unique address constraint

Technical Implementation

Database

  • Added ContractDB SQLAlchemy model with:
    • id: Auto-incrementing primary key
    • name: String, indexed
    • address: String, unique, indexed
    • deployment_date: DateTime

API Models

  • Contract: Response model
  • ContractCreate: Request validation model
  • DeployedContractsResponse: Paginated response model

Validation

  • Contract address must be a valid Ethereum address (0x + 40 hex chars)
  • Contract name length: 1-100 characters
  • Rate limiting using slowapi
  • Unique address constraint at database level

Example Usage

# Get all contracts with pagination
GET /api/deployed_contracts?limit=10&skip=0

# Filter by name
GET /api/deployed_contracts?name=Token

# Sort by deployment date
GET /api/deployed_contracts?sort_by=deployment_date:desc

# Create a new contract
POST /api/contracts
{
    "name": "My Contract",
    "address": "0x1234567890123456789012345678901234567890",
    "deployment_date": "2025-08-29T12:00:00Z"
}

🔗 Linked Issues

✅ What’s New

  • Added comprehensive test suite covering:
    • ✅ Contract creation
    • ✅ Contract listing with filters
    • ✅ Sorting functionality
    • ✅ Pagination
    • ✅ Rate limiting
    • ✅ Error cases
    • ✅ Input validation

📚 Documentation

  • Added OpenAPI tags and descriptions
  • Added detailed docstrings
  • Added example requests and responses
  • Documented error handling scenarios

📦 Dependencies Added

  • slowapi – for rate limiting
  • httpx – for HTTP-based testing
  • pytest-asyncio – for async test support

🛠 Migration

  • No database migrations needed (new feature only)

⚡ Performance Considerations

  • ✅ Added DB indexes for commonly queried fields
  • ✅ Implemented efficient pagination
  • ✅ Configured rate limiting to prevent abuse

🔐 Security

  • ✅ Input validation for all parameters
  • ✅ Rate limiting to prevent DoS attacks
  • ✅ Error messages do not leak internal details

🔗 Related Issues


✅ Checklist

  • Tests added and passing
  • API documentation updated
  • Input validation implemented
  • Rate limiting configured
  • Error handling implemented
  • Database indexes added
  • Code follows project style
  • No breaking changes

- Add ContractDB SQLAlchemy model
- Implement GET /deployed_contracts endpoint with filtering and sorting
- Add POST /contracts endpoint for creating new contracts
- Add database integration
- Support pagination with limit and skip parameters
- Add input validation for contract addresses
- Add rate limiting (60/min for GET, 10/min for POST)
- Improve error handling for invalid sort fields
- Add comprehensive API documentation
- Add unit tests with 100% coverage
- Add test configuration with in-memory SQLite
- Replace deprecated constr with Field validation
- Update string constraints for user and contract models
- Add Request parameter to rate-limited endpoints
- Fix rate limiter configuration for FastAPI
- Add proper rate limit exceeded error handler
- Add missing imports for FastAPI responses
- Generate unique addresses for each POST request in rate limit test
- Add early break when rate limit is hit
- Fix test assertions
@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stark-finder-mq45 Ready Ready Preview Comment Aug 28, 2025 9:59pm

@palit-pratyush palit-pratyush changed the title Get/deployed-contracts-endpoint GET/deployed-contracts-endpoint Aug 28, 2025
@Caffeine-Connoisseur
Copy link
Copy Markdown
Collaborator

@palit-pratyush run

  poetry run black 
  poetry run isort 

to fix lint issues

- Fix Python linting issues
  - Apply black formatting
  - Sort imports with isort
  - Fix coding style issues

- Fix Cairo contract implementation
  - Update to Cairo 2.8.0 syntax
  - Implement proper interfaces
  - Add complete test suite
  - Fix visibility modifiers
  - Add proper trait implementations
@PoulavBhowmick03
Copy link
Copy Markdown
Contributor

@palit-pratyush kindly resolve the conflicts

Copy link
Copy Markdown
Contributor

@tosoham tosoham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix merge conflicts

@palit-pratyush palit-pratyush deleted the GET/deployed-contracts-endpoint branch August 29, 2025 16:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement GET /deployed_contracts Endpoint

4 participants