Skip to content

Commit

Permalink
Merge #1612: RPC API: Add optional txfee property for single joins
Browse files Browse the repository at this point in the history
ab1481d RPC API: Add optional txfee property for single joins (Kristaps Kaupe)

Pull request description:

  Resolves #1607.

Top commit has no ACKs.

Tree-SHA512: 2cbb8cd38d8888d84fd6ea438dadaf31d0406c4bdadcf9206ca539e1ae728e6c9cb4504de4c62f626bdae585fc7fb923cb148883a5a60faa1c82cf2e00837efa
  • Loading branch information
kristapsk committed Jan 27, 2024
2 parents 927ed0a + ab1481d commit d21f7c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/api/wallet-rpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ components:
destination:
type: string
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:
type: object
required:
Expand Down
44 changes: 35 additions & 9 deletions src/jmclient/wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def __init__(self, port, wss_port, tls=True):
# a tumble schedule.
self.tumbler_options = 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):
return JMClientProtocolFactory(self.taker)
Expand Down Expand Up @@ -511,6 +514,8 @@ def taker_finished(self, res, fromtx=False, waittime=0.0, txdetails=None):
if not self.tumbler_options:
# We were doing a single coinjoin -- stop taker.
self.stop_taker(res)
jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
else:
# We're running the tumbler.
assert self.tumble_log is not None
Expand Down Expand Up @@ -782,24 +787,33 @@ def directsend(self, request, walletname):
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"]))
if int(payment_info_json["txfee"]) > 0:
jm_single().config.set("POLICY", "tx_fees",
str(payment_info_json["txfee"]))
else:
raise InvalidRequestFormat()

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)
jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
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()
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))
except Exception:
jm_single().config.set("POLICY", "tx_fees",
self.default_policy_tx_fees)
raise
if not tx:
# this should not really happen; not a coinjoin
# so tx should go through.
Expand Down Expand Up @@ -1183,6 +1197,9 @@ def configset(self, request, walletname):
try:
jm_single().config.set(config_json["section"],
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:
raise ConfigNotPresent()
# null return indicates success in updating:
Expand Down Expand Up @@ -1265,9 +1282,13 @@ def docoinjoin(self, request, walletname):
raise NoWalletFound()
if not self.wallet_name == walletname:
raise InvalidRequestFormat()
request_data = self.get_POST_body(request,["mixdepth", "amount_sats",
"counterparties", "destination"])
if not request_data:
request_data = self.get_POST_body(request,
["mixdepth", "amount_sats",
"counterparties",
"destination"],
["txfee"])
if not request_data or \
("txfee" in request_data and int(request_data["txfee"]) <= 0):
raise InvalidRequestFormat()
#see file scripts/sample-schedule-for-testnet for schedule format
waittime = 0
Expand Down Expand Up @@ -1297,6 +1318,11 @@ def dummy_user_callback(rel, abs):
# Before actual start, update our coinjoin state:
if not self.activate_coinjoin_state(CJ_TAKER_RUNNING):
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,
max_cj_fee = max_cj_fee,
callbacks=(self.filter_orders_callback,
Expand Down

0 comments on commit d21f7c0

Please sign in to comment.