From d8f1fc42d455653db904e2f5547cc1006ee0df09 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Thu, 16 Nov 2023 19:30:38 +0200 Subject: [PATCH] Add optional txfee property for direct-send wallet RPC --- docs/api/wallet-rpc.yaml | 4 ++++ src/jmclient/wallet_rpc.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/api/wallet-rpc.yaml b/docs/api/wallet-rpc.yaml index f68cd4a70..eeffeaba0 100644 --- a/docs/api/wallet-rpc.yaml +++ b/docs/api/wallet-rpc.yaml @@ -1113,6 +1113,10 @@ components: destination: type: string example: bcrt1qu7k4dppungsqp95nwc7ansqs9m0z95h72j9mze + txfee: + type: integer + example: 6 + description: Bitcoin miner fee to use for transaction. A number higher than 1000 is used as satoshi per kvB tx fee. The number lower than that uses the dynamic fee estimation of blockchain provider as confirmation target. ErrorMessage: type: object properties: diff --git a/src/jmclient/wallet_rpc.py b/src/jmclient/wallet_rpc.py index 1dd15ea96..e9a9e6658 100644 --- a/src/jmclient/wallet_rpc.py +++ b/src/jmclient/wallet_rpc.py @@ -766,7 +766,8 @@ def directsend(self, request, walletname): self.check_cookie(request) assert isinstance(request.content, BytesIO) payment_info_json = self.get_POST_body(request, ["mixdepth", "amount_sats", - "destination"]) + "destination"], + ["txfee"]) if not payment_info_json: raise InvalidRequestFormat() if not self.services["wallet"]: @@ -780,15 +781,24 @@ def directsend(self, request, walletname): # all error conditions). if not self.coinjoin_state == CJ_NOT_RUNNING: raise ActionNotAllowed() + + old_txfee = jm_single().config.get("POLICY", "tx_fees") + if "txfee" in payment_info_json: + jm_single().config.set("POLICY", "tx_fees", + str(payment_info_json["txfee"])) + try: tx = direct_send(self.services["wallet"], int(payment_info_json["amount_sats"]), int(payment_info_json["mixdepth"]), destination=payment_info_json["destination"], return_transaction=True, answeryes=True) + jm_single().config.set("POLICY", "tx_fees", old_txfee) except AssertionError: + jm_single().config.set("POLICY", "tx_fees", old_txfee) raise InvalidRequestFormat() except NotEnoughFundsException as e: + jm_single().config.set("POLICY", "tx_fees", old_txfee) raise TransactionFailed(repr(e)) if not tx: # this should not really happen; not a coinjoin