Allow bumpfee on transactions with a single output (#2433)

Co-authored-by: k9ert <k9ert@gmx.de>
This commit is contained in:
Leon Costa 2024-05-06 17:40:18 +02:00 committed by GitHub
parent c56eff5816
commit 9890d1e9bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1734,18 +1734,24 @@ class Wallet(AbstractWallet):
raise SpecterError(
"Fee difference is too small to relay the RBF transaction"
)
# find change output
change_index = None
for i, out in enumerate(psbt.outputs):
if out.is_change:
change_index = i
break
if change_index is None:
raise SpecterError("Can't bump fee in a transaction without change outputs")
psbt.psbt.outputs[i].value -= round(fee_delta)
if psbt.psbt.outputs[i].value <= 0:
# if we went negative - just drop the change output
psbt.psbt.outputs.remove(psbt.psbt.outputs[i])
if len(psbt.outputs) == 1:
# On single-output transactions we just decrease the output value
psbt.psbt.outputs[0].value -= round(fee_delta)
else:
# find change output
change_index = None
for i, out in enumerate(psbt.outputs):
if out.is_change:
change_index = i
break
if change_index is None:
raise SpecterError(
"Can't bump fee in a transaction without change outputs"
)
psbt.psbt.outputs[i].value -= round(fee_delta)
if psbt.psbt.outputs[i].value <= 0:
# if we went negative - just drop the change output
psbt.psbt.outputs.remove(psbt.psbt.outputs[i])
self.save_pending_psbt(psbt)
return psbt.to_dict()