Skip to content

Microservice for obtaining information about wallets in the Tron network. Allows you to get the TRX balance, bandwidth and energy by wallet address. Saves the history of queries in the database with pagination support. Implemented on FastAPI using SQLAlchemy ORM and TronPy.

Notifications You must be signed in to change notification settings

averageencoreenjoer/tron-wallet-info

Repository files navigation

Tron Wallet Info Service

Microservice for obtaining information about wallets in the Tron network with saving the history of requests.

Features

  • Getting information about the wallet (TRX balance, bandwidth, energy)
  • Saving the history of requests in the DB
  • Viewing history with pagination
  • Full API documentation (Swagger UI)
  • Unit and integration tests
  • Docker support

Technologies

  • Python 3.11
  • FastAPI
  • SQLAlchemy 2.0
  • TronPy
  • Pytest
  • Docker

Quick Start

Without Docker

git clone https://github.com/averageencoreenjoer/tron-wallet-info
cd tron_wallet_info

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

uvicorn app.main:app --reload

With Docker

git clone https://github.com/averageencoreenjoer/tron-wallet-info
cd tron_wallet_info

docker-compose up --build

The application will be available at: http://localhost:8000

Configuration

Create a .env file based on .env.example:

cp .env.example .env

Available environment variables:

  • DATABASE_URL - Database URL (default: sqlite:///./tron_wallet.db)
  • TRON_NETWORK - Tron network (shasta/mainnet)

API Endpoints

Getting wallet info

POST /wallet-info

{
"address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
}

Response example:

{
"address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"trx_balance": 1000000,
"bandwidth": 500,
"energy": 200
}

Getting request history

GET /request-history?skip=0&limit=10

Example answer:

{
  "count": 15,
  "results": [
    {
      "id": 15,
      "address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
      "trx_balance": 1000000,
      "bandwidth": 500,
      "energy": 200,
      "created_at": "2023-10-05T12:00:00"
    },
    ...
  ]
}

Testing

# Running tests
pytest -v

# Running tests with coverage
pytest --cov=app --cov-report=html

API documentation

After running the application, the documentation is available at:

Using Docker

Building an image

docker-compose build

Starting a service

docker-compose up

Stopping the service

docker-compose down

To use PostgreSQL

Uncomment the db section in docker-compose.yml and set:

DATABASE_URL=postgresql://tron:tronpass@db:5432/tron_db

Database migrations

# Generating migrations
alembic revision --autogenerate -m "Description of changes"

# Applying migrations
alembic upgrade head

About

Microservice for obtaining information about wallets in the Tron network. Allows you to get the TRX balance, bandwidth and energy by wallet address. Saves the history of queries in the database with pagination support. Implemented on FastAPI using SQLAlchemy ORM and TronPy.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published