Fabiana Cecin ce918b0819
chore: replace Option with Opt (#4035)
* change all usage of std.options.Option[T] to results.Opt[T]
* fix broken apps and examples (to validate refactor)
* removed all std/options code added for libp2p v2 migration
* add broker Opt codec to persistency/backend_comm.nim
* add a readValue overload for Opt[T] in tools/confutils/cli_args.nim
* keep Option where required (Presto, confutils' config_file.nim)
* Change generateRlnProof error handling
* Fix imports
2026-07-16 14:02:17 -03:00

54 lines
1.8 KiB
Nim

## Waku layer API — store (historical query) operations.
{.push raises: [].}
import results, chronos, chronicles
import logos_delivery/waku/waku
import
logos_delivery/waku/
[waku_core, node/waku_node, node/peer_manager, waku_store/common, waku_store/client]
proc isStoreMounted*(self: Waku): bool =
## True if a store client is mounted (the node can run store queries).
return not self.node.wakuStoreClient.isNil()
proc hasStorePeer*(self: Waku): bool =
## True if at least one store service peer is available to query.
return self.node.peerManager.selectPeer(WakuStoreCodec).isSome()
proc storeQueryToAny*(
self: Waku, request: StoreQueryRequest
): Future[Result[StoreQueryResponse, string]] {.async.} =
## Runs a store query against any available store peer (retries across peers).
try:
if self.node.wakuStoreClient.isNil():
return err("wakuStoreClient is not mounted")
let queryResponse = (await self.node.wakuStoreClient.queryToAny(request)).valueOr:
return err($error)
return ok(queryResponse)
except CatchableError as e:
return err(e.msg)
proc storeQuery*(
self: Waku, request: StoreQueryRequest, peer: string, timeoutMs: int
): Future[Result[StoreQueryResponse, string]] {.async.} =
try:
if self.node.wakuStoreClient.isNil():
return err("wakuStoreClient is not mounted")
let remotePeer = parsePeerInfo(peer).valueOr:
return err("storeQuery failed to parse peer addr: " & $error)
let queryFut = self.node.wakuStoreClient.query(request, remotePeer)
if not await queryFut.withTimeout(timeoutMs.milliseconds):
return err("storeQuery timed out")
let queryResponse = queryFut.read().valueOr:
return err("storeQuery failed: " & $error)
return ok(queryResponse)
except CatchableError as e:
return err(e.msg)