Skip to content

[CONTRACTS] Add helper for fetching current Stellar ledger timestamp from Horizon RPCΒ #159

Description

@chizzy192

Metadata

Field Value
Domain Contracts
Difficulty Easy (1–2 Days)
Effort Estimate effort: 3h
Priority P2-Medium
Labels good first issue, easy, Stellar Wave
Target Branch dev
Depends On #131

🎯 Context & Goal

To compare invoice due dates against on-chain Stellar time, backend services need to fetch the latest closed ledger timestamp from Horizon / Soroban RPC rather than relying on local server system time.

This issue adds fetchLatestLedgerTimestamp(): Promise to src/services/stellar/horizon-client.service.ts.

πŸ“‚ Target Files

  • src/services/stellar/horizon-client.service.ts -> Fetch ledger timestamp helper

πŸ“‹ Implementation Tasks

  • Implement fetchLatestLedgerTimestamp() using Horizon Server.ledgers().order("desc").limit(1).call()
  • Extract closed_at ISO timestamp string and convert to Unix epoch seconds
  • Add unit tests mocking Horizon ledgers response

πŸ› οΈ Technical Guidance

const ledgers = await server.ledgers().order('desc').limit(1).call();
return Math.floor(new Date(ledgers.records[0].closed_at).getTime() / 1000);

πŸ”— References & Related

  • Stellar Horizon API Ledgers Endpoint

⏳ Delivery Window

This issue should be completed within 2 day(s) of assignment.

Contribution Workflow

  1. Branch off dev: git checkout -b feature/descriptive-name dev
  2. Implement all tasks in the checklist above.
  3. Run all CI checks locally (see DEVELOPMENT.md).
  4. Open a Pull Request targeting dev.
  5. Link this issue in your PR description: Closes #XX.

βœ… Acceptance Criteria

  • All implementation tasks above are completed.
  • Code compiles/builds without errors.
  • All existing tests continue to pass.
  • New tests are added with >80% coverage of new code.
  • Code follows project style guidelines (formatting, linting).
  • PR targets dev branch (NOT main).
  • PR description references this issue.
  • Documentation is updated if public API changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programeasySmall scope / straightforwardgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions