Skip to content

Commit

Permalink
Improve sweep method fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Apr 28, 2024
1 parent 1f0c5db commit 5413b31
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4258,18 +4258,17 @@ def sweep(self, to_address, account_id=None, input_key_id=None, network=None, ma
total_amount += utxo['value']
srv = Service(network=network, wallet_name=self.name, providers=self.providers, cache_uri=self.db_cache_uri)

fee_modifier = 1 if self.witness_type == 'legacy' else 0.5
fee_modifier = 1 if self.witness_type == 'legacy' else 0.6
if isinstance(fee, str):
n_outputs = 1 if not isinstance(to_address, list) else len(to_address)
fee_per_kb = srv.estimatefee(priority=fee)
tr_size = 125 + (len(input_arr) * (77 + self.multisig_n_required * 72)) + n_outputs * 30
fee = int(100 + ((tr_size / 1000.0) * fee_per_kb * fee_modifier))

fee = None
if not fee:
if fee_per_kb is None:
fee_per_kb = srv.estimatefee()
tr_size = 125 + (len(input_arr) * 125)
fee = int((tr_size / 1000.0) * fee_per_kb * fee_modifier)
n_outputs = 1 if not isinstance(to_address, list) else len(to_address)
tr_size = 125 + (len(input_arr) * (77 + self.multisig_n_required * 72)) + n_outputs * 30
fee = int(100 + ((tr_size / 1000.0) * fee_per_kb * fee_modifier))

if total_amount - fee <= self.network.dust_amount:
raise WalletError("Amount to send is smaller then dust amount: %s" % (total_amount - fee))

Expand Down

0 comments on commit 5413b31

Please sign in to comment.