2020-12-01 09:57:54 +00:00
|
|
|
{.push raises: [Exception, Defect].}
|
|
|
|
|
2020-11-24 03:44:37 +00:00
|
|
|
import
|
|
|
|
std/options,
|
|
|
|
json_rpc/rpcserver,
|
2020-11-24 04:34:32 +00:00
|
|
|
../../protocol/waku_store/waku_store_types,
|
2020-11-24 03:44:37 +00:00
|
|
|
../wakunode2,
|
|
|
|
./jsonrpc_types, ./jsonrpc_utils
|
|
|
|
|
2020-12-23 09:33:28 +00:00
|
|
|
export jsonrpc_types
|
|
|
|
|
2020-11-27 07:18:48 +00:00
|
|
|
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
2020-11-24 03:44:37 +00:00
|
|
|
const futTimeout = 5.seconds
|
|
|
|
|
|
|
|
## Store API version 1 definitions
|
|
|
|
|
|
|
|
rpcsrv.rpc("get_waku_v2_store_v1_messages") do(topics: seq[ContentTopic], pagingOptions: Option[StorePagingOptions]) -> StoreResponse:
|
|
|
|
## 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())
|
|
|
|
|
|
|
|
let historyQuery = HistoryQuery(topics: topics,
|
|
|
|
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
|
|
|
|
raise newException(ValueError, "No history response received")
|