diff --git a/clients/stellarcore/client.go b/clients/stellarcore/client.go index 0d4e4765da..d954e5fcf6 100644 --- a/clients/stellarcore/client.go +++ b/clients/stellarcore/client.go @@ -150,22 +150,9 @@ func (c *Client) SetCursor(ctx context.Context, id string, cursor int32) (err er return nil } - -func (c *Client) GetLedgerEntries(ctx context.Context, ledgerSeq uint32, keys ...xdr.LedgerKey) (proto.GetLedgerEntriesResponse, error) { - var resp proto.GetLedgerEntriesResponse - return resp, c.makeLedgerKeyRequest(ctx, &resp, "getledgerentry", ledgerSeq, keys...) -} - -//lint:ignore U1000 Ignore unused function until it's supported in Core -func (c *Client) getInvocationProof(ctx context.Context, ledgerSeq uint32, keys ...xdr.LedgerKey) (proto.ProofResponse, error) { - var resp proto.ProofResponse - return resp, c.makeLedgerKeyRequest(ctx, &resp, "getinvocationproof", ledgerSeq, keys...) -} - -//lint:ignore U1000 Ignore unused function until it's supported in Core -func (c *Client) getRestorationProof(ctx context.Context, ledgerSeq uint32, keys ...xdr.LedgerKey) (proto.ProofResponse, error) { - var resp proto.ProofResponse - return resp, c.makeLedgerKeyRequest(ctx, &resp, "getrestorationproof", ledgerSeq, keys...) +func (c *Client) GetLedgerEntryRaw(ctx context.Context, ledgerSeq uint32, keys ...xdr.LedgerKey) (proto.GetLedgerEntryRawResponse, error) { + var resp proto.GetLedgerEntryRawResponse + return resp, c.makeLedgerKeyRequest(ctx, &resp, "getledgerentryraw", ledgerSeq, keys...) } // SubmitTransaction calls the `tx` command on the connected stellar core with the provided envelope @@ -333,7 +320,7 @@ func (c *Client) rawPost( } // makeLedgerKeyRequest is a generic method to perform a request in the form -// `key=...&key=...&ledgerSeq=...` which is useful because three Stellar Core +// `key=...&key=...&ledgerSeq=...` which is useful because several Stellar Core // endpoints all use this request format. Be sure to pass `target` by reference. func (c *Client) makeLedgerKeyRequest( ctx context.Context, diff --git a/clients/stellarcore/client_test.go b/clients/stellarcore/client_test.go index aa068610b1..7f6b01983a 100644 --- a/clients/stellarcore/client_test.go +++ b/clients/stellarcore/client_test.go @@ -84,22 +84,20 @@ func TestGetLedgerEntries(t *testing.T) { c := &Client{HTTP: hmock, URL: "http://localhost:11626"} // build a fake response body - mockResp := proto.GetLedgerEntriesResponse{ + mockResp := proto.GetLedgerEntryRawResponse{ Ledger: 1215, // checkpoint align on expected request - Entries: []proto.LedgerEntryResponse{ + Entries: []proto.RawLedgerEntryResponse{ { Entry: "pretend this is XDR lol", - State: proto.DeadState, }, { Entry: "pretend this is another XDR lol", - State: proto.ArchivedStateNoProof, }, }, } // happy path - fetch an entry - hmock.On("POST", "http://localhost:11626/getledgerentry"). + hmock.On("POST", "http://localhost:11626/getledgerentryraw"). ReturnJSON(http.StatusOK, &mockResp) var key xdr.LedgerKey @@ -107,12 +105,12 @@ func TestGetLedgerEntries(t *testing.T) { require.NoError(t, err) key.SetAccount(acc) - resp, err := c.GetLedgerEntries(context.Background(), 1234, key) + resp, err := c.GetLedgerEntryRaw(context.Background(), 1234, key) require.NoError(t, err) require.NotNil(t, resp) require.EqualValues(t, 1215, resp.Ledger) require.Len(t, resp.Entries, 2) - require.Equal(t, resp.Entries[0].State, proto.DeadState) - require.Equal(t, resp.Entries[1].State, proto.ArchivedStateNoProof) + require.Equal(t, "pretend this is XDR lol", resp.Entries[0].Entry) + require.Equal(t, "pretend this is another XDR lol", resp.Entries[1].Entry) } diff --git a/protocols/stellarcore/getledgerentryraw_response.go b/protocols/stellarcore/getledgerentryraw_response.go new file mode 100644 index 0000000000..f4d31a635f --- /dev/null +++ b/protocols/stellarcore/getledgerentryraw_response.go @@ -0,0 +1,11 @@ +package stellarcore + +// GetLedgerEntryRawResponse is the structure of Stellar Core's /getledgerentryraw +type GetLedgerEntryRawResponse struct { + Ledger uint32 `json:"ledger"` + Entries []RawLedgerEntryResponse `json:"entries"` +} + +type RawLedgerEntryResponse struct { + Entry string `json:"le"` // base64-encoded xdr.LedgerEntry +}