2022-11-04 13:14:22 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
else:
|
|
|
|
|
{.push raises: [].}
|
2020-12-21 11:45:07 +00:00
|
|
|
|
|
|
|
|
import
|
|
|
|
|
std/options,
|
2021-06-09 14:59:52 +00:00
|
|
|
chronicles,
|
2022-08-01 11:31:00 +00:00
|
|
|
json_rpc/rpcserver
|
|
|
|
|
import
|
2022-10-28 18:43:17 +00:00
|
|
|
../peer_manager/peer_manager,
|
2022-10-18 14:46:26 +00:00
|
|
|
../waku_node,
|
2022-08-01 11:31:00 +00:00
|
|
|
../../protocol/waku_store,
|
2022-02-17 15:26:49 +00:00
|
|
|
../../utils/time,
|
2022-08-01 11:31:00 +00:00
|
|
|
./jsonrpc_types,
|
|
|
|
|
./jsonrpc_utils
|
2020-12-21 11:45:07 +00:00
|
|
|
|
2020-12-23 09:47:40 +00:00
|
|
|
export jsonrpc_types
|
|
|
|
|
|
2021-03-23 08:24:09 +00:00
|
|
|
logScope:
|
2022-11-03 16:14:45 +00:00
|
|
|
topics = "waku node jsonrpc store_api"
|
2021-03-23 08:24:09 +00:00
|
|
|
|
2020-12-21 11:45:07 +00:00
|
|
|
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
|
|
|
|
const futTimeout = 5.seconds
|
|
|
|
|
|
|
|
|
|
## Store API version 1 definitions
|
|
|
|
|
|
2022-10-28 18:43:17 +00: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-12-21 11:45:07 +00:00
|
|
|
## Returns history for a list of content topics with optional paging
|
|
|
|
|
debug "get_waku_v2_store_v1_messages"
|
|
|
|
|
|
2022-10-28 18:43:17 +00:00
|
|
|
let peerOpt = node.peerManager.selectPeer(WakuStoreCodec)
|
|
|
|
|
if peerOpt.isNone():
|
|
|
|
|
raise newException(ValueError, "no suitable remote store peers")
|
|
|
|
|
|
2021-05-03 19:49:34 +00:00
|
|
|
let historyQuery = HistoryQuery(pubsubTopic: if pubsubTopicOption.isSome: pubsubTopicOption.get() else: "",
|
|
|
|
|
contentFilters: if contentFiltersOption.isSome: contentFiltersOption.get() else: @[],
|
2022-02-17 15:26:49 +00:00
|
|
|
startTime: if startTime.isSome: startTime.get() else: Timestamp(0),
|
|
|
|
|
endTime: if endTime.isSome: endTime.get() else: Timestamp(0),
|
2020-12-21 11:45:07 +00:00
|
|
|
pagingInfo: if pagingOptions.isSome: pagingOptions.get.toPagingInfo() else: PagingInfo())
|
2022-10-28 18:43:17 +00:00
|
|
|
let queryFut = node.query(historyQuery, peerOpt.get())
|
2020-12-21 11:45:07 +00:00
|
|
|
|
2022-10-28 18:43:17 +00:00
|
|
|
if not await queryFut.withTimeout(futTimeout):
|
2022-09-21 17:03:54 +00:00
|
|
|
raise newException(ValueError, "No history response received (timeout)")
|
|
|
|
|
|
2022-10-28 18:43:17 +00:00
|
|
|
let res = queryFut.read()
|
2022-09-21 17:03:54 +00:00
|
|
|
if res.isErr():
|
2022-10-28 18:43:17 +00:00
|
|
|
raise newException(ValueError, $res.error)
|
2022-09-21 17:03:54 +00:00
|
|
|
|
|
|
|
|
debug "get_waku_v2_store_v1_messages response"
|
|
|
|
|
return res.value.toStoreResponse()
|