Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1612: RPC API: Add optional txfee property for single joins

ab1481d814 RPC API: Add optional txfee property for single joins (Kristaps Kaupe)

Pull request description:

  Resolves #1607.

Top commit has no ACKs.

Tree-SHA512: 2cbb8cd38d8888d84fd6ea438dadaf31d0406c4bdadcf9206ca539e1ae728e6c9cb4504de4c62f626bdae585fc7fb923cb148883a5a60faa1c82cf2e00837efa
master
Kristaps Kaupe 2 years ago
parent
commit
d21f7c0b93
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 3
      docs/api/wallet-rpc.yaml
  2. 44
      src/jmclient/wallet_rpc.py

3
docs/api/wallet-rpc.yaml

@ -655,6 +655,9 @@ components:
destination: destination:
type: string type: string
example: "bcrt1qujp2x2fv437493sm25gfjycns7d39exjnpptzw" example: "bcrt1qujp2x2fv437493sm25gfjycns7d39exjnpptzw"
txfee:
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.
TokenRequest: TokenRequest:
type: object type: object
required: required:

44
src/jmclient/wallet_rpc.py

@ -187,6 +187,9 @@ class JMWalletDaemon(Service):
# a tumble schedule. # a tumble schedule.
self.tumbler_options = None self.tumbler_options = None
self.tumble_log = None self.tumble_log = None
# save settings we might temporary change runtime
self.default_policy_tx_fees = jm_single().config.get("POLICY",
"tx_fees")
def get_client_factory(self): def get_client_factory(self):
return JMClientProtocolFactory(self.taker) return JMClientProtocolFactory(self.taker)
@ -511,6 +514,8 @@ class JMWalletDaemon(Service):
if not self.tumbler_options: if not self.tumbler_options:
# We were doing a single coinjoin -- stop taker. # We were doing a single coinjoin -- stop taker.
self.stop_taker(res) self.stop_taker(res)
jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
else: else:
# We're running the tumbler. # We're running the tumbler.
assert self.tumble_log is not None assert self.tumble_log is not None
@ -782,10 +787,12 @@ class JMWalletDaemon(Service):
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: if "txfee" in payment_info_json:
jm_single().config.set("POLICY", "tx_fees", if int(payment_info_json["txfee"]) > 0:
str(payment_info_json["txfee"])) jm_single().config.set("POLICY", "tx_fees",
str(payment_info_json["txfee"]))
else:
raise InvalidRequestFormat()
try: try:
tx = direct_send(self.services["wallet"], tx = direct_send(self.services["wallet"],
@ -793,13 +800,20 @@ class JMWalletDaemon(Service):
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) jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
except AssertionError: except AssertionError:
jm_single().config.set("POLICY", "tx_fees", old_txfee) jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
raise InvalidRequestFormat() raise InvalidRequestFormat()
except NotEnoughFundsException as e: except NotEnoughFundsException as e:
jm_single().config.set("POLICY", "tx_fees", old_txfee) jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
raise TransactionFailed(repr(e)) raise TransactionFailed(repr(e))
except Exception:
jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
raise
if not tx: if not tx:
# this should not really happen; not a coinjoin # this should not really happen; not a coinjoin
# so tx should go through. # so tx should go through.
@ -1183,6 +1197,9 @@ class JMWalletDaemon(Service):
try: try:
jm_single().config.set(config_json["section"], jm_single().config.set(config_json["section"],
config_json["field"], config_json["value"]) config_json["field"], config_json["value"])
if config_json["section"] == "POLICY":
if config_json["field"] == "tx_fees":
self.default_policy_tx_fees = config_json["value"]
except: except:
raise ConfigNotPresent() raise ConfigNotPresent()
# null return indicates success in updating: # null return indicates success in updating:
@ -1265,9 +1282,13 @@ class JMWalletDaemon(Service):
raise NoWalletFound() raise NoWalletFound()
if not self.wallet_name == walletname: if not self.wallet_name == walletname:
raise InvalidRequestFormat() raise InvalidRequestFormat()
request_data = self.get_POST_body(request,["mixdepth", "amount_sats", request_data = self.get_POST_body(request,
"counterparties", "destination"]) ["mixdepth", "amount_sats",
if not request_data: "counterparties",
"destination"],
["txfee"])
if not request_data or \
("txfee" in request_data and int(request_data["txfee"]) <= 0):
raise InvalidRequestFormat() raise InvalidRequestFormat()
#see file scripts/sample-schedule-for-testnet for schedule format #see file scripts/sample-schedule-for-testnet for schedule format
waittime = 0 waittime = 0
@ -1297,6 +1318,11 @@ class JMWalletDaemon(Service):
# Before actual start, update our coinjoin state: # Before actual start, update our coinjoin state:
if not self.activate_coinjoin_state(CJ_TAKER_RUNNING): if not self.activate_coinjoin_state(CJ_TAKER_RUNNING):
raise ServiceAlreadyStarted() raise ServiceAlreadyStarted()
if "txfee" in request_data:
jm_single().config.set("POLICY", "tx_fees",
str(request_data["txfee"]))
self.taker = Taker(self.services["wallet"], schedule, self.taker = Taker(self.services["wallet"], schedule,
max_cj_fee = max_cj_fee, max_cj_fee = max_cj_fee,
callbacks=(self.filter_orders_callback, callbacks=(self.filter_orders_callback,

Loading…
Cancel
Save