(recv func() (proto.Message, error), onPage func(proto.Message) error, method string, upstreamId string)
| 122 | } |
| 123 | |
| 124 | func (qe *EvmQueryExecutor) recvProtoStream(recv func() (proto.Message, error), onPage func(proto.Message) error, method string, upstreamId string) error { |
| 125 | type cursorPage interface { |
| 126 | proto.Message |
| 127 | GetCursorBlock() *evm.CursorBlock |
| 128 | } |
| 129 | |
| 130 | var lastCursor *evm.CursorBlock |
| 131 | pageEmitted := false |
| 132 | pageCount := 0 |
| 133 | |
| 134 | for { |
| 135 | page, err := recv() |
| 136 | if err == io.EOF { |
| 137 | qe.logger.Debug().Str("upstreamId", upstreamId).Str("method", method).Int("pagesReceived", pageCount).Msgf("upstream query stream completed (EOF)") |
| 138 | return nil |
| 139 | } |
| 140 | if err != nil { |
| 141 | qe.logger.Debug().Err(err).Str("upstreamId", upstreamId).Str("method", method).Int("pagesReceived", pageCount).Bool("pageEmitted", pageEmitted).Msgf("upstream query stream error") |
| 142 | return &StreamError{Err: err, LastCursor: lastCursor, PageEmitted: pageEmitted} |
| 143 | } |
| 144 | |
| 145 | pageCount++ |
| 146 | cursorBlock := (*evm.CursorBlock)(nil) |
| 147 | if cursorAware, ok := any(page).(cursorPage); ok { |
| 148 | cursorBlock = cursorAware.GetCursorBlock() |
| 149 | if cursorBlock != nil { |
| 150 | lastCursor = cursorBlock |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | qe.logger.Trace().Str("upstreamId", upstreamId).Str("method", method).Int("page", pageCount).Interface("cursor", cursorBlock).Msgf("received page from upstream query stream") |
| 155 | |
| 156 | if err := onPage(page); err != nil { |
| 157 | return &StreamError{Err: err, LastCursor: lastCursor, PageEmitted: true} |
| 158 | } |
| 159 | pageEmitted = true |
| 160 | |
| 161 | if cursorBlock == nil { |
| 162 | qe.logger.Debug().Str("upstreamId", upstreamId).Str("method", method).Int("pagesReceived", pageCount).Msgf("upstream query stream completed (no cursor)") |
| 163 | return nil |
| 164 | } |
| 165 | } |
| 166 | } |
no test coverage detected