@@ -129,8 +129,8 @@ func getHeightFromEntry(field string, value []byte) (uint64, error) {
129
129
}
130
130
131
131
type blockFilter struct { // needs this for the Filter interface
132
- start int64
133
- end int64
132
+ max int64
133
+ min int64
134
134
field string //need this field for differentiation between getting headers and getting data
135
135
}
136
136
@@ -139,17 +139,17 @@ func (f *blockFilter) Filter(e dsq.Entry) bool {
139
139
if err != nil {
140
140
return false
141
141
}
142
- return height >= uint64 (f .end ) && height <= uint64 (f .start )
142
+ return height >= uint64 (f .min ) && height <= uint64 (f .max )
143
143
}
144
144
145
- func BlockIterator (start int64 , end int64 ) []BlockResponse {
145
+ func BlockIterator (ctx context. Context , max int64 , min int64 ) []BlockResponse {
146
146
var blocks []BlockResponse
147
147
ds , ok := env .Adapter .RollkitStore .(ds.Batching )
148
148
if ! ok {
149
149
return blocks
150
150
}
151
- filterData := & blockFilter {start : start , end : end , field : "data" }
152
- filterHeader := & blockFilter {start : start , end : end , field : "header" }
151
+ filterData := & blockFilter {max : max , min : min , field : "data" }
152
+ filterHeader := & blockFilter {max : max , min : min , field : "header" }
153
153
154
154
// we need to do two queries, one for the block header and one for the block data
155
155
qHeader := dsq.Query {
@@ -162,11 +162,11 @@ func BlockIterator(start int64, end int64) []BlockResponse {
162
162
}
163
163
qData .Filters = append (qData .Filters , filterData )
164
164
165
- rHeader , err := ds .Query (context . Background () , qHeader )
165
+ rHeader , err := ds .Query (ctx , qHeader )
166
166
if err != nil {
167
167
return blocks
168
168
}
169
- rData , err := ds .Query (context . Background () , qData )
169
+ rData , err := ds .Query (ctx , qData )
170
170
if err != nil {
171
171
return blocks
172
172
}
@@ -175,18 +175,24 @@ func BlockIterator(start int64, end int64) []BlockResponse {
175
175
176
176
//we need to match the data to the header using the height, for that we use a map
177
177
headerMap := make (map [uint64 ]* rlktypes.SignedHeader )
178
- for h := range rHeader .Next () {
178
+ for res := range rHeader .Next () {
179
+ if res .Error != nil {
180
+ continue
181
+ }
179
182
header := new (rlktypes.SignedHeader )
180
- if err := header .UnmarshalBinary (h .Value ); err != nil {
183
+ if err := header .UnmarshalBinary (res .Value ); err != nil {
181
184
continue
182
185
}
183
186
headerMap [header .Height ()] = header
184
187
}
185
188
186
189
dataMap := make (map [uint64 ]* rlktypes.Data )
187
- for d := range rData .Next () {
190
+ for res := range rData .Next () {
191
+ if res .Error != nil {
192
+ continue
193
+ }
188
194
data := new (rlktypes.Data )
189
- if err := data .UnmarshalBinary (d .Value ); err != nil {
195
+ if err := data .UnmarshalBinary (res .Value ); err != nil {
190
196
continue
191
197
}
192
198
dataMap [data .Height ()] = data
0 commit comments