Fixes for TrustedCoin plugin:
- reset billing_info after broadcast - when bumping tx fee, do not use Trustedcoin output
This commit is contained in:
@@ -1340,9 +1340,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
_("Mining fee") + ": " + self.format_amount_and_units(fee),
|
_("Mining fee") + ": " + self.format_amount_and_units(fee),
|
||||||
]
|
]
|
||||||
|
|
||||||
extra_fee = run_hook('get_additional_fee', self.wallet, tx)
|
x_fee = run_hook('get_tx_extra_fee', self.wallet, tx)
|
||||||
if extra_fee:
|
if x_fee:
|
||||||
msg.append( _("Additional fees") + ": " + self.format_amount_and_units(extra_fee) )
|
x_fee_address, x_fee_amount = x_fee
|
||||||
|
msg.append( _("Additional fees") + ": " + self.format_amount_and_units(x_fee_amount) )
|
||||||
|
|
||||||
confirm_rate = 2 * self.config.max_fee_rate()
|
confirm_rate = 2 * self.config.max_fee_rate()
|
||||||
if fee > confirm_rate * tx.estimated_size() / 1000:
|
if fee > confirm_rate * tx.estimated_size() / 1000:
|
||||||
|
|||||||
@@ -1030,6 +1030,11 @@ class Abstract_Wallet(PrintError):
|
|||||||
# ... unless there is none
|
# ... unless there is none
|
||||||
if not s:
|
if not s:
|
||||||
s = outputs
|
s = outputs
|
||||||
|
x_fee = run_hook('get_tx_extra_fee', self, tx)
|
||||||
|
if x_fee:
|
||||||
|
x_fee_address, x_fee_amount = x_fee
|
||||||
|
s = filter(lambda x: x[1]!=x_fee_address, s)
|
||||||
|
|
||||||
# prioritize low value outputs, to get rid of dust
|
# prioritize low value outputs, to get rid of dust
|
||||||
s = sorted(s, key=lambda x: x[2])
|
s = sorted(s, key=lambda x: x[2])
|
||||||
for o in s:
|
for o in s:
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ class Plugin(TrustedCoinPlugin):
|
|||||||
button = StatusBarButton(QIcon(":icons/trustedcoin-status.png"),
|
button = StatusBarButton(QIcon(":icons/trustedcoin-status.png"),
|
||||||
_("TrustedCoin"), action)
|
_("TrustedCoin"), action)
|
||||||
window.statusBar().addPermanentWidget(button)
|
window.statusBar().addPermanentWidget(button)
|
||||||
t = Thread(target=self.request_billing_info, args=(wallet,))
|
self.start_request_thread(window.wallet)
|
||||||
t.setDaemon(True)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
def auth_dialog(self, window):
|
def auth_dialog(self, window):
|
||||||
d = WindowModalDialog(window, _("Authorization"))
|
d = WindowModalDialog(window, _("Authorization"))
|
||||||
@@ -102,13 +100,10 @@ class Plugin(TrustedCoinPlugin):
|
|||||||
wallet = window.wallet
|
wallet = window.wallet
|
||||||
if not isinstance(wallet, self.wallet_class):
|
if not isinstance(wallet, self.wallet_class):
|
||||||
return
|
return
|
||||||
if not wallet.can_sign_without_server():
|
if wallet.can_sign_without_server():
|
||||||
if wallet.billing_info is None:
|
return
|
||||||
# request billing info before forming the transaction
|
if wallet.billing_info is None:
|
||||||
waiting_dialog(self, window).wait()
|
return True
|
||||||
if wallet.billing_info is None:
|
|
||||||
window.show_message('Could not contact server')
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -237,6 +237,9 @@ class Wallet_2fa(Multisig_Wallet):
|
|||||||
def extra_fee(self, config):
|
def extra_fee(self, config):
|
||||||
if self.can_sign_without_server():
|
if self.can_sign_without_server():
|
||||||
return 0
|
return 0
|
||||||
|
if self.billing_info is None:
|
||||||
|
self.plugin.start_request_thread(self)
|
||||||
|
return 0
|
||||||
if self.billing_info.get('tx_remaining'):
|
if self.billing_info.get('tx_remaining'):
|
||||||
return 0
|
return 0
|
||||||
if self.is_billing:
|
if self.is_billing:
|
||||||
@@ -282,6 +285,8 @@ class Wallet_2fa(Multisig_Wallet):
|
|||||||
raw_tx = r.get('transaction')
|
raw_tx = r.get('transaction')
|
||||||
tx.update(raw_tx)
|
tx.update(raw_tx)
|
||||||
self.print_error("twofactor: is complete", tx.is_complete())
|
self.print_error("twofactor: is complete", tx.is_complete())
|
||||||
|
# reset billing_info
|
||||||
|
self.billing_info = None
|
||||||
|
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
@@ -314,6 +319,7 @@ class TrustedCoinPlugin(BasePlugin):
|
|||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config, name):
|
||||||
BasePlugin.__init__(self, parent, config, name)
|
BasePlugin.__init__(self, parent, config, name)
|
||||||
self.wallet_class.plugin = self
|
self.wallet_class.plugin = self
|
||||||
|
self.requesting = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_seed(seed):
|
def is_valid_seed(seed):
|
||||||
@@ -326,23 +332,34 @@ class TrustedCoinPlugin(BasePlugin):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def get_additional_fee(self, wallet, tx):
|
def get_tx_extra_fee(self, wallet, tx):
|
||||||
if type(wallet) != Wallet_2fa:
|
if type(wallet) != Wallet_2fa:
|
||||||
return
|
return
|
||||||
address = wallet.billing_info['billing_address']
|
address = wallet.billing_info['billing_address']
|
||||||
for _type, addr, amount in tx.outputs():
|
for _type, addr, amount in tx.outputs():
|
||||||
if _type == TYPE_ADDRESS and addr == address:
|
if _type == TYPE_ADDRESS and addr == address:
|
||||||
return amount
|
return address, amount
|
||||||
|
|
||||||
def request_billing_info(self, wallet):
|
def request_billing_info(self, wallet):
|
||||||
|
self.print_error("request billing info")
|
||||||
billing_info = server.get(wallet.get_user_id()[1])
|
billing_info = server.get(wallet.get_user_id()[1])
|
||||||
billing_address = make_billing_address(wallet, billing_info['billing_index'])
|
billing_address = make_billing_address(wallet, billing_info['billing_index'])
|
||||||
assert billing_address == billing_info['billing_address']
|
assert billing_address == billing_info['billing_address']
|
||||||
wallet.billing_info = billing_info
|
wallet.billing_info = billing_info
|
||||||
wallet.price_per_tx = dict(billing_info['price_per_tx'])
|
wallet.price_per_tx = dict(billing_info['price_per_tx'])
|
||||||
wallet.price_per_tx.pop(1)
|
wallet.price_per_tx.pop(1)
|
||||||
|
self.requesting = False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def start_request_thread(self, wallet):
|
||||||
|
from threading import Thread
|
||||||
|
if self.requesting is False:
|
||||||
|
self.requesting = True
|
||||||
|
t = Thread(target=self.request_billing_info, args=(wallet,))
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
return t
|
||||||
|
|
||||||
def make_seed(self):
|
def make_seed(self):
|
||||||
return Mnemonic('english').make_seed(seed_type='2fa', num_bits=128)
|
return Mnemonic('english').make_seed(seed_type='2fa', num_bits=128)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user