From 7928c783e65d3347651b5e4f1f9c481d5b1d1a48 Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Mon, 15 Apr 2024 14:21:26 -0400 Subject: [PATCH] Add getLedgers --- cmd/soroban-rpc/internal/db/ledger.go | 13 ++++++++++++- cmd/soroban-rpc/internal/transactions/cursor.go | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cmd/soroban-rpc/internal/db/ledger.go b/cmd/soroban-rpc/internal/db/ledger.go index a8676aa2..3be9671e 100644 --- a/cmd/soroban-rpc/internal/db/ledger.go +++ b/cmd/soroban-rpc/internal/db/ledger.go @@ -71,7 +71,18 @@ func (r ledgerReader) GetLedger(ctx context.Context, sequence uint32) (xdr.Ledge } func (r ledgerReader) GetLedgers(ctx context.Context, startSequence uint32, endSequence uint32) ([]xdr.LedgerCloseMeta, error) { - return []xdr.LedgerCloseMeta{}, nil + sql := sq.Select("meta"). + From(ledgerCloseMetaTableName). + Where( + sq.And{ + sq.GtOrEq{"sequence": startSequence}, + sq.LtOrEq{"sequence": endSequence}, + }) + var results []xdr.LedgerCloseMeta + if err := r.db.Select(ctx, &results, sql); err != nil { + return []xdr.LedgerCloseMeta{}, err + } + return results, nil } type ledgerWriter struct { diff --git a/cmd/soroban-rpc/internal/transactions/cursor.go b/cmd/soroban-rpc/internal/transactions/cursor.go index 8c1d2897..c88e8dc7 100644 --- a/cmd/soroban-rpc/internal/transactions/cursor.go +++ b/cmd/soroban-rpc/internal/transactions/cursor.go @@ -43,6 +43,21 @@ func (c Cursor) UnmarshalJSON(b []byte) error { // 1 is returned if c is greater than other. // -1 is returned if c is less than other. func (c Cursor) Cmp(other interfaces.Cursor) int { + otherCursor := other.(*Cursor) + + if c.LedgerSequence == otherCursor.LedgerSequence { + return cmp(c.TxIdx, otherCursor.TxIdx) + } + return cmp(c.LedgerSequence, otherCursor.LedgerSequence) +} + +func cmp(a, b uint32) int { + if a < b { + return -1 + } + if a > b { + return 1 + } return 0 }