Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension field to getLedgerEntries response #388

Open
wants to merge 1 commit into
base: protocol-23
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/stellar-rpc/internal/methods/get_ledger_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,15 @@ func ledgerKeyEntryToResult(keyEntry db.LedgerKeyAndEntry, format string) (proto
if err != nil {
return protocol.LedgerEntryResult{}, err
}
extJs, err := xdr2json.ConvertInterface(keyEntry.Entry.Ext)
if err != nil {
return protocol.LedgerEntryResult{}, err
}

result.KeyJSON = keyJs
result.DataJSON = entryJs
result.ExtensionJSON = extJs

default:
keyXDR, err := xdr.MarshalBase64(keyEntry.Key)
if err != nil {
Expand All @@ -273,9 +280,17 @@ func ledgerKeyEntryToResult(keyEntry db.LedgerKeyAndEntry, format string) (proto
return protocol.LedgerEntryResult{}, err
}

extXDR, err := xdr.MarshalBase64(keyEntry.Entry.Ext)
if err != nil {
err = fmt.Errorf("could not serialize ledger entry extension %v: %w", keyEntry.Entry.Ext, err)
return protocol.LedgerEntryResult{}, err
}

result.KeyXDR = keyXDR
result.DataXDR = entryXDR
result.ExtensionXDR = extXDR
}

result.LastModifiedLedger = uint32(keyEntry.Entry.LastModifiedLedgerSeq)
result.LiveUntilLedgerSeq = keyEntry.LiveUntilLedgerSeq
return result, nil
Expand Down
3 changes: 3 additions & 0 deletions protocol/get_ledger_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type LedgerEntryResult struct {
LastModifiedLedger uint32 `json:"lastModifiedLedgerSeq"`
// The ledger sequence until the entry is live, available for entries that have associated ttl ledger entries.
LiveUntilLedgerSeq *uint32 `json:"liveUntilLedgerSeq,omitempty"`
// Extension field for this entry, if any
ExtensionXDR string `json:"extXdr,omitempty"`
ExtensionJSON json.RawMessage `json:"extJson,omitempty"`
}

type GetLedgerEntriesResponse struct {
Expand Down
Loading