@@ -84,17 +84,38 @@ proc getReceipts*(
84
84
85
85
await vp.getReceipts(header, numberTag)
86
86
87
+ proc verifyFilterBoundaries* (
88
+ filter: FilterOptions, logObjs: seq [LogObject]
89
+ ) : Result[bool , string ] =
90
+ let
91
+ fromBlock = filter.fromBlock.get(
92
+ BlockTag(kind: BlockIdentifierKind.bidAlias, alias: " latest" )
93
+ )
94
+ toBlock =
95
+ filter.toBlock.get(BlockTag(kind: BlockIdentifierKind.bidAlias, alias: " latest" ))
96
+
97
+ bottom =
98
+ if fromBlock.kind == BlockIdentifierKind.bidNumber:
99
+ fromBlock.number
100
+ else :
101
+ return err(" Cannot verify boundaries for block tags in 'fromBlock' field" )
102
+ top =
103
+ if toBlock.kind == BlockIdentifierKind.bidNumber:
104
+ toBlock.number
105
+ else :
106
+ return err(" Cannot verify boundaries for block tags in 'toBlock' field" )
107
+
108
+ for lg in logObjs:
109
+ if lg.blockNumber.isSome:
110
+ if lg.blockNumber.get < bottom or lg.blockNumber.get > top:
111
+ return ok(false )
112
+
113
+ return ok(true )
114
+
87
115
proc verifyLogs* (
88
116
vp: VerifiedRpcProxy, logObjs: seq [LogObject]
89
117
) : Future[Result[seq [LogObject], string ]] {.async.} =
90
- let
91
- fromBlock = filter.fromBlock.get(BlockTag(kind:BlockIdentifierKind.bidAlias, alias: " latest" ))
92
- toBlock = filter.toBlock.get(BlockTag(kind:BlockIdentifierKind.bidAlias, alias: " latest" ))
93
-
94
- bottom = if fromBlock.kind == BlockIdentifierKind.bidNumber: fromBlock.number
95
- else : return err(" Cannot verify boundaries for block tags in 'fromBlock' field" )
96
- top = if toBlock.kind == BlockIdentifierKind.bidNumber: toBlock.number
97
- else : return err(" Cannot verify boundaries for block tags in 'toBlock' field" )
118
+ var res = newSeq[LogObject]()
98
119
99
120
# store block hashes contains the logs so that we can batch receipt requests
100
121
var
@@ -103,7 +124,7 @@ proc verifyLogs*(
103
124
104
125
for lg in logObjs:
105
126
# none only for pending logs before block is built
106
- if lg.blockNumber.isSome() and lg. blockHash.isSome() and lg.transactionIndex.isSome() and lg.logIndex.isSome():
127
+ if lg.blockHash.isSome() and lg.transactionIndex.isSome() and lg.logIndex.isSome():
107
128
# exploit sequentiality of logs
108
129
if prevBlockHash != lg.blockHash.get():
109
130
# TODO: a cache will solve downloading the same block receipts for multiple logs
@@ -119,7 +140,7 @@ proc verifyLogs*(
119
140
120
141
if rxLog.address != lg.address or rxLog.data != lg.data or
121
142
rxLog.topics != lg.topics or
122
- (not match(toLog(lg), filterOptions.address, filterOptions.topics)) or lg.blockNumber.get < bottom or lg.blockNumber.get > top :
143
+ (not match(toLog(lg), filterOptions.address, filterOptions.topics)):
123
144
return err(" one of the returned logs is invalid" )
124
145
125
146
return ok(logObjs)
0 commit comments