mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 16:01:30 +00:00
remove dust output when bumping fee
This commit is contained in:
parent
9d2e322760
commit
15546d817c
1 changed files with 12 additions and 9 deletions
|
@ -804,6 +804,10 @@ class Abstract_Wallet(PrintError):
|
||||||
f = self.network.relay_fee if self.network and self.network.relay_fee else RELAY_FEE
|
f = self.network.relay_fee if self.network and self.network.relay_fee else RELAY_FEE
|
||||||
return min(f, MAX_RELAY_FEE)
|
return min(f, MAX_RELAY_FEE)
|
||||||
|
|
||||||
|
def dust_threshold(self):
|
||||||
|
# Change <= dust threshold is added to the tx fee
|
||||||
|
return 182 * 3 * self.relayfee() / 1000
|
||||||
|
|
||||||
def get_tx_fee(self, tx):
|
def get_tx_fee(self, tx):
|
||||||
# this method can be overloaded
|
# this method can be overloaded
|
||||||
return tx.get_fee()
|
return tx.get_fee()
|
||||||
|
@ -844,14 +848,11 @@ class Abstract_Wallet(PrintError):
|
||||||
else:
|
else:
|
||||||
fee_estimator = lambda size: fixed_fee
|
fee_estimator = lambda size: fixed_fee
|
||||||
|
|
||||||
# Change <= dust threshold is added to the tx fee
|
|
||||||
dust_threshold = 182 * 3 * self.relayfee() / 1000
|
|
||||||
|
|
||||||
# Let the coin chooser select the coins to spend
|
# Let the coin chooser select the coins to spend
|
||||||
max_change = self.max_change_outputs if self.multiple_change else 1
|
max_change = self.max_change_outputs if self.multiple_change else 1
|
||||||
coin_chooser = coinchooser.get_coin_chooser(config)
|
coin_chooser = coinchooser.get_coin_chooser(config)
|
||||||
tx = coin_chooser.make_tx(coins, outputs, change_addrs[:max_change],
|
tx = coin_chooser.make_tx(coins, outputs, change_addrs[:max_change],
|
||||||
fee_estimator, dust_threshold)
|
fee_estimator, self.dust_threshold())
|
||||||
|
|
||||||
# Sort the inputs and outputs deterministically
|
# Sort the inputs and outputs deterministically
|
||||||
tx.BIP_LI01_sort()
|
tx.BIP_LI01_sort()
|
||||||
|
@ -1008,7 +1009,7 @@ class Abstract_Wallet(PrintError):
|
||||||
|
|
||||||
def bump_fee(self, tx, delta):
|
def bump_fee(self, tx, delta):
|
||||||
if tx.is_final():
|
if tx.is_final():
|
||||||
raise BaseException("cannot bump fee: transaction is final")
|
raise BaseException(_("Cannot bump fee: transaction is final"))
|
||||||
inputs = copy.deepcopy(tx.inputs())
|
inputs = copy.deepcopy(tx.inputs())
|
||||||
outputs = copy.deepcopy(tx.outputs())
|
outputs = copy.deepcopy(tx.outputs())
|
||||||
for txin in inputs:
|
for txin in inputs:
|
||||||
|
@ -1017,12 +1018,14 @@ class Abstract_Wallet(PrintError):
|
||||||
for i, o in enumerate(outputs):
|
for i, o in enumerate(outputs):
|
||||||
otype, address, value = o
|
otype, address, value = o
|
||||||
if self.is_mine(address) and value >= delta:
|
if self.is_mine(address) and value >= delta:
|
||||||
outputs[i] = otype, address, value - delta
|
if value - delta >= self.dust_threshold():
|
||||||
|
outputs[i] = otype, address, value - delta
|
||||||
|
else:
|
||||||
|
del outputs[i]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise BaseException("cannot bump fee: could not find a change output")
|
raise BaseException(_("Cannot bump fee: could not find a change output"))
|
||||||
new_tx = Transaction.from_io(inputs, outputs)
|
return Transaction.from_io(inputs, outputs)
|
||||||
return new_tx
|
|
||||||
|
|
||||||
def add_input_info(self, txin):
|
def add_input_info(self, txin):
|
||||||
# Add address for utxo that are in wallet
|
# Add address for utxo that are in wallet
|
||||||
|
|
Loading…
Add table
Reference in a new issue