Skip to content

Commit

Permalink
trustedcoin: fix 'send max' shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdsa committed Feb 2, 2016
1 parent a43b039 commit 57af8d1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plugins/trustedcoin/trustedcoin.py
Expand Up @@ -206,6 +206,27 @@ def make_seed(self):
def can_sign_without_server(self):
return self.master_private_keys.get('x2/') is not None

def get_max_amount(self, config, inputs, fee):
from electrum.transaction import Transaction
sendable = sum(map(lambda x:x['value'], inputs))
for i in inputs:
self.add_input_info(i)
dummy_address = self.addresses(False)[0]
xf = self.extra_fee()
if xf and sendable >= xf:
billing_address = self.billing_info['billing_address']
sendable -= xf
outputs = [(TYPE_ADDRESS, dummy_address, sendable),
(TYPE_ADDRESS, billing_address, xf)]
else:
outputs = [(TYPE_ADDRESS, dummy_addr, sendable)]

dummy_tx = Transaction.from_io(inputs, outputs)
if fee is None:
fee = self.estimate_fee(config, dummy_tx.estimated_size())
amount = max(0, sendable - fee)
return amount, fee

def extra_fee(self):
if self.can_sign_without_server():
return 0
Expand Down

0 comments on commit 57af8d1

Please sign in to comment.