Added more ledger details output by getLatestLedger endpoint#544
Added more ledger details output by getLatestLedger endpoint#544
Conversation
|
for the reference/convenience of anyone interested: |
protocol/get_latest_ledger.go
Outdated
| @@ -1,12 +1,24 @@ | |||
| package protocol | |||
|
|
|||
| import "encoding/json" | |||
There was a problem hiding this comment.
we moved the protocol package and the stellar-rpc client to the go sdk:
https://github.com/stellar/go-stellar-sdk/tree/master/protocols/rpc
https://github.com/stellar/go-stellar-sdk/tree/master/clients/rpcclient
I think we forgot to delete the code from the stellar-rpc repo. So, we will need to:
- delete the rpc client and protocols packages from the stellar-rpc repo
- update rpc codebase to use the client / protocols package from the go sdk
- create a PR in the go sdk repo to update the GetLatestLedgerResponse
There was a problem hiding this comment.
Great catch, will raise an issue about this!
There was a problem hiding this comment.
That's already done on the protocol-25 branch (see #527). This could retarget that branch and be released as part of that, or we can try to merge the branches but that'd probably be more painful.
protocol/get_latest_ledger.go
Outdated
| // LedgerHeader of the latest ledger (base64-encoded XDR) | ||
| LedgerHeader string `json:"header"` | ||
| // JSON representation of the latest ledger header | ||
| LedgerHeaderJSON json.RawMessage `json:"headerJson,omitempty"` | ||
| // LedgerMetadata of the latest ledger (base64-encoded XDR) | ||
| LedgerMetadata string `json:"metadata"` | ||
| // JSON representation of the latest ledger metadata | ||
| LedgerMetadataJSON json.RawMessage `json:"metadataJson,omitempty"` |
There was a problem hiding this comment.
I recommend dropping JSON support and just having base64 fields, but still suffixing them appropriately in case we want to introduce json later.
| // LedgerHeader of the latest ledger (base64-encoded XDR) | |
| LedgerHeader string `json:"header"` | |
| // JSON representation of the latest ledger header | |
| LedgerHeaderJSON json.RawMessage `json:"headerJson,omitempty"` | |
| // LedgerMetadata of the latest ledger (base64-encoded XDR) | |
| LedgerMetadata string `json:"metadata"` | |
| // JSON representation of the latest ledger metadata | |
| LedgerMetadataJSON json.RawMessage `json:"metadataJson,omitempty"` | |
| // LedgerHeader of the latest ledger (base64-encoded XDR) | |
| LedgerHeader string `json:"headerXdr"` | |
| // LedgerMetadata of the latest ledger (base64-encoded XDR) | |
| LedgerMetadata string `json:"metadataXdr"` |
| LedgerCloseTime: latestLedger.LedgerCloseTime(), | ||
| LedgerHeader: base64.StdEncoding.EncodeToString(headerBytes), | ||
| } | ||
| if LedgerHeaderJSON, err := json.Marshal(header); err == nil { |
There was a problem hiding this comment.
Nah you can't just call Marshal on this because it's an XDR structure, you'll almost certainly error out every time; that's what xdr2json is for. I recommend not having JSON-formatted fields in this endpoint at all tbh, because we'd then need to add xdrFormat: "json" | "base64" to the request itself to switch between them like with the other endpoints.
There was a problem hiding this comment.
oddly, this never error'd out on my testing of this (curling http://localhost:8000). still a great catch and indeed why xdr2json is there. becomes moot because I'm taking your advice to drop JSON support.
There was a problem hiding this comment.
the conditional relies on err == nil 😉 you were hiding the error case
|
|
||
| assert.Equal(t, expectedLatestLedgerProtocolVersion, latestLedgerResp.ProtocolVersion) | ||
| assert.Equal(t, expectedLatestLedgerSequence, latestLedgerResp.Sequence) | ||
| assert.Equal(t, int64(expectedLatestLedgerCloseTime), latestLedgerResp.LedgerCloseTime) |
There was a problem hiding this comment.
No tests for header/metadata equivalence?
There was a problem hiding this comment.
fixed in latest commit
MIGRATING THIS PR TO
protocol 25 branchWhat
See issue #79. Included more details to be output by the
getLatestLedgerendpoint such that it matches the info output bygetLedgers. The following fields are output:id: hash of the lastest ledgerprotocolVersion: Stellar Core protocol versionsequence: sequence number of the latest ledgercloseTime: time the latest ledger closedheader: base64 encoded ledger headerheaderJson: JSON representation of the latest ledger header (omitted if empty)metadata: base64 encoded representation of latest ledger metadatametadataJson: JSON representation of latest ledger metadata (omitted if empty)Why
The getLatestLedger endpoint should return all information about the ledger, but it previously only output
id,protocolVersion, andsequence.Known limitations
N/A.