Skip to content

Comments

feat: add GET /auth/finance/revenue endpoint#15

Closed
mukama wants to merge 4 commits intotetherto:developfrom
mukama:feat/finance-revenue
Closed

feat: add GET /auth/finance/revenue endpoint#15
mukama wants to merge 4 commits intotetherto:developfrom
mukama:feat/finance-revenue

Conversation

@mukama
Copy link
Contributor

@mukama mukama commented Feb 19, 2026

Summary

  • Adds GET /auth/finance/revenue API v2 endpoint that fetches pool transaction data, separates revenue from pool fees, and aggregates by period
  • Supports both F2Pool (changed_balance + tx_fee) and Ocean (satoshis_net_earned + fees_colected_satoshis) transaction formats
  • Supports daily, weekly, monthly, yearly period aggregation with optional pool filter

Usage

GET /auth/finance/revenue?start=1700000000000&end=1700100000000&period=daily&pool=f2pool&overwriteCache=true
Optional: period ("daily" | "weekly" | "monthly" | "yearly"), pool, overwriteCache

Port pool transaction revenue data from legacy dashboard to API v2.
Separates revenue from pool fees, supporting both F2Pool (changed_balance
+ tx_fee) and Ocean (satoshis_net_earned + fees_colected_satoshis) formats.
Aggregates by period with optional pool filter.
@mukama mukama changed the base branch from main to develop February 19, 2026 11:51
tekwani
tekwani previously approved these changes Feb 19, 2026
if (!ts) continue
const day = daily[ts] ??= { revenueBTC: 0, feesBTC: 0 }
if (t.satoshis_net_earned) {
day.revenueBTC += Math.abs(t.satoshis_net_earned) / BTC_SATS

Choose a reason for hiding this comment

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

@mukama this logic seems to be repeating in lots of places in different apis. Can we make this common function ?

- Create finance.utils.js with shared utilities:
  - validateStartEnd: replaces duplicated validation in every handler
  - normalizeTimestampMs: moved from finance.handlers.js
  - processTransactions: consolidates processTransactionData and
    processEbitdaTransactions (fixes missing normalizeTimestampMs and
    incorrect BTC_SATS division bugs), supports trackFees option
  - extractCurrentPrice: merges flat and nested EBITDA price formats
  - processBlockData: extracted for reuse across revenue endpoints
- Refactor finance.handlers.js to use shared utils
- Add comprehensive unit tests for all utils (24 tests)
- Update handler tests to remove tests for deleted functions
- Merge refactor/finance-utils branch
- Replace processRevenueTransactions with processTransactions({trackFees: true})
- Replace inline validation with validateStartEnd in getRevenue
- Remove duplicate processRevenueTransactions tests (covered by utils)
mukama added a commit to mukama/miningos-app-node that referenced this pull request Feb 20, 2026
Merge feat/finance-revenue (PR tetherto#15) and feat/finance-revenue-summary (PR tetherto#16)
into a single branch with shared finance utilities refactor:
- GET /auth/finance/revenue - per-pool transaction revenue with fees
- GET /auth/finance/revenue-summary - comprehensive revenue dashboard
- Shared finance.utils.js with consolidated transaction processing
- Fixes duplicate code, normalizes timestamp handling, renames ambiguous functions
@mukama
Copy link
Contributor Author

mukama commented Feb 20, 2026

Superseded by #22 (feat/finance-endpoints) which combines this with PR #16 and the shared finance utils refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants