Browse Source

Add optional txfee property for direct-send wallet RPC

master
Kristaps Kaupe 2 years ago
parent
commit
d8f1fc42d4
  1. 4
      docs/api/wallet-rpc.yaml
  2. 12
      src/jmclient/wallet_rpc.py

4
docs/api/wallet-rpc.yaml

@ -1113,6 +1113,10 @@ components:
destination: destination:
type: string type: string
example: bcrt1qu7k4dppungsqp95nwc7ansqs9m0z95h72j9mze 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: ErrorMessage:
type: object type: object
properties: properties:

12
src/jmclient/wallet_rpc.py

@ -766,7 +766,8 @@ class JMWalletDaemon(Service):
self.check_cookie(request) self.check_cookie(request)
assert isinstance(request.content, BytesIO) assert isinstance(request.content, BytesIO)
payment_info_json = self.get_POST_body(request, ["mixdepth", "amount_sats", payment_info_json = self.get_POST_body(request, ["mixdepth", "amount_sats",
"destination"]) "destination"],
["txfee"])
if not payment_info_json: if not payment_info_json:
raise InvalidRequestFormat() raise InvalidRequestFormat()
if not self.services["wallet"]: if not self.services["wallet"]:
@ -780,15 +781,24 @@ class JMWalletDaemon(Service):
# all error conditions). # all error conditions).
if not self.coinjoin_state == CJ_NOT_RUNNING: if not self.coinjoin_state == CJ_NOT_RUNNING:
raise ActionNotAllowed() 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: try:
tx = direct_send(self.services["wallet"], tx = direct_send(self.services["wallet"],
int(payment_info_json["amount_sats"]), int(payment_info_json["amount_sats"]),
int(payment_info_json["mixdepth"]), int(payment_info_json["mixdepth"]),
destination=payment_info_json["destination"], destination=payment_info_json["destination"],
return_transaction=True, answeryes=True) return_transaction=True, answeryes=True)
jm_single().config.set("POLICY", "tx_fees", old_txfee)
except AssertionError: except AssertionError:
jm_single().config.set("POLICY", "tx_fees", old_txfee)
raise InvalidRequestFormat() raise InvalidRequestFormat()
except NotEnoughFundsException as e: except NotEnoughFundsException as e:
jm_single().config.set("POLICY", "tx_fees", old_txfee)
raise TransactionFailed(repr(e)) raise TransactionFailed(repr(e))
if not tx: if not tx:
# this should not really happen; not a coinjoin # this should not really happen; not a coinjoin

Loading…
Cancel
Save