Skip to content

Commit

Permalink
Drop nonexisting endpoints and add /getledgerentryraw
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Sep 19, 2024
1 parent bff826e commit 48060ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
21 changes: 4 additions & 17 deletions clients/stellarcore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions clients/stellarcore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,33 @@ 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
acc, err := xdr.AddressToAccountId(keypair.MustRandom().Address())
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)
}
11 changes: 11 additions & 0 deletions protocols/stellarcore/getledgerentryraw_response.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 48060ec

Please sign in to comment.