From 6ae9f87be7ae062e0cc4251d777e55c1c61518c0 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Sun, 28 Apr 2024 13:06:05 +0300 Subject: [PATCH] RPC API endpoint to get wallet rescan status --- docs/api/wallet-rpc.yaml | 37 +++++++++++++++++++++++++++++++++++++ src/jmclient/wallet_rpc.py | 18 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/docs/api/wallet-rpc.yaml b/docs/api/wallet-rpc.yaml index 5bc34bfc0..291eea69a 100644 --- a/docs/api/wallet-rpc.yaml +++ b/docs/api/wallet-rpc.yaml @@ -240,6 +240,27 @@ paths: $ref: '#/components/responses/400-BadRequest' '404': $ref: '#/components/responses/404-NotFound' + /wallet/{walletname}/getrescaninfo: + get: + security: + - bearerAuth: [] + summary: get the current rescan status + operationId: getrescaninfo + description: get the current rescan status + parameters: + - name: walletname + in: path + description: name of wallet including .jmdat + required: true + schema: + type: string + responses: + '200': + $ref: '#/components/responses/RescanInfo-200-OK' + '400': + $ref: '#/components/responses/400-BadRequest' + '404': + $ref: '#/components/responses/404-NotFound' /wallet/{walletname}/address/timelock/new/{lockdate}: get: security: @@ -805,6 +826,16 @@ components: walletname: type: string example: "wallet.jmdat" + RescanInfoResponse: + type: object + required: + - rescanning + - progress + properties: + rescanning: + type: boolean + block_height: + type: number SessionResponse: type: object required: @@ -1190,6 +1221,12 @@ components: application/json: schema: $ref: "#/components/schemas/RescanBlockchainResponse" + RescanInfo-200-OK: + description: "Blockchain rescan status retrieved successfully" + content: + application/json: + schema: + $ref: "#/components/schemas/RescanInfoResponse" Create-201-OK: description: "wallet created successfully" content: diff --git a/src/jmclient/wallet_rpc.py b/src/jmclient/wallet_rpc.py index a2fdc7d6b..37a9237f4 100644 --- a/src/jmclient/wallet_rpc.py +++ b/src/jmclient/wallet_rpc.py @@ -692,6 +692,24 @@ def rescanblockchain(self, request, walletname, blockheight): self.services["wallet"].rescanblockchain(blockheight) return make_jmwalletd_response(request, walletname=walletname) + @app.route('/wallet//getrescaninfo', methods=['GET']) + def getrescaninfo(self, request, walletname): + """ This route lets the user get the current rescan status. + """ + print_req(request) + self.check_cookie(request) + if not self.services["wallet"]: + jlog.warn("getrescaninfo called, but no wallet service active.") + raise NoWalletFound() + if not self.wallet_name == walletname: + jlog.warn("called getrescaninfo with wrong wallet") + raise InvalidRequestFormat() + else: + rescanning, progress = \ + self.services["wallet"].get_backend_wallet_rescan_status() + return make_jmwalletd_response(request, walletname=walletname, + rescanning=rescanning, progress=progress) + @app.route('/getinfo', methods=['GET']) def version(self, request): """ This route sends information about the backend, including