2022-03-23 15:20:07 +02:00
|
|
|
{.push raises: [Defect].}
|
2020-12-01 11:57:54 +02:00
|
|
|
|
2020-11-24 05:44:37 +02:00
|
|
|
import
|
|
|
|
std/options,
|
2021-06-09 16:37:08 +02:00
|
|
|
chronicles,
|
2022-07-25 13:01:37 +02:00
|
|
|
json_rpc/rpcserver
|
|
|
|
import
|
2020-11-24 05:44:37 +02:00
|
|
|
../wakunode2,
|
2022-07-25 13:01:37 +02:00
|
|
|
../../protocol/waku_store,
|
2022-02-17 16:00:15 +01:00
|
|
|
../../utils/time,
|
2022-07-25 13:01:37 +02:00
|
|
|
../../utils/pagination,
|
|
|
|
./jsonrpc_types,
|
|
|
|
./jsonrpc_utils
|
2020-11-24 05:44:37 +02:00
|
|
|
|
2020-12-23 11:33:28 +02:00
|
|
|
export jsonrpc_types
|
|
|
|
|
2021-03-23 10:04:51 +02:00
|
|
|
logScope:
|
|
|
|
topics = "store api"
|
|
|
|
|
2020-11-27 09:18:48 +02:00
|
|
|
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
2020-11-24 05:44:37 +02:00
|
|
|
const futTimeout = 5.seconds
|
|
|
|
|
|
|
|
## Store API version 1 definitions
|
|
|
|
|
2022-02-17 16:00:15 +01:00
|
|
|
rpcsrv.rpc("get_waku_v2_store_v1_messages") do(pubsubTopicOption: Option[string], contentFiltersOption: Option[seq[HistoryContentFilter]], startTime: Option[Timestamp], endTime: Option[Timestamp], pagingOptions: Option[StorePagingOptions]) -> StoreResponse:
|
2020-11-24 05:44:37 +02:00
|
|
|
## Returns history for a list of content topics with optional paging
|
|
|
|
debug "get_waku_v2_store_v1_messages"
|
|
|
|
|
|
|
|
var responseFut = newFuture[StoreResponse]()
|
|
|
|
|
|
|
|
proc queryFuncHandler(response: HistoryResponse) {.gcsafe, closure.} =
|
|
|
|
debug "get_waku_v2_store_v1_messages response"
|
|
|
|
responseFut.complete(response.toStoreResponse())
|
|
|
|
|
2021-05-03 12:25:28 -07:00
|
|
|
let historyQuery = HistoryQuery(pubsubTopic: if pubsubTopicOption.isSome: pubsubTopicOption.get() else: "",
|
|
|
|
contentFilters: if contentFiltersOption.isSome: contentFiltersOption.get() else: @[],
|
2022-02-17 16:00:15 +01:00
|
|
|
startTime: if startTime.isSome: startTime.get() else: Timestamp(0),
|
|
|
|
endTime: if endTime.isSome: endTime.get() else: Timestamp(0),
|
2020-11-24 05:44:37 +02:00
|
|
|
pagingInfo: if pagingOptions.isSome: pagingOptions.get.toPagingInfo() else: PagingInfo())
|
|
|
|
|
|
|
|
await node.query(historyQuery, queryFuncHandler)
|
|
|
|
|
|
|
|
if (await responseFut.withTimeout(futTimeout)):
|
|
|
|
# Future completed
|
|
|
|
return responseFut.read()
|
|
|
|
else:
|
|
|
|
# Future failed to complete
|
2021-04-23 14:14:40 -07:00
|
|
|
raise newException(ValueError, "No history response received")
|