Skip to content

Commit

Permalink
Revert "update change in receipt indexer api"
Browse files Browse the repository at this point in the history
This reverts commit 2105329.
  • Loading branch information
Gregor Gololicic committed Jan 30, 2024
1 parent e8e8086 commit fb3f275
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions storage/memory/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type baseStorage struct {
firstHeight uint64
lastHeight uint64

receiptsTxIDs map[common.Hash]*gethTypes.Receipt
receiptBlockHeightTxID map[*big.Int]common.Hash
bloomHeight map[*big.Int]gethTypes.Bloom
receiptsTxIDs map[common.Hash]*gethTypes.Receipt
receiptBlockIDTxIDs map[common.Hash]common.Hash
bloomHeight map[int64]gethTypes.Bloom

transactionsIDs map[common.Hash]*gethTypes.Transaction
}
Expand All @@ -36,14 +36,14 @@ var store *baseStorage
func baseStorageFactory() *baseStorage {
if store == nil {
store = &baseStorage{
blocksIDs: make(map[common.Hash]*types.Block),
blockHeightsIDs: make(map[uint64]common.Hash),
firstHeight: unknownHeight,
lastHeight: unknownHeight,
receiptsTxIDs: make(map[common.Hash]*gethTypes.Receipt),
receiptBlockHeightTxID: make(map[*big.Int]common.Hash),
bloomHeight: make(map[*big.Int]gethTypes.Bloom),
transactionsIDs: make(map[common.Hash]*gethTypes.Transaction),
blocksIDs: make(map[common.Hash]*types.Block),
blockHeightsIDs: make(map[uint64]common.Hash),
firstHeight: unknownHeight,
lastHeight: unknownHeight,
receiptsTxIDs: make(map[common.Hash]*gethTypes.Receipt),
receiptBlockIDTxIDs: make(map[common.Hash]common.Hash),
bloomHeight: make(map[int64]gethTypes.Bloom),
transactionsIDs: make(map[common.Hash]*gethTypes.Transaction),
}
}
return store
Expand Down Expand Up @@ -169,8 +169,13 @@ func (r ReceiptStorage) Store(receipt *gethTypes.Receipt) error {
}

r.base.receiptsTxIDs[receipt.TxHash] = receipt
r.base.receiptBlockHeightTxID[receipt.BlockNumber] = receipt.TxHash
r.base.bloomHeight[receipt.BlockNumber] = receipt.Bloom
r.base.receiptBlockIDTxIDs[receipt.BlockHash] = receipt.TxHash

if _, ok := r.base.bloomHeight[receipt.BlockNumber.Int64()]; ok {
return errors.Duplicate
}

r.base.bloomHeight[receipt.BlockNumber.Int64()] = receipt.Bloom

return nil
}
Expand All @@ -187,11 +192,11 @@ func (r ReceiptStorage) GetByTransactionID(ID common.Hash) (*gethTypes.Receipt,
return receipt, nil
}

func (r ReceiptStorage) GetByBlockHeight(height *big.Int) (*gethTypes.Receipt, error) {
func (r ReceiptStorage) GetByBlockID(ID common.Hash) (*gethTypes.Receipt, error) {
r.base.mu.RLock()
defer r.base.mu.RUnlock()

txID, exists := r.base.receiptBlockHeightTxID[height]
txID, exists := r.base.receiptBlockIDTxIDs[ID]
if !exists {
return nil, errors.NotFound
}
Expand All @@ -208,15 +213,14 @@ func (r ReceiptStorage) BloomsForBlockRange(start, end *big.Int) ([]*gethTypes.B
r.base.mu.RLock()
defer r.base.mu.RUnlock()

// make sure start is not bigger than end
if start.Cmp(end) > 0 {
if start.Cmp(end) > -1 {
return nil, errors.InvalidRange
}

blooms := make([]*gethTypes.Bloom, 0)

// Iterate through the range of block heights and add the blooms to the result
for i := start.Int64(); i <= end.Int64(); i++ {
for i := start.Int64(); i < end.Int64(); i++ {
b, exists := r.base.bloomHeight[i]
if exists {
blooms = append(blooms, &b)
Expand Down

0 comments on commit fb3f275

Please sign in to comment.