nwaku/waku/waku_store/self_req_handler.nim
Ivan FB fd6a71cdd7
chore: Bump dependencies for v0.31.0 (#2885)
* bump_dependencies.md: add nim-results dependency
* change imports stew/results to results
* switching to Nim 2.0.8
* waku.nimble: reflect the requirement nim 1.6.0 to 2.0.8
  Adding --mm:refc as nim 2.0 enables a new garbage collector that we're
  not yet ready to support
* adapt waku code to Nim 2.0
* gcsafe adaptations because Nim 2.0 is more strict
2024-07-09 13:14:28 +02:00

38 lines
1.3 KiB
Nim

##
## This file is aimed to attend the requests that come directly
## from the 'self' node. It is expected to attend the store requests that
## come from REST-store endpoint when those requests don't indicate
## any store-peer address.
##
## Notice that the REST-store requests normally assume that the REST
## server is acting as a store-client. In this module, we allow that
## such REST-store node can act as store-server as well by retrieving
## its own stored messages. The typical use case for that is when
## using `nwaku-compose`, which spawn a Waku node connected to a local
## database, and the user is interested in retrieving the messages
## stored by that local store node.
##
import results, chronos
import ./protocol, ./common
proc handleSelfStoreRequest*(
self: WakuStore, req: StoreQueryRequest
): Future[WakuStoreResult[StoreQueryResponse]] {.async.} =
## Handles the store requests made by the node to itself.
## Normally used in REST-store requests
let handlerResult = catch:
await self.requestHandler(req)
let resResult =
if handlerResult.isErr():
return err("exception in handleSelfStoreRequest: " & handlerResult.error.msg)
else:
handlerResult.get()
let res = resResult.valueOr:
return err("error in handleSelfStoreRequest: " & $error)
return ok(res)