Skip to content

Add missing fields to rpc Server.getLatestLedger response#1389

Merged
Ryang-21 merged 7 commits intomasterfrom
add-missing-fields-get-latest-ledger
Apr 17, 2026
Merged

Add missing fields to rpc Server.getLatestLedger response#1389
Ryang-21 merged 7 commits intomasterfrom
add-missing-fields-get-latest-ledger

Conversation

@Ryang-21
Copy link
Copy Markdown
Contributor

What

  • rpc.Server.getLatestLedger() now includes closeTime, headerXdr, and metadataXdr in the typed response, with headerXdr/metadataXdr parsed into XDR objects instead of raw base64 strings.

Copilot AI review requested due to automatic review settings April 16, 2026 20:39
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Apr 16, 2026
@Ryang-21 Ryang-21 requested a review from quietbits April 16, 2026 20:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates rpc.Server.getLatestLedger() to return a richer, parsed response object (including additional fields and decoded XDR) instead of the raw RPC payload.

Changes:

  • Added parsing logic for getLatestLedger to decode headerXdr/metadataXdr into XDR objects.
  • Introduced a raw response type and a raw _getLatestLedger() method.
  • Updated unit tests to validate the new parsed response shape and adjust mocks used by other tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/unit/server/soroban/get_latest_ledger.test.ts Updates expectations to match parsed getLatestLedger response, including XDR decoding.
test/unit/server/soroban/get_classic_entries.test.ts Adjusts HTTP mocks to handle getLatestLedger being called (e.g., via getAssetBalance).
src/rpc/server.ts Routes getLatestLedger() through a new parser and adds _getLatestLedger() for raw access.
src/rpc/parsers.ts Adds parseRawLatestLedger to decode XDR and shape the typed response.
src/rpc/api.ts Extends GetLatestLedgerResponse and adds RawGetLatestLedgerResponse typing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/rpc/api.ts Outdated
Comment on lines +57 to +59
/** a base-64 encoded {@link xdr.LedgerHeaderHistoryEntry} instance */
headerXdr: xdr.LedgerHeader;
/** a base-64 encoded {@link xdr.LedgerCloseMeta} instance */
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

GetLatestLedgerResponse JSDoc/typing is internally inconsistent: the comments say headerXdr/metadataXdr are base64-encoded XDR strings (and even reference xdr.LedgerHeaderHistoryEntry), but the types are parsed XDR objects (xdr.LedgerHeader / xdr.LedgerCloseMeta). Please update the docs to match the actual types (and ensure the referenced XDR type matches what parseRawLatestLedger returns).

Suggested change
/** a base-64 encoded {@link xdr.LedgerHeaderHistoryEntry} instance */
headerXdr: xdr.LedgerHeader;
/** a base-64 encoded {@link xdr.LedgerCloseMeta} instance */
/** a parsed {@link xdr.LedgerHeader} instance */
headerXdr: xdr.LedgerHeader;
/** a parsed {@link xdr.LedgerCloseMeta} instance */

Copilot uses AI. Check for mistakes.
Comment thread src/rpc/parsers.ts Outdated
raw: Api.RawGetLatestLedgerResponse,
): Api.GetLatestLedgerResponse {
if (!raw.headerXdr || !raw.metadataXdr) {
throw new TypeError(`invalid response missing fields`);
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

parseRawLatestLedger throws a generic invalid response missing fields error when headerXdr/metadataXdr are absent. For debugging, please include which field(s) are missing (similar to parseRawLedger) and ideally mention the RPC method/response type in the message.

Suggested change
throw new TypeError(`invalid response missing fields`);
let missingFields: string;
if (!raw.metadataXdr && !raw.headerXdr) {
missingFields = "metadataXdr and headerXdr";
} else if (!raw.metadataXdr) {
missingFields = "metadataXdr";
} else {
missingFields = "headerXdr";
}
throw new TypeError(
`invalid getLatestLedger response missing fields: ${missingFields}`,
);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This suggestion returns a better error for the user

@@ -23,12 +24,25 @@ describe("Server#getLatestLedger", () => {
id: "hashed_id",
sequence: 123,
protocolVersion: 20,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

Type mismatch: Api.RawGetLatestLedgerResponse.protocolVersion is declared as a string, but this mock response uses a number (20). This makes it easy for runtime/type drift to slip through—either update the mock to a string value or adjust the API types/parsing if the RPC actually returns a number.

Suggested change
protocolVersion: 20,
protocolVersion: "20",

Copilot uses AI. Check for mistakes.
result: {
id: "hashed_id",
sequence: 123,
protocolVersion: 20,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

Type mismatch: Api.RawGetLatestLedgerResponse.protocolVersion is declared as a string, but this getLatestLedger mock returns a number (20). Consider using a string here (or updating the API types/parsing if the RPC response is numeric) so tests validate the intended schema.

Suggested change
protocolVersion: 20,
protocolVersion: "20",

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We define protocolVersion as a string in GetLatestLedgerResponse. Is this using a different type?

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

Size Change: +75.7 kB (+0.17%)

Total Size: 45.7 MB

📦 View Changed
Filename Size Change
dist/stellar-sdk-minimal.js 6.05 MB +12.5 kB (+0.21%)
dist/stellar-sdk-minimal.min.js 5.14 MB +6.4 kB (+0.12%)
dist/stellar-sdk-no-axios.js 6.05 MB +12.5 kB (+0.21%)
dist/stellar-sdk-no-axios.min.js 5.14 MB +6.4 kB (+0.12%)
dist/stellar-sdk-no-eventsource.js 6.32 MB +12.5 kB (+0.2%)
dist/stellar-sdk-no-eventsource.min.js 5.36 MB +6.4 kB (+0.12%)
dist/stellar-sdk.js 6.32 MB +12.5 kB (+0.2%)
dist/stellar-sdk.min.js 5.36 MB +6.4 kB (+0.12%)

compressed-size-action

Comment thread CHANGELOG.md Outdated
## Unreleased

### Added
* Added
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: finish adding added 😉

Comment thread src/rpc/parsers.ts Outdated
raw: Api.RawGetLatestLedgerResponse,
): Api.GetLatestLedgerResponse {
if (!raw.headerXdr || !raw.metadataXdr) {
throw new TypeError(`invalid response missing fields`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This suggestion returns a better error for the user

result: {
id: "hashed_id",
sequence: 123,
protocolVersion: 20,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We define protocolVersion as a string in GetLatestLedgerResponse. Is this using a different type?

@Ryang-21 Ryang-21 merged commit 8db146e into master Apr 17, 2026
10 checks passed
@Ryang-21 Ryang-21 deleted the add-missing-fields-get-latest-ledger branch April 17, 2026 17:29
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants