wallet.make_unsigned_transaction: add batch_rbf/send_change params
Don't side-effect config just to modify the next call of make_unsigned_transaction >.< Cleaner to pass parameters.
This commit is contained in:
@@ -428,12 +428,13 @@ class QESwapHelper(AuthMixin, QObject, QtEventListener):
|
|||||||
raise InvalidSwapParameters("swap_manager.max_amount_forward_swap() is None")
|
raise InvalidSwapParameters("swap_manager.max_amount_forward_swap() is None")
|
||||||
if max_amount > max_swap_amount:
|
if max_amount > max_swap_amount:
|
||||||
onchain_amount = max_swap_amount
|
onchain_amount = max_swap_amount
|
||||||
self._wallet.wallet.config.WALLET_SEND_CHANGE_TO_LIGHTNING = False
|
|
||||||
outputs = [PartialTxOutput.from_address_and_value(DummyAddress.SWAP, onchain_amount)]
|
outputs = [PartialTxOutput.from_address_and_value(DummyAddress.SWAP, onchain_amount)]
|
||||||
try:
|
try:
|
||||||
tx = self._wallet.wallet.make_unsigned_transaction(
|
tx = self._wallet.wallet.make_unsigned_transaction(
|
||||||
coins=coins,
|
coins=coins,
|
||||||
outputs=outputs)
|
outputs=outputs,
|
||||||
|
send_change_to_lightning=False,
|
||||||
|
)
|
||||||
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
|
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
|
||||||
raise InvalidSwapParameters(str(e)) from e
|
raise InvalidSwapParameters(str(e)) from e
|
||||||
return tx
|
return tx
|
||||||
|
|||||||
@@ -293,12 +293,13 @@ class SwapDialog(WindowModalDialog, QtEventListener):
|
|||||||
raise InvalidSwapParameters("swap_manager.max_amount_forward_swap() is None")
|
raise InvalidSwapParameters("swap_manager.max_amount_forward_swap() is None")
|
||||||
if max_amount > max_swap_amount:
|
if max_amount > max_swap_amount:
|
||||||
onchain_amount = max_swap_amount
|
onchain_amount = max_swap_amount
|
||||||
self.config.WALLET_SEND_CHANGE_TO_LIGHTNING = False
|
|
||||||
outputs = [PartialTxOutput.from_address_and_value(DummyAddress.SWAP, onchain_amount)]
|
outputs = [PartialTxOutput.from_address_and_value(DummyAddress.SWAP, onchain_amount)]
|
||||||
try:
|
try:
|
||||||
tx = self.window.wallet.make_unsigned_transaction(
|
tx = self.window.wallet.make_unsigned_transaction(
|
||||||
coins=coins,
|
coins=coins,
|
||||||
outputs=outputs)
|
outputs=outputs,
|
||||||
|
send_change_to_lightning=False,
|
||||||
|
)
|
||||||
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
|
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
|
||||||
raise InvalidSwapParameters(str(e)) from e
|
raise InvalidSwapParameters(str(e)) from e
|
||||||
return tx
|
return tx
|
||||||
|
|||||||
@@ -406,8 +406,7 @@ class SwapManager(Logger):
|
|||||||
if swap.funding_txid is None:
|
if swap.funding_txid is None:
|
||||||
password = self.wallet.get_unlocked_password()
|
password = self.wallet.get_unlocked_password()
|
||||||
for batch_rbf in [True, False]:
|
for batch_rbf in [True, False]:
|
||||||
self.wallet.config.WALLET_BATCH_RBF = batch_rbf
|
tx = self.create_funding_tx(swap, None, password, batch_rbf=batch_rbf)
|
||||||
tx = self.create_funding_tx(swap, None, password)
|
|
||||||
try:
|
try:
|
||||||
await self.broadcast_funding_tx(swap, tx)
|
await self.broadcast_funding_tx(swap, tx)
|
||||||
except TxBroadcastServerReturnedError:
|
except TxBroadcastServerReturnedError:
|
||||||
@@ -716,13 +715,18 @@ class SwapManager(Logger):
|
|||||||
await self.broadcast_funding_tx(swap, tx)
|
await self.broadcast_funding_tx(swap, tx)
|
||||||
return swap.funding_txid
|
return swap.funding_txid
|
||||||
|
|
||||||
def create_funding_tx(self, swap, tx, password):
|
def create_funding_tx(self, swap, tx, password, *, batch_rbf: Optional[bool] = None):
|
||||||
# create funding tx
|
# create funding tx
|
||||||
# note: rbf must not decrease payment
|
# note: rbf must not decrease payment
|
||||||
# this is taken care of in wallet._is_rbf_allowed_to_touch_tx_output
|
# this is taken care of in wallet._is_rbf_allowed_to_touch_tx_output
|
||||||
if tx is None:
|
if tx is None:
|
||||||
funding_output = PartialTxOutput.from_address_and_value(swap.lockup_address, swap.onchain_amount)
|
funding_output = PartialTxOutput.from_address_and_value(swap.lockup_address, swap.onchain_amount)
|
||||||
tx = self.wallet.create_transaction(outputs=[funding_output], rbf=True, password=password)
|
tx = self.wallet.create_transaction(
|
||||||
|
outputs=[funding_output],
|
||||||
|
rbf=True,
|
||||||
|
password=password,
|
||||||
|
batch_rbf=batch_rbf,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
tx.replace_output_address(DummyAddress.SWAP, swap.lockup_address)
|
tx.replace_output_address(DummyAddress.SWAP, swap.lockup_address)
|
||||||
tx.set_rbf(True)
|
tx.set_rbf(True)
|
||||||
|
|||||||
@@ -1724,13 +1724,20 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
fee=None,
|
fee=None,
|
||||||
change_addr: str = None,
|
change_addr: str = None,
|
||||||
is_sweep=False,
|
is_sweep=False,
|
||||||
rbf=True) -> PartialTransaction:
|
rbf=True,
|
||||||
|
batch_rbf: Optional[bool] = None,
|
||||||
|
send_change_to_lightning: Optional[bool] = None,
|
||||||
|
) -> PartialTransaction:
|
||||||
"""Can raise NotEnoughFunds or NoDynamicFeeEstimates."""
|
"""Can raise NotEnoughFunds or NoDynamicFeeEstimates."""
|
||||||
|
|
||||||
if not coins: # any bitcoin tx must have at least 1 input by consensus
|
if not coins: # any bitcoin tx must have at least 1 input by consensus
|
||||||
raise NotEnoughFunds()
|
raise NotEnoughFunds()
|
||||||
if any([c.already_has_some_signatures() for c in coins]):
|
if any([c.already_has_some_signatures() for c in coins]):
|
||||||
raise Exception("Some inputs already contain signatures!")
|
raise Exception("Some inputs already contain signatures!")
|
||||||
|
if batch_rbf is None:
|
||||||
|
batch_rbf = self.config.WALLET_BATCH_RBF
|
||||||
|
if send_change_to_lightning is None:
|
||||||
|
send_change_to_lightning = self.config.WALLET_SEND_CHANGE_TO_LIGHTNING
|
||||||
|
|
||||||
# prevent side-effect with '!'
|
# prevent side-effect with '!'
|
||||||
outputs = copy.deepcopy(outputs)
|
outputs = copy.deepcopy(outputs)
|
||||||
@@ -1767,7 +1774,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
# Let the coin chooser select the coins to spend
|
# Let the coin chooser select the coins to spend
|
||||||
coin_chooser = coinchooser.get_coin_chooser(self.config)
|
coin_chooser = coinchooser.get_coin_chooser(self.config)
|
||||||
# If there is an unconfirmed RBF tx, merge with it
|
# If there is an unconfirmed RBF tx, merge with it
|
||||||
base_tx = self.get_unconfirmed_base_tx_for_batching(outputs, coins) if self.config.WALLET_BATCH_RBF else None
|
base_tx = self.get_unconfirmed_base_tx_for_batching(outputs, coins) if batch_rbf else None
|
||||||
if base_tx:
|
if base_tx:
|
||||||
# make sure we don't try to spend change from the tx-to-be-replaced:
|
# make sure we don't try to spend change from the tx-to-be-replaced:
|
||||||
coins = [c for c in coins if c.prevout.txid.hex() != base_tx.txid()]
|
coins = [c for c in coins if c.prevout.txid.hex() != base_tx.txid()]
|
||||||
@@ -1801,7 +1808,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
change_addrs=change_addrs,
|
change_addrs=change_addrs,
|
||||||
fee_estimator_vb=fee_estimator,
|
fee_estimator_vb=fee_estimator,
|
||||||
dust_threshold=self.dust_threshold())
|
dust_threshold=self.dust_threshold())
|
||||||
if self.lnworker and self.config.WALLET_SEND_CHANGE_TO_LIGHTNING:
|
if self.lnworker and send_change_to_lightning:
|
||||||
change = tx.get_change_outputs()
|
change = tx.get_change_outputs()
|
||||||
# do not use multiple change addresses
|
# do not use multiple change addresses
|
||||||
if len(change) == 1:
|
if len(change) == 1:
|
||||||
@@ -2924,8 +2931,22 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
def get_all_known_addresses_beyond_gap_limit(self) -> Set[str]:
|
def get_all_known_addresses_beyond_gap_limit(self) -> Set[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_transaction(self, outputs, *, fee=None, feerate=None, change_addr=None, domain_addr=None, domain_coins=None,
|
def create_transaction(
|
||||||
unsigned=False, rbf=True, password=None, locktime=None):
|
self,
|
||||||
|
outputs,
|
||||||
|
*,
|
||||||
|
fee=None,
|
||||||
|
feerate=None,
|
||||||
|
change_addr=None,
|
||||||
|
domain_addr=None,
|
||||||
|
domain_coins=None,
|
||||||
|
unsigned=False,
|
||||||
|
rbf=True,
|
||||||
|
password=None,
|
||||||
|
locktime=None,
|
||||||
|
batch_rbf: Optional[bool] = None,
|
||||||
|
send_change_to_lightning: Optional[bool] = None,
|
||||||
|
):
|
||||||
if fee is not None and feerate is not None:
|
if fee is not None and feerate is not None:
|
||||||
raise Exception("Cannot specify both 'fee' and 'feerate' at the same time!")
|
raise Exception("Cannot specify both 'fee' and 'feerate' at the same time!")
|
||||||
coins = self.get_spendable_coins(domain_addr)
|
coins = self.get_spendable_coins(domain_addr)
|
||||||
@@ -2940,7 +2961,10 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
coins=coins,
|
coins=coins,
|
||||||
outputs=outputs,
|
outputs=outputs,
|
||||||
fee=fee_estimator,
|
fee=fee_estimator,
|
||||||
change_addr=change_addr)
|
change_addr=change_addr,
|
||||||
|
batch_rbf=batch_rbf,
|
||||||
|
send_change_to_lightning=send_change_to_lightning,
|
||||||
|
)
|
||||||
if locktime is not None:
|
if locktime is not None:
|
||||||
tx.locktime = locktime
|
tx.locktime = locktime
|
||||||
tx.set_rbf(rbf)
|
tx.set_rbf(rbf)
|
||||||
|
|||||||
Reference in New Issue
Block a user