| 52 | } |
| 53 | |
| 54 | func (qe *EvmQueryExecutor) shimQueryTransactions(ctx context.Context, req *evm.QueryTransactionsRequest, fromBlock, toBlock uint64, onPage func(proto.Message) error) error { |
| 55 | _, shimSpan := common.StartDetailSpan(ctx, "Query.ShimTransactions") |
| 56 | defer shimSpan.End() |
| 57 | |
| 58 | order := req.GetOrder() |
| 59 | limit := queryLimit(req.GetLimit()) |
| 60 | qe.logger.Debug().Uint64("fromBlock", fromBlock).Uint64("toBlock", toBlock).Uint32("limit", limit).Msgf("starting shimQueryTransactions") |
| 61 | |
| 62 | txs := make([]*evm.Transaction, 0, limit) |
| 63 | blocks := make([]*evm.BlockHeader, 0) |
| 64 | var lastIncluded *evm.BlockHeader |
| 65 | var hasMore bool |
| 66 | iter := newBlockIterator(fromBlock, toBlock, order) |
| 67 | for iter.Next() { |
| 68 | header, blockTxs, err := qe.fetchBlockViaForward(ctx, iter.Value(), true) |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | if header == nil { |
| 73 | continue |
| 74 | } |
| 75 | matched := make([]*evm.Transaction, 0) |
| 76 | for _, tx := range blockTxs { |
| 77 | if matchTransactionFilter(tx, req.Filter) { |
| 78 | matched = append(matched, projectTransactionForResponse(tx, req.TransactionFields)) |
| 79 | } |
| 80 | } |
| 81 | if len(matched) == 0 { |
| 82 | continue |
| 83 | } |
| 84 | if len(txs) > 0 && len(txs)+len(matched) > int(limit) { |
| 85 | hasMore = true |
| 86 | break |
| 87 | } |
| 88 | txs = append(txs, matched...) |
| 89 | if req.BlockFields != nil { |
| 90 | blocks = append(blocks, projectBlockForResponse(header, req.BlockFields)) |
| 91 | } |
| 92 | lastIncluded = header |
| 93 | if len(txs) >= int(limit) { |
| 94 | hasMore = iter.HasMore() |
| 95 | break |
| 96 | } |
| 97 | } |
| 98 | var cursor *evm.CursorBlock |
| 99 | if hasMore && lastIncluded != nil { |
| 100 | cursor = cursorFromBlock(lastIncluded) |
| 101 | } |
| 102 | return onPage(&evm.QueryTransactionsResponse{ |
| 103 | Transactions: txs, |
| 104 | Blocks: blocks, |
| 105 | FromBlock: cursorFromNumber(fromBlock), |
| 106 | ToBlock: cursorFromNumber(toBlock), |
| 107 | CursorBlock: cursor, |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | func (qe *EvmQueryExecutor) shimQueryLogs(ctx context.Context, req *evm.QueryLogsRequest, fromBlock, toBlock uint64, onPage func(proto.Message) error) error { |