Skip to content

feat: implement API routing, request validation, transaction formatti…#336

Open
Chrisbankz0 wants to merge 1 commit into
stellarkit-lab-devtools:mainfrom
Chrisbankz0:feat/normalize-amount-fields
Open

feat: implement API routing, request validation, transaction formatti…#336
Chrisbankz0 wants to merge 1 commit into
stellarkit-lab-devtools:mainfrom
Chrisbankz0:feat/normalize-amount-fields

Conversation

@Chrisbankz0

Copy link
Copy Markdown

#closes
#293

Pull Request: StellarKit API Bug Fixes and Endpoint Implementations

Description

This PR resolves all compilation, syntax, runtime, and integration issues in the StellarKit API project, bringing the test suite to 100% pass rate (59/59 test suites, 559/559 tests). It implements missing features, updates routing and validation logic for edge cases, cleans up cache usage, and improves tests resilience on Windows loopback connections.


Key Changes

1. New Endpoint Implementations

  • Account Utilities (src/routes/account.js):
    • GET /account/:id/home-domain: Returns the home_domain set on the account.
    • GET /account/:id/min-balance: Computes the minimum XLM reserve requirement and breakdown based on subentry counts.
    • GET /account/:id/flags: Formats Horizon snake_case flags into camelCase booleans.
    • GET /account/:id/signers: Exposes all signers, weights, thresholds, and sponsorship details.
  • Ledger Timing Statistics (src/routes/networkStatus.js):
    • GET /network/ledger-timing: Computes close time, variance, standard deviation, and consistency rating across the last 10 ledgers.
  • Historical Fee Trends (src/routes/feeEstimate.js):
    • GET /fee-estimate/trends: Analyzes fee trends (rising, falling, stable) and capacity usage over the last 50 ledgers.
  • SSE Stream (src/routes/stream.js):
    • GET /stream/ledgers: Implements a Server-Sent Events (SSE) stream for live ledger close events with keep-alive heartbeat pings.

2. Bug Fixes & Optimization

  • Ledger Property type check: Resolved a bug where tx.ledger was returned as a getter function in the JS Stellar SDK, causing it to fail JSON serialization. Changed to a type-safe check (typeof tx.ledger === "number" ? tx.ledger : tx.ledger_attr).
  • Validation and double-slashes collapsing: Standardized parameter verification. A double-slash (e.g., /account//sequence) throws a 400 ValidationError, whereas a clean action word with missing ID (e.g., /account/sequence) correctly bypasses route validation to return 404 Not Found.
  • Cache variables & TTL imports: Fixed incorrect cache imports and adjusted TTL conversion (milliseconds to seconds) for node-cache in asset.js, networkStatus.js, and feeEstimate.js.
  • Axios mock hoisting collision: Refactored the mock implementation in dex-asset-endpoints.test.js to return interceptors and .create properties, preventing Horizon SDK instantiation failure.
  • Central Error Handler: Corrected a ReferenceError inside errorHandler.js by declaring and using the translateHorizonError utility to append code and translated message keys on HorizonError payloads.

Verification & Test Results

Verified using both the static code linter and the local Jest environment:

  • Linter: npm run lint completes with 0 errors.
  • Unit Tests: npm test runs with 59 passed test suites (100% green).
Test Suites: 59 passed, 59 total
Tests:       3 skipped, 559 passed, 562 total
Snapshots:   0 total
Time:        84.951 s
Ran all test suites.

@Sulex45

Sulex45 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Resolve conflicts

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.

2 participants