@@ -5,49 +5,18 @@ package ethereum
5
5
6
6
import (
7
7
"context"
8
- "sync"
9
8
10
9
etypes "github.com/ethereum/go-ethereum/core/types"
11
- "golang.org/x/sync/errgroup"
10
+ "github.com/ethereum/go-ethereum/rpc"
11
+ log "github.com/sirupsen/logrus"
12
12
)
13
13
14
- const receiptFetchBatchSize int = 10
15
-
16
- // Fetch all receipts for the given block in batches of `receiptFetchBatchSize`
14
+ // GetAllReceipts fetches all the transaction receipts in the given block.
17
15
func GetAllReceipts (ctx context.Context , conn * Connection , block * etypes.Block ) (etypes.Receipts , error ) {
18
- transactions := block .Body ().Transactions
19
- numTransactions := len (transactions )
20
- receiptsByIndex := sync.Map {}
21
-
22
- for i := 0 ; i < numTransactions ; i += receiptFetchBatchSize {
23
- eg , ctx := errgroup .WithContext (ctx )
24
- upper := i + receiptFetchBatchSize
25
- if upper >= numTransactions {
26
- upper = numTransactions
27
- }
28
- for j , tx := range transactions [i :upper ] {
29
- index := i + j
30
- txHash := tx .Hash ()
31
- eg .Go (func () error {
32
- receipt , err := conn .client .TransactionReceipt (ctx , txHash )
33
- if err != nil {
34
- return err
35
- }
36
- receiptsByIndex .Store (index , receipt )
37
- return nil
38
- })
39
- }
40
- err := eg .Wait ()
41
- if err != nil {
42
- return nil , err
43
- }
44
- }
45
-
46
- // Place receipts in same order as corresponding transactions
47
- receipts := make ([]* etypes.Receipt , numTransactions )
48
- receiptsByIndex .Range (func (index interface {}, receipt interface {}) bool {
49
- receipts [index .(int )] = receipt .(* etypes.Receipt )
50
- return true
51
- })
52
- return receipts , nil
16
+ blockHash := block .Hash ()
17
+ log .WithFields (log.Fields {
18
+ "numTransactions" : len (block .Body ().Transactions ),
19
+ "blockHash" : blockHash ,
20
+ }).Debug ("Querying transaction receipts" )
21
+ return conn .client .BlockReceipts (ctx , rpc .BlockNumberOrHashWithHash (blockHash , false ))
53
22
}
0 commit comments