A microservice built with FastAPI to retrieve and store information about Tron wallet addresses, including balance, bandwidth, and energy.
- POST /wallet/: Fetch wallet details and save the request in the database.
- GET /wallet/queries/: Retrieve a paginated list of recent wallet queries.
- Database integration with SQLAlchemy ORM.
- Tron API interaction using
tronpy. - Comprehensive unit and integration tests with
pytest.
├── config.py # Configuration for API keys and test address
├── database.py # Database models and connection
├── main.py # FastAPI application and endpoints
├── schemas.py # Pydantic models for request/response validation
├── test_wallet.py # Unit and integration tests
- Python 3.9+
- FastAPI
- SQLAlchemy
- Tronpy
- Pytest
Install the dependencies:
pip install fastapi sqlalchemy tronpy pytestAdd your TronGrid API key and a test address in config.py:
API_KEY = "your_api_key_here"
TEST_ADDRESS = "your_test_address_here"- Initialize the database by running the application.
- Start the FastAPI server:
uvicorn main:app --reload- Access the API documentation at http://127.0.0.1:8000/docs.
Fetch wallet information and store the request in the database.
Request Body:
{
"address": "wallet_address_here"
}Response:
{
"address": "wallet_address_here",
"balance": 100,
"bandwidth": 2000,
"energy": 500
}Retrieve the paginated list of recent wallet queries.
Query Parameters:
skip: Number of records to skip (default: 0).limit: Maximum number of records to return (default: 10).
Response:
[
{
"id": 1,
"address": "wallet_address_here",
"timestamp": "2024-12-27T12:00:00"
}
]Execute unit and integration tests using pytest:
pytest- Use a valid Tron wallet address for testing.
- Ensure the database is properly configured in
database.py. - Activate Tron addresses by making a transaction if needed.
This project is open-source and available under the MIT License.