mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-31 09:08:31 +00:00
fb2ea06a4f
* replaces topics with seq of ContentFilters * update topics to contentFilter * updates the contentFilter structure one content topic per content filter instead of a sequence of topics * updates store json rpc api * renames ContentFilter to HistoryContentFilter * unit test for a query with several content filters * makes shortcut for store api * updates chat2 * clean up * renames topic to contentTopic * clarifies the use of content topic in store api * clarifies the use of contentTopic in the init method of HistoryContentFilter
45 lines
1.6 KiB
Nim
45 lines
1.6 KiB
Nim
{.push raises: [Exception, Defect].}
|
|
|
|
import
|
|
std/options,
|
|
json_rpc/rpcserver,
|
|
../../protocol/waku_store/waku_store_types,
|
|
../wakunode2,
|
|
./jsonrpc_types, ./jsonrpc_utils
|
|
|
|
export jsonrpc_types
|
|
|
|
logScope:
|
|
topics = "store api"
|
|
|
|
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
|
const futTimeout = 5.seconds
|
|
|
|
## Store API version 1 definitions
|
|
|
|
rpcsrv.rpc("get_waku_v2_store_v1_messages") do(contentTopics: 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())
|
|
|
|
var contentFilters: seq[HistoryContentFilter] = @[]
|
|
# items in contentTopics map to the contentTopic field of waku message (not to be confused with pubsub topic)
|
|
for ct in contentTopics:
|
|
contentFilters.add(HistoryContentFilter(contentTopic: ct))
|
|
let historyQuery = HistoryQuery(contentFilters: contentFilters,
|
|
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")
|