electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit da8fce1914e03b49945cde6df296788bbaf5023e
parent 4eba1c1d8a10e8a35bc8b2202a6e745198427f86
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 14 Jan 2016 16:06:22 +0100

if available, use relayfee from server instead of hard coded value

Diffstat:
Mlib/bitcoin.py | 1-
Mlib/network.py | 6++++++
Mlib/transaction.py | 10+++++-----
Mlib/wallet.py | 11+++++++++--
4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -30,7 +30,6 @@ import aes ################################## transactions -MIN_RELAY_TX_FEE = 5000 RECOMMENDED_FEE = 50000 COINBASE_MATURITY = 100 COIN = 100000000 diff --git a/lib/network.py b/lib/network.py @@ -167,6 +167,7 @@ class Network(util.DaemonThread): self.banner = '' self.fee = None + self.relay_fee = None self.heights = {} self.merkle_roots = {} self.utxo_roots = {} @@ -289,6 +290,7 @@ class Network(util.DaemonThread): self.queue_request('server.banner', []) self.queue_request('server.peers.subscribe', []) self.queue_request('blockchain.estimatefee', [2]) + self.queue_request('blockchain.relayfee', []) def get_status_value(self, key): if key == 'status': @@ -487,6 +489,10 @@ class Network(util.DaemonThread): self.fee = int(result * COIN) self.print_error("recommended fee", self.fee) self.notify('fee') + elif method == 'blockchain.relayfee': + if error is None: + self.relay_fee = int(result * COIN) + self.print_error("relayfee", self.relay_fee) elif method == 'blockchain.block.get_chunk': self.on_get_chunk(interface, response) elif method == 'blockchain.block.get_header': diff --git a/lib/transaction.py b/lib/transaction.py @@ -698,12 +698,12 @@ class Transaction: return self.input_value() - self.output_value() @classmethod - def fee_for_size(self, fee_per_kb, size): + def fee_for_size(self, relay_fee, fee_per_kb, size): '''Given a fee per kB in satoshis, and a tx size in bytes, returns the transaction fee.''' fee = int(fee_per_kb * size / 1000.) - if fee < MIN_RELAY_TX_FEE: - fee = MIN_RELAY_TX_FEE + if fee < relay_fee: + fee = relay_fee return fee @profiler @@ -716,9 +716,9 @@ class Transaction: '''Return an estimated of serialized input size in bytes.''' return len(self.serialize_input(txin, -1, -1)) / 2 - def estimated_fee(self, fee_per_kb): + def estimated_fee(self, relay_fee, fee_per_kb): '''Return an estimated fee given a fee per kB in satoshis.''' - return self.fee_for_size(fee_per_kb, self.estimated_size()) + return self.fee_for_size(relay_fee, fee_per_kb, self.estimated_size()) def signature_count(self): r = 0 diff --git a/lib/wallet.py b/lib/wallet.py @@ -662,7 +662,7 @@ class Abstract_Wallet(PrintError): dummy_tx = Transaction.from_io(inputs, [output]) if fee is None: fee_per_kb = self.fee_per_kb(config) - fee = dummy_tx.estimated_fee(fee_per_kb) + fee = dummy_tx.estimated_fee(self.relayfee(), fee_per_kb) amount = max(0, sendable - fee) return amount, fee @@ -901,6 +901,12 @@ class Abstract_Wallet(PrintError): F = config.get('fee_per_kb', bitcoin.RECOMMENDED_FEE) return min(F, self.network.fee*(50 + f)/100) if b and self.network and self.network.fee else F + def relayfee(self): + RELAY_FEE = 5000 + MAX_RELAY_FEE = 50000 + f = self.network.relay_fee if self.network and self.network.relay_fee else RELAY_FEE + return min(f, MAX_RELAY_FEE) + def get_tx_fee(self, tx): # this method can be overloaded return tx.get_fee() @@ -950,12 +956,13 @@ class Abstract_Wallet(PrintError): # Fee estimator if fixed_fee is None: fee_estimator = partial(Transaction.fee_for_size, + self.relayfee(), self.fee_per_kb(config)) else: fee_estimator = lambda size: fixed_fee # Change <= dust threshold is added to the tx fee - dust_threshold = 182 * 3 * MIN_RELAY_TX_FEE / 1000 + dust_threshold = 182 * 3 * self.relayfee() / 1000 # Check cache to see if we just calculated this. If prior # calculated a fee and this fixes it to the same, return same