Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1686: yieldgenerator: allow change address to be overridden

d11779184f yieldgenerator: allow change address to be overridden (Matt Whitlock)

Pull request description:

  I have a custom yield generator that sometimes sends change to external addresses. Implementing this required me to add an extension point in `jmclient/yieldgenerator.py` to allow the change address to be overridden. As this could be useful to others as well, I am submitting it for review and merge.

ACKs for top commit:
  kristapsk:
    cr utACK d11779184f. Tests pass, that should be enough here.

Tree-SHA512: 459e4d5cd64010feda2092ebf69c4227b428b0ff45edcca3635ca553e5aa64bd1395374d5bc31080091dcd49426c3f8bf018c9cad2476411e99f65ab46aa31b7
master
Kristaps Kaupe 2 years ago
parent
commit
830ec5a7cb
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 9
      src/jmclient/yieldgenerator.py

9
src/jmclient/yieldgenerator.py

@ -201,7 +201,8 @@ class YieldGeneratorBasic(YieldGenerator):
return None, None, None
jlog.info('sending output to address=' + str(cj_addr))
change_addr = self.wallet_service.get_internal_addr(mixdepth)
change_amount = sum(u["value"] for u in utxos.values()) - total_amount + real_cjfee
change_addr = self.select_change_address(mixdepth, change_amount)
return utxos, cj_addr, change_addr
def _get_order_inputs(self, filtered_mix_balance, offer, required_amount):
@ -268,6 +269,12 @@ class YieldGeneratorBasic(YieldGenerator):
cjoutmix = (input_mixdepth + 1) % (self.wallet_service.mixdepth + 1)
return self.wallet_service.get_internal_addr(cjoutmix)
def select_change_address(self, input_mixdepth: int, change_amount: int) -> str:
"""Returns the address to which the change should be sent for an
order spending from the given input mixdepth. Must not return
None."""
return self.wallet_service.get_internal_addr(input_mixdepth)
class YieldGeneratorService(Service):
def __init__(self, wallet_service, daemon_host, daemon_port, yg_config):
self.wallet_service = wallet_service

Loading…
Cancel
Save