Skip to content

feat: add transaction history endpoint#163

Merged
salazarsebas merged 3 commits intoHarmonia-Development:mainfrom
derianrddev:feat/transaction-history
Oct 6, 2025
Merged

feat: add transaction history endpoint#163
salazarsebas merged 3 commits intoHarmonia-Development:mainfrom
derianrddev:feat/transaction-history

Conversation

@derianrddev
Copy link
Contributor

🛠️ Issue
Closes #139

📖 Description
This PR implements a new endpoint to retrieve transaction history for Stellar wallets on Testnet. The endpoint fetches transactions from the local SQLite database and enriches them with detailed information from the Horizon API, including timestamps, amounts, and destination addresses.

✅ Changes Made

  • Database Layer: Added getTransactionsByUserId() helper function to query user transactions ordered by newest first
  • API Endpoint: Implemented GET /wallet/transactions/:user_id with JWT authentication
    • Validates user_id parameter (must be positive integer)
    • Verifies JWT authorization (returns 403 if user_id doesn't match token)
    • Fetches transactions from SQLite database
    • Enriches each transaction with Horizon API data (timestamp, amount, destination)
    • Uses Promise.all for parallel Horizon API calls to optimize performance
    • Handles edge cases: empty transactions (returns 200 with empty array), invalid user_id (400), Horizon failures (500)
  • Tests: Added comprehensive test suite with 10 test cases covering:
    • Success scenarios with enriched transaction data
    • Validation tests (invalid/negative/zero user_id)
    • Authorization tests (JWT mismatch, invalid JWT)
    • Error handling (Horizon API failures)
    • Edge cases (empty transactions, non-payment operations)
    • Achieved 100% coverage for the new endpoint

🖼️ Media (screenshots/videos)

image

- Add function to retrieve all transactions for a given user

- Orders results by id DESC (newest first)

- Returns TransactionRow[] with full transaction details
- Implement JWT-protected endpoint to fetch user transaction history

- Validate user_id and verify JWT authorization (403 on mismatch)

- Enrich transactions with Horizon data (timestamp, amount, destination)

- Use Promise.all for parallel Horizon API calls

- Handle edge cases: empty transactions, invalid user_id, Horizon errors

- Return 200 with enriched transaction list or empty array
- Add 10 test cases covering success and error scenarios

- Mock Horizon API calls (transactions and operations endpoints)

- Test validation: invalid/negative/zero user_id

- Test authorization: JWT mismatch (403), invalid JWT (401)

- Test error handling: Horizon failures (500)

- Test edge cases: empty transactions, no payment operations

- Achieve 100% coverage for new endpoint
Copy link
Contributor

@salazarsebas salazarsebas left a comment

Choose a reason for hiding this comment

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

LGTM

@salazarsebas salazarsebas merged commit 75baed1 into Harmonia-Development:main Oct 6, 2025
4 checks passed
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.

Query Transaction History for Stellar Wallet Service [wallet - service]

2 participants