update logs oracle (#379)
This commit is contained in:
@@ -33,12 +33,24 @@ class LogsOracle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun estimate(
|
fun estimate(
|
||||||
|
limit: Long?,
|
||||||
fromBlock: Long,
|
fromBlock: Long,
|
||||||
toBlock: Long,
|
toBlock: Long,
|
||||||
address: List<String>,
|
address: List<String>,
|
||||||
topics: List<List<String>>,
|
topics: List<List<String>>,
|
||||||
): Mono<Long> {
|
): Mono<String> {
|
||||||
return Mono.fromCallable { db.Query(fromBlock, toBlock, address, topics) }
|
return Mono.fromCallable {
|
||||||
|
try {
|
||||||
|
val estimate = db.Query(limit, fromBlock, toBlock, address, topics)
|
||||||
|
"{\"total\":$estimate,\"overflow\":false}"
|
||||||
|
} catch (e: org.drpc.logsoracle.LogsOracle.LogsOracleException) {
|
||||||
|
if (e.isQueryOverflow()) {
|
||||||
|
"{\"total\":\"-1\",\"overflow\":true}"
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.subscribeOn(scheduler)
|
.subscribeOn(scheduler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,10 @@ class EthereumLocalReader(
|
|||||||
|
|
||||||
val req = params[0] as LinkedHashMap<String, Any?>
|
val req = params[0] as LinkedHashMap<String, Any?>
|
||||||
|
|
||||||
|
val limit = try { req.get("limit") as Integer? } catch (_: IllegalArgumentException) {
|
||||||
|
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'limit' parameter")
|
||||||
|
}
|
||||||
|
|
||||||
val fromBlock = try { parseBlockRef(req.get("fromBlock") as String?) } catch (_: IllegalArgumentException) {
|
val fromBlock = try { parseBlockRef(req.get("fromBlock") as String?) } catch (_: IllegalArgumentException) {
|
||||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'fromBlock' parameter")
|
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'fromBlock' parameter")
|
||||||
}
|
}
|
||||||
@@ -217,8 +221,8 @@ class EthereumLocalReader(
|
|||||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'topics' parameter")
|
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'topics' parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
return logsOracle.estimate(fromBlock, toBlock, address, topics)
|
return logsOracle.estimate(limit?.toLong() ?: null, fromBlock, toBlock, address, topics)
|
||||||
.map { "{\"result\":$it}".toByteArray() to null }
|
.map { it.toByteArray() to null }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseBlockRef(blockRef: String?): Long {
|
private fun parseBlockRef(blockRef: String?): Long {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user