{"id":20399696,"url":"https://github.com/ohld/rated-network-coding-challenge","last_synced_at":"2026-05-10T18:05:31.059Z","repository":{"id":188986186,"uuid":"679298888","full_name":"ohld/rated-network-coding-challenge","owner":"ohld","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-18T13:43:32.000Z","size":553,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-15T11:18:53.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-16T14:27:40.000Z","updated_at":"2024-08-24T16:27:19.000Z","dependencies_parsed_at":"2024-11-15T12:16:31.380Z","dependency_job_id":null,"html_url":"https://github.com/ohld/rated-network-coding-challenge","commit_stats":null,"previous_names":["ohld/rated-network-coding-challenge"],"tags_count":0,"template":false,"template_full_name":"zhanymkanov/fastapi_production_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohld%2Frated-network-coding-challenge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohld%2Frated-network-coding-challenge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohld%2Frated-network-coding-challenge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohld%2Frated-network-coding-challenge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohld","download_url":"https://codeload.github.com/ohld/rated-network-coding-challenge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241946934,"owners_count":20047085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T04:31:30.954Z","updated_at":"2026-05-10T18:05:31.032Z","avatar_url":"https://github.com/ohld.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rated Network Coding Challenge\nOriginal repo with task description: https://github.com/rated-network/coding-challenge/\n\nBuilt with [FastAPI best practices](https://github.com/zhanymkanov/fastapi-best-practices) in mind using [FastAPI production template](https://github.com/zhanymkanov/fastapi_production_template).\n\n# Quick start\n\n``` bash\n\ngit clone https://github.com/ohld/rated-network-coding-challenge\ncd rated-network-coding-challenge\n\ncp .env.example .env\ndocker network create app_main\ndocker-compose up -d --build\n\n# apply migrations to local db\ndocker compose exec app migrate\n\n# upload sample data\ndocker compose exec app python ./tests/upload_tx_data.py\n```\n\nI'd suggest to run the latter command separately to let docker image run for a couple seconds. Otherwise phantom errors like `Cannot assign requested address` for localhost may occur. 🤷\n\n\n## What's inside\n\n### GET `/stats` (src/stats/router.py)\n\n``` json\n{\n  \"total_transactions_in_db\": 5000,\n  \"total_gas_used_gwei\": 10492553722.431274,\n  \"total_gas_cost_in_usd\": 19219.824439832475\n}\n```\n\n### POST `/transactions` (src/transactions/router.py)\n\nCreates transaction in db, returns nothing (for simplicity). Boilerplate to integrate streams further. \n1. Stores raw data\n2. Calculates `gas_used_gwei` on the fly\n3. Background task to calculate `gas_used_usd` using Coingecko API (cached with Redis)\n\n### GET `/transactions/{tx_hash}` (src/transactions/router.py)\n\nReturns TransactionCompactResponse:\n``` json\n{\n  \"hash\": \"0x06568e8d3c76f6961c650c3b2c9404c79b3bb14138051313b9a74e6255d02140\",\n  \"from_address\": \"0x7f21c6ab63892ed9db38f5b79d0fadaf4ec79a42\",\n  \"to_address\": \"0x7a097dbacb237d6b6a047368f43514992510bb79\",\n  \"block_number\": 17818510,\n  \"block_timestamp\": \"2023-08-01T06:58:35+0000\",\n  \"gas_used_gwei\": 399397.655979,\n  \"gas_used_usd\": 0.7305556709464458\n}\n```\n\n### Tests\n\n1. tx data upload + proper get response with calculated fields (`gas_used_gwei`, `gas_used_usd`)\n2. txs data upload from csv file + proper /stats response\n\nI didn't test the Coingecko API integration and didn't write fallbacks in case it will not be available at some point.\n\n\n## Local Development\n\n### First Build Only\n1. `cp .env.example .env`\n2. `docker network create app_main`\n3. `docker-compose up -d --build`\n\n### Linters\nFormat the code\n```shell\ndocker compose exec app format\n```\n\n### Migrations\n- Create an automatic migration from changes in `src/database.py`\n```shell\ndocker compose exec app makemigrations *migration_name*\n```\n- Run migrations\n```shell\ndocker compose exec app migrate\n```\n- Downgrade migrations\n```shell\ndocker compose exec app downgrade -1  # or -2 or base or hash of the migration\n```\n### Tests\nAll tests are integrational and require DB connection. \n\nOne of the choices I've made is to use default database (`postgres`), separated from app's `app` database.\n- Using default database makes it easier to run tests in CI/CD environments, since there is no need to setup additional databases\n- Tests are run with `force_rollback=True`, i.e. every transaction made is then reverted\n\nRun tests\n```shell\ndocker compose exec app pytest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohld%2Frated-network-coding-challenge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohld%2Frated-network-coding-challenge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohld%2Frated-network-coding-challenge/lists"}