From 1bd519a4f22d150047b13712c10d6a6e9f81017d Mon Sep 17 00:00:00 2001 From: Anjor Kanekar Date: Fri, 15 Nov 2024 10:16:50 +0000 Subject: [PATCH] gsfa reader for slot range (#184) * gsfa reader for slot range * use calc epoch * minor --- multiepoch-getSignaturesForAddress.go | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/multiepoch-getSignaturesForAddress.go b/multiepoch-getSignaturesForAddress.go index d51dcdb3..b6ad8e49 100644 --- a/multiepoch-getSignaturesForAddress.go +++ b/multiepoch-getSignaturesForAddress.go @@ -42,6 +42,39 @@ func (ser *MultiEpoch) getGsfaReadersInEpochDescendingOrder() ([]*gsfa.GsfaReade return gsfaReaders, epochNums } +// getGsfaReadersInEpochDescendingOrder returns a list of gsfa readers in epoch order (from most recent to oldest). +func (ser *MultiEpoch) getGsfaReadersInEpochDescendingOrderForSlotRange(ctx context.Context, startSlot, endSlot uint64) ([]*gsfa.GsfaReader, []uint64) { + ser.mu.RLock() + defer ser.mu.RUnlock() + + startEpoch := CalcEpochForSlot(startSlot) + endEpoch := CalcEpochForSlot(endSlot) + + epochs := make([]*Epoch, 0, endEpoch-startEpoch+1) + for _, epoch := range ser.epochs { + + if epoch.Epoch() >= startEpoch && epoch.Epoch() <= endEpoch { + epochs = append(epochs, epoch) + } + } + + // sort epochs by epoch number (from biggest to smallest): + sort.Slice(epochs, func(i, j int) bool { + return epochs[i].epoch > epochs[j].epoch + }) + + gsfaReaders := make([]*gsfa.GsfaReader, 0, len(epochs)) + epochNums := make([]uint64, 0, len(epochs)) + for _, epoch := range epochs { + if epoch.gsfaReader != nil { + epoch.gsfaReader.SetEpoch(epoch.Epoch()) + gsfaReaders = append(gsfaReaders, epoch.gsfaReader) + epochNums = append(epochNums, epoch.Epoch()) + } + } + return gsfaReaders, epochNums +} + func countTransactions(v gsfa.EpochToTransactionObjects) int { var count int for _, txs := range v {