Make trustedcoin.py multi-window compatible
This commit is contained in:
@@ -1170,7 +1170,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
|||||||
|
|
||||||
|
|
||||||
def do_send(self):
|
def do_send(self):
|
||||||
if run_hook('before_send', self):
|
if run_hook('abort_send', self):
|
||||||
return
|
return
|
||||||
r = self.read_send_tab()
|
r = self.read_send_tab()
|
||||||
if not r:
|
if not r:
|
||||||
|
|||||||
@@ -972,7 +972,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
# Sort the inputs and outputs deterministically
|
# Sort the inputs and outputs deterministically
|
||||||
tx.BIP_LI01_sort()
|
tx.BIP_LI01_sort()
|
||||||
|
|
||||||
run_hook('make_unsigned_transaction', tx)
|
run_hook('make_unsigned_transaction', self, tx)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def mktx(self, outputs, password, config, fee=None, change_addr=None, domain=None):
|
def mktx(self, outputs, password, config, fee=None, change_addr=None, domain=None):
|
||||||
@@ -1022,7 +1022,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
tx.sign(keypairs)
|
tx.sign(keypairs)
|
||||||
# Run hook, and raise if error
|
# Run hook, and raise if error
|
||||||
tx.error = None
|
tx.error = None
|
||||||
run_hook('sign_transaction', tx, password)
|
run_hook('sign_transaction', self, tx, password)
|
||||||
if tx.error:
|
if tx.error:
|
||||||
raise BaseException(tx.error)
|
raise BaseException(tx.error)
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import threading
|
from threading import Thread
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -170,7 +170,6 @@ class TrustedCoinCosignerClient(object):
|
|||||||
|
|
||||||
server = TrustedCoinCosignerClient(user_agent="Electrum/" + version.ELECTRUM_VERSION)
|
server = TrustedCoinCosignerClient(user_agent="Electrum/" + version.ELECTRUM_VERSION)
|
||||||
|
|
||||||
|
|
||||||
class Wallet_2fa(Multisig_Wallet):
|
class Wallet_2fa(Multisig_Wallet):
|
||||||
|
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
@@ -197,72 +196,111 @@ class Wallet_2fa(Multisig_Wallet):
|
|||||||
|
|
||||||
def estimated_fee(self, tx, fee_per_kb):
|
def estimated_fee(self, tx, fee_per_kb):
|
||||||
fee = Multisig_Wallet.estimated_fee(self, tx, fee_per_kb)
|
fee = Multisig_Wallet.estimated_fee(self, tx, fee_per_kb)
|
||||||
x = run_hook('extra_fee', tx)
|
x = run_hook('extra_fee', self, tx)
|
||||||
if x: fee += x
|
if x: fee += x
|
||||||
return fee
|
return fee
|
||||||
|
|
||||||
def get_tx_fee(self, tx):
|
def get_tx_fee(self, tx):
|
||||||
fee = Multisig_Wallet.get_tx_fee(self, tx)
|
fee = Multisig_Wallet.get_tx_fee(self, tx)
|
||||||
x = run_hook('extra_fee', tx)
|
x = run_hook('extra_fee', self, tx)
|
||||||
if x: fee += x
|
if x: fee += x
|
||||||
return fee
|
return fee
|
||||||
|
|
||||||
|
# Utility functions
|
||||||
|
|
||||||
|
def get_user_id(wallet):
|
||||||
|
def make_long_id(xpub_hot, xpub_cold):
|
||||||
|
return bitcoin.sha256(''.join(sorted([xpub_hot, xpub_cold])))
|
||||||
|
|
||||||
|
xpub_hot = wallet.master_public_keys["x1/"]
|
||||||
|
xpub_cold = wallet.master_public_keys["x2/"]
|
||||||
|
long_id = make_long_id(xpub_hot, xpub_cold)
|
||||||
|
short_id = hashlib.sha256(long_id).hexdigest()
|
||||||
|
return long_id, short_id
|
||||||
|
|
||||||
|
def make_xpub(xpub, s):
|
||||||
|
_, _, _, c, cK = deserialize_xkey(xpub)
|
||||||
|
cK2, c2 = bitcoin._CKD_pub(cK, c, s)
|
||||||
|
xpub2 = ("0488B21E" + "00" + "00000000" + "00000000").decode("hex") + c2 + cK2
|
||||||
|
return EncodeBase58Check(xpub2)
|
||||||
|
|
||||||
|
def restore_third_key(wallet):
|
||||||
|
long_user_id, short_id = get_user_id(wallet)
|
||||||
|
xpub3 = make_xpub(signing_xpub, long_user_id)
|
||||||
|
wallet.add_master_public_key('x3/', xpub3)
|
||||||
|
|
||||||
|
def make_billing_address(wallet, num):
|
||||||
|
long_id, short_id = get_user_id(wallet)
|
||||||
|
xpub = make_xpub(billing_xpub, long_id)
|
||||||
|
_, _, _, c, cK = deserialize_xkey(xpub)
|
||||||
|
cK, c = bitcoin.CKD_pub(cK, c, num)
|
||||||
|
address = public_key_to_bc_address( cK )
|
||||||
|
return address
|
||||||
|
|
||||||
|
def need_server(wallet, tx):
|
||||||
|
from electrum.account import BIP32_Account
|
||||||
|
# Detect if the server is needed
|
||||||
|
long_id, short_id = get_user_id(wallet)
|
||||||
|
xpub3 = wallet.master_public_keys['x3/']
|
||||||
|
for x in tx.inputs_to_sign():
|
||||||
|
if x[0:2] == 'ff':
|
||||||
|
xpub, sequence = BIP32_Account.parse_xpubkey(x)
|
||||||
|
if xpub == xpub3:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
|
|
||||||
wallet = None
|
|
||||||
|
|
||||||
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.seed_func = lambda x: bitcoin.is_new_seed(x, SEED_PREFIX)
|
self.seed_func = lambda x: bitcoin.is_new_seed(x, SEED_PREFIX)
|
||||||
self.billing_info = None
|
# Keyed by wallet to handle multiple pertinent windows. Each
|
||||||
self.is_billing = False
|
# wallet is a 2fa wallet. Each value is a dictionary with
|
||||||
|
# information about the wallet for the plugin
|
||||||
|
self.wallets = {}
|
||||||
|
|
||||||
def constructor(self, s):
|
def constructor(self, s):
|
||||||
return Wallet_2fa(s)
|
return Wallet_2fa(s)
|
||||||
|
|
||||||
def is_available(self):
|
def is_available(self):
|
||||||
if not self.wallet:
|
return bool(self.wallets)
|
||||||
return False
|
|
||||||
if self.wallet.storage.get('wallet_type') == '2fa':
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def set_enabled(self, enabled):
|
def set_enabled(self, wallet, enabled):
|
||||||
self.wallet.storage.put('use_' + self.name, enabled)
|
wallet.storage.put('use_' + self.name, enabled)
|
||||||
|
|
||||||
def is_enabled(self):
|
def is_enabled(self):
|
||||||
if not self.is_available():
|
return (self.is_available() and
|
||||||
return False
|
not all(wallet.master_private_keys.get('x2/')
|
||||||
if self.wallet.master_private_keys.get('x2/'):
|
for wallet in self.wallets.keys()))
|
||||||
return False
|
|
||||||
|
def on_new_window(self, window):
|
||||||
|
wallet = window.wallet
|
||||||
|
if wallet.storage.get('wallet_type') == '2fa':
|
||||||
|
button = StatusBarButton(QIcon(":icons/trustedcoin.png"),
|
||||||
|
_("TrustedCoin"),
|
||||||
|
partial(self.settings_dialog, window))
|
||||||
|
window.statusBar().addPermanentWidget(button)
|
||||||
|
self.wallets[wallet] = {
|
||||||
|
'is_billing' : False,
|
||||||
|
'billing_info' : None,
|
||||||
|
'button' : button, # Avoid loss to GC
|
||||||
|
}
|
||||||
|
t = Thread(target=self.request_billing_info, args=(wallet,))
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
def on_close_window(self, window):
|
||||||
|
self.wallets.pop(window.wallet, None)
|
||||||
|
|
||||||
|
def request_billing_info(self, wallet):
|
||||||
|
billing_info = server.get(get_user_id(wallet)[1])
|
||||||
|
billing_address = make_billing_address(wallet, billing_info['billing_index'])
|
||||||
|
assert billing_address == billing_info['billing_address']
|
||||||
|
wallet_info = self.wallets[wallet]
|
||||||
|
wallet_info['billing_info'] = billing_info
|
||||||
|
wallet_info['price_per_tx'] = dict(billing_info['price_per_tx'])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def make_long_id(self, xpub_hot, xpub_cold):
|
|
||||||
return bitcoin.sha256(''.join(sorted([xpub_hot, xpub_cold])))
|
|
||||||
|
|
||||||
def get_user_id(self):
|
|
||||||
xpub_hot = self.wallet.master_public_keys["x1/"]
|
|
||||||
xpub_cold = self.wallet.master_public_keys["x2/"]
|
|
||||||
long_id = self.make_long_id(xpub_hot, xpub_cold)
|
|
||||||
short_id = hashlib.sha256(long_id).hexdigest()
|
|
||||||
return long_id, short_id
|
|
||||||
|
|
||||||
def make_xpub(self, xpub, s):
|
|
||||||
_, _, _, c, cK = deserialize_xkey(xpub)
|
|
||||||
cK2, c2 = bitcoin._CKD_pub(cK, c, s)
|
|
||||||
xpub2 = ("0488B21E" + "00" + "00000000" + "00000000").decode("hex") + c2 + cK2
|
|
||||||
return EncodeBase58Check(xpub2)
|
|
||||||
|
|
||||||
def make_billing_address(self, num):
|
|
||||||
long_id, short_id = self.get_user_id()
|
|
||||||
xpub = self.make_xpub(billing_xpub, long_id)
|
|
||||||
_, _, _, c, cK = deserialize_xkey(xpub)
|
|
||||||
cK, c = bitcoin.CKD_pub(cK, c, num)
|
|
||||||
address = public_key_to_bc_address( cK )
|
|
||||||
return address
|
|
||||||
|
|
||||||
def create_extended_seed(self, wallet, window):
|
def create_extended_seed(self, wallet, window):
|
||||||
seed = wallet.make_seed()
|
seed = wallet.make_seed()
|
||||||
if not window.show_seed(seed, None):
|
if not window.show_seed(seed, None):
|
||||||
@@ -309,34 +347,12 @@ class Plugin(BasePlugin):
|
|||||||
icon = QPixmap(':icons/trustedcoin.png')
|
icon = QPixmap(':icons/trustedcoin.png')
|
||||||
if not window.question(''.join(msg), icon=icon):
|
if not window.question(''.join(msg), icon=icon):
|
||||||
return False
|
return False
|
||||||
self.wallet = wallet
|
self.set_enabled(wallet, True)
|
||||||
self.set_enabled(True)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def restore_third_key(self, wallet):
|
|
||||||
long_user_id, short_id = self.get_user_id()
|
|
||||||
xpub3 = self.make_xpub(signing_xpub, long_user_id)
|
|
||||||
wallet.add_master_public_key('x3/', xpub3)
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def do_clear(self, window):
|
def do_clear(self, window):
|
||||||
self.is_billing = False
|
self.wallets[window.wallet]['is_billing'] = False
|
||||||
|
|
||||||
@hook
|
|
||||||
def load_wallet(self, wallet, window):
|
|
||||||
self.wallet = wallet
|
|
||||||
self.trustedcoin_button = StatusBarButton(QIcon(":icons/trustedcoin.png"), _("TrustedCoin"), partial(self.settings_dialog, window))
|
|
||||||
window.statusBar().addPermanentWidget(self.trustedcoin_button)
|
|
||||||
self.xpub = self.wallet.master_public_keys.get('x1/')
|
|
||||||
self.user_id = self.get_user_id()[1]
|
|
||||||
t = threading.Thread(target=self.request_billing_info)
|
|
||||||
t.setDaemon(True)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def installwizard_load_wallet(self, wallet, window):
|
|
||||||
self.wallet = wallet
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def get_wizard_action(self, window, wallet, action):
|
def get_wizard_action(self, window, wallet, action):
|
||||||
@@ -352,7 +368,6 @@ class Plugin(BasePlugin):
|
|||||||
if not seed:
|
if not seed:
|
||||||
return
|
return
|
||||||
wallet = Wallet_2fa(storage)
|
wallet = Wallet_2fa(storage)
|
||||||
self.wallet = wallet
|
|
||||||
password = window.password_dialog()
|
password = window.password_dialog()
|
||||||
|
|
||||||
wallet.add_seed(seed, password)
|
wallet.add_seed(seed, password)
|
||||||
@@ -361,16 +376,14 @@ class Plugin(BasePlugin):
|
|||||||
wallet.add_cosigner_seed(' '.join(words[0:n]), 'x1/', password)
|
wallet.add_cosigner_seed(' '.join(words[0:n]), 'x1/', password)
|
||||||
wallet.add_cosigner_seed(' '.join(words[n:]), 'x2/', password)
|
wallet.add_cosigner_seed(' '.join(words[n:]), 'x2/', password)
|
||||||
|
|
||||||
self.restore_third_key(wallet)
|
restore_third_key(wallet)
|
||||||
wallet.create_main_account(password)
|
wallet.create_main_account(password)
|
||||||
# disable plugin
|
# disable plugin
|
||||||
self.set_enabled(False)
|
self.set_enabled(wallet, False)
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
|
|
||||||
def create_remote_key(self, wallet, window):
|
def create_remote_key(self, wallet, window):
|
||||||
self.wallet = wallet
|
|
||||||
|
|
||||||
if wallet.storage.get('wallet_type') != '2fa':
|
if wallet.storage.get('wallet_type') != '2fa':
|
||||||
raise
|
raise
|
||||||
return
|
return
|
||||||
@@ -383,8 +396,8 @@ class Plugin(BasePlugin):
|
|||||||
xpub_cold = wallet.master_public_keys["x2/"]
|
xpub_cold = wallet.master_public_keys["x2/"]
|
||||||
|
|
||||||
# Generate third key deterministically.
|
# Generate third key deterministically.
|
||||||
long_user_id, self.user_id = self.get_user_id()
|
long_user_id, short_id = get_user_id(wallet)
|
||||||
xpub3 = self.make_xpub(signing_xpub, long_user_id)
|
xpub3 = make_xpub(signing_xpub, long_user_id)
|
||||||
|
|
||||||
# secret must be sent by the server
|
# secret must be sent by the server
|
||||||
try:
|
try:
|
||||||
@@ -408,110 +421,18 @@ class Plugin(BasePlugin):
|
|||||||
_xpub3 = r['xpubkey_cosigner']
|
_xpub3 = r['xpubkey_cosigner']
|
||||||
_id = r['id']
|
_id = r['id']
|
||||||
try:
|
try:
|
||||||
assert _id == self.user_id, ("user id error", _id, self.user_id)
|
assert _id == short_id, ("user id error", _id, short_id)
|
||||||
assert xpub3 == _xpub3, ("xpub3 error", xpub3, _xpub3)
|
assert xpub3 == _xpub3, ("xpub3 error", xpub3, _xpub3)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
window.show_message(str(e))
|
window.show_message(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.setup_google_auth(window, self.user_id, otp_secret):
|
if not self.setup_google_auth(window, short_id, otp_secret):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.wallet.add_master_public_key('x3/', xpub3)
|
wallet.add_master_public_key('x3/', xpub3)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def need_server(self, tx):
|
|
||||||
from electrum.account import BIP32_Account
|
|
||||||
# Detect if the server is needed
|
|
||||||
long_id, short_id = self.get_user_id()
|
|
||||||
xpub3 = self.wallet.master_public_keys['x3/']
|
|
||||||
for x in tx.inputs_to_sign():
|
|
||||||
if x[0:2] == 'ff':
|
|
||||||
xpub, sequence = BIP32_Account.parse_xpubkey(x)
|
|
||||||
if xpub == xpub3:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def sign_tx(self, window, tx):
|
|
||||||
self.print_error("twofactor:sign_tx")
|
|
||||||
if self.wallet.storage.get('wallet_type') != '2fa':
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.need_server(tx):
|
|
||||||
self.print_error("twofactor: xpub3 not needed")
|
|
||||||
self.auth_code = None
|
|
||||||
return
|
|
||||||
|
|
||||||
self.auth_code = self.auth_dialog(window)
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def before_send(self, window):
|
|
||||||
# request billing info before forming the transaction
|
|
||||||
self.billing_info = None
|
|
||||||
self.waiting_dialog = WaitingDialog(window, 'please wait...', self.request_billing_info)
|
|
||||||
self.waiting_dialog.start()
|
|
||||||
self.waiting_dialog.wait()
|
|
||||||
if self.billing_info is None:
|
|
||||||
window.show_message('Could not contact server')
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def extra_fee(self, tx):
|
|
||||||
if self.billing_info.get('tx_remaining'):
|
|
||||||
return 0
|
|
||||||
if self.is_billing:
|
|
||||||
return 0
|
|
||||||
# trustedcoin won't charge if the total inputs is lower than their fee
|
|
||||||
price = int(self.price_per_tx.get(1))
|
|
||||||
assert price <= 100000
|
|
||||||
if tx.input_value() < price:
|
|
||||||
self.print_error("not charging for this tx")
|
|
||||||
return 0
|
|
||||||
return price
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def make_unsigned_transaction(self, tx):
|
|
||||||
price = self.extra_fee(tx)
|
|
||||||
if not price:
|
|
||||||
return
|
|
||||||
tx.outputs.append(('address', self.billing_info['billing_address'], price))
|
|
||||||
|
|
||||||
@hook
|
|
||||||
def sign_transaction(self, tx, password):
|
|
||||||
self.print_error("twofactor:sign")
|
|
||||||
if self.wallet.storage.get('wallet_type') != '2fa':
|
|
||||||
self.print_error("twofactor: aborting")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.long_user_id, self.user_id = self.get_user_id()
|
|
||||||
|
|
||||||
if not self.auth_code:
|
|
||||||
return
|
|
||||||
|
|
||||||
if tx.is_complete():
|
|
||||||
return
|
|
||||||
|
|
||||||
tx_dict = tx.as_dict()
|
|
||||||
raw_tx = tx_dict["hex"]
|
|
||||||
try:
|
|
||||||
r = server.sign(self.user_id, raw_tx, self.auth_code)
|
|
||||||
except Exception as e:
|
|
||||||
tx.error = str(e)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.print_error( "received answer", r)
|
|
||||||
if not r:
|
|
||||||
return
|
|
||||||
|
|
||||||
raw_tx = r.get('transaction')
|
|
||||||
tx.update(raw_tx)
|
|
||||||
self.print_error("twofactor: is complete", tx.is_complete())
|
|
||||||
|
|
||||||
|
|
||||||
def auth_dialog(self, window):
|
def auth_dialog(self, window):
|
||||||
d = QDialog(window)
|
d = QDialog(window)
|
||||||
d.setModal(1)
|
d.setModal(1)
|
||||||
@@ -529,8 +450,93 @@ class Plugin(BasePlugin):
|
|||||||
return
|
return
|
||||||
return pw.get_amount()
|
return pw.get_amount()
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def sign_tx(self, window, tx):
|
||||||
|
self.print_error("twofactor:sign_tx")
|
||||||
|
if window.wallet in self.wallets:
|
||||||
|
auth_code = None
|
||||||
|
if need_server(window.wallet, tx):
|
||||||
|
auth_code = self.auth_dialog(window)
|
||||||
|
else:
|
||||||
|
self.print_error("twofactor: xpub3 not needed")
|
||||||
|
self.wallets[window.wallet]['auth_code'] = auth_code
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def abort_send(self, window):
|
||||||
|
if window.wallet in self.wallets:
|
||||||
|
wallet_info = self.wallets[window.wallet]
|
||||||
|
# request billing info before forming the transaction
|
||||||
|
wallet_info['billing_info'] = None
|
||||||
|
task = partial(self.request_billing_info, window.wallet)
|
||||||
|
waiting_dialog = WaitingDialog(window, 'please wait...', task)
|
||||||
|
waiting_dialog.start()
|
||||||
|
waiting_dialog.wait()
|
||||||
|
if wallet_info['billing_info'] is None:
|
||||||
|
window.show_message('Could not contact server')
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def extra_fee(self, wallet, tx):
|
||||||
|
if not wallet in self.wallets:
|
||||||
|
return 0
|
||||||
|
wallet_info = self.wallets[wallet]
|
||||||
|
if wallet_info['billing_info'].get('tx_remaining'):
|
||||||
|
return 0
|
||||||
|
if wallet_info['is_billing']:
|
||||||
|
return 0
|
||||||
|
# trustedcoin won't charge if the total inputs is lower than their fee
|
||||||
|
price = int(wallet_info['price_per_tx'].get(1))
|
||||||
|
assert price <= 100000
|
||||||
|
if tx.input_value() < price:
|
||||||
|
self.print_error("not charging for this tx")
|
||||||
|
return 0
|
||||||
|
return price
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def make_unsigned_transaction(self, wallet, tx):
|
||||||
|
if wallet in self.wallets:
|
||||||
|
price = self.extra_fee(wallet, tx)
|
||||||
|
if not price:
|
||||||
|
return
|
||||||
|
address = self.wallets[wallet]['billing_info']['billing_address']
|
||||||
|
tx.outputs.append(('address', address, price))
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def sign_transaction(self, wallet, tx, password):
|
||||||
|
self.print_error("twofactor:sign")
|
||||||
|
if not wallet in self.wallets:
|
||||||
|
self.print_error("not 2fa wallet")
|
||||||
|
return
|
||||||
|
|
||||||
|
auth_code = self.wallets[wallet]['auth_code']
|
||||||
|
if not auth_code:
|
||||||
|
self.print_error("sign_transaction: no auth code")
|
||||||
|
return
|
||||||
|
|
||||||
|
if tx.is_complete():
|
||||||
|
return
|
||||||
|
|
||||||
|
long_user_id, short_id = get_user_id(wallet)
|
||||||
|
tx_dict = tx.as_dict()
|
||||||
|
raw_tx = tx_dict["hex"]
|
||||||
|
try:
|
||||||
|
r = server.sign(short_id, raw_tx, auth_code)
|
||||||
|
except Exception as e:
|
||||||
|
tx.error = str(e)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.print_error( "received answer", r)
|
||||||
|
if not r:
|
||||||
|
return
|
||||||
|
|
||||||
|
raw_tx = r.get('transaction')
|
||||||
|
tx.update(raw_tx)
|
||||||
|
self.print_error("twofactor: is complete", tx.is_complete())
|
||||||
|
|
||||||
def settings_dialog(self, window):
|
def settings_dialog(self, window):
|
||||||
self.waiting_dialog = WaitingDialog(window, 'please wait...', self.request_billing_info, partial(self.show_settings_dialog, window))
|
task = partial(self.request_billing_info, window.wallet)
|
||||||
|
self.waiting_dialog = WaitingDialog(window, 'please wait...', task, partial(self.show_settings_dialog, window))
|
||||||
self.waiting_dialog.start()
|
self.waiting_dialog.start()
|
||||||
|
|
||||||
def show_settings_dialog(self, window, success):
|
def show_settings_dialog(self, window, success):
|
||||||
@@ -538,6 +544,7 @@ class Plugin(BasePlugin):
|
|||||||
window.show_message(_('Server not reachable.'))
|
window.show_message(_('Server not reachable.'))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
wallet = window.wallet
|
||||||
d = QDialog(window)
|
d = QDialog(window)
|
||||||
d.setWindowTitle("TrustedCoin Information")
|
d.setWindowTitle("TrustedCoin Information")
|
||||||
d.setMinimumSize(500, 200)
|
d.setMinimumSize(500, 200)
|
||||||
@@ -569,16 +576,17 @@ class Plugin(BasePlugin):
|
|||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
vbox.addLayout(grid)
|
vbox.addLayout(grid)
|
||||||
|
|
||||||
v = self.price_per_tx.get(1)
|
price_per_tx = self.wallets[wallet]['price_per_tx']
|
||||||
|
v = price_per_tx.get(1)
|
||||||
grid.addWidget(QLabel(_("Price per transaction (not prepaid):")), 0, 0)
|
grid.addWidget(QLabel(_("Price per transaction (not prepaid):")), 0, 0)
|
||||||
grid.addWidget(QLabel(window.format_amount(v) + ' ' + window.base_unit()), 0, 1)
|
grid.addWidget(QLabel(window.format_amount(v) + ' ' + window.base_unit()), 0, 1)
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
|
|
||||||
if 10 not in self.price_per_tx:
|
if 10 not in price_per_tx:
|
||||||
self.price_per_tx[10] = 10 * self.price_per_tx.get(1)
|
price_per_tx[10] = 10 * price_per_tx.get(1)
|
||||||
|
|
||||||
for k, v in sorted(self.price_per_tx.items()):
|
for k, v in sorted(price_per_tx.items()):
|
||||||
if k == 1:
|
if k == 1:
|
||||||
continue
|
continue
|
||||||
grid.addWidget(QLabel("Price for %d prepaid transactions:"%k), i, 0)
|
grid.addWidget(QLabel("Price for %d prepaid transactions:"%k), i, 0)
|
||||||
@@ -588,7 +596,7 @@ class Plugin(BasePlugin):
|
|||||||
grid.addWidget(b, i, 2)
|
grid.addWidget(b, i, 2)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
n = self.billing_info.get('tx_remaining', 0)
|
n = self.wallets[wallet]['billing_info'].get('tx_remaining', 0)
|
||||||
grid.addWidget(QLabel(_("Your wallet has %d prepaid transactions.")%n), i, 0)
|
grid.addWidget(QLabel(_("Your wallet has %d prepaid transactions.")%n), i, 0)
|
||||||
|
|
||||||
# tranfer button
|
# tranfer button
|
||||||
@@ -608,21 +616,14 @@ class Plugin(BasePlugin):
|
|||||||
d.close()
|
d.close()
|
||||||
if window.pluginsdialog:
|
if window.pluginsdialog:
|
||||||
window.pluginsdialog.close()
|
window.pluginsdialog.close()
|
||||||
uri = "bitcoin:" + self.billing_info['billing_address'] + "?message=TrustedCoin %d Prepaid Transactions&amount="%k + str(Decimal(v)/100000000)
|
wallet_info = self.wallets[window.wallet]
|
||||||
self.is_billing = True
|
uri = "bitcoin:" + wallet_info['billing_info']['billing_address'] + "?message=TrustedCoin %d Prepaid Transactions&amount="%k + str(Decimal(v)/100000000)
|
||||||
|
wallet_info['is_billing'] = True
|
||||||
window.pay_to_URI(uri)
|
window.pay_to_URI(uri)
|
||||||
window.payto_e.setFrozen(True)
|
window.payto_e.setFrozen(True)
|
||||||
window.message_e.setFrozen(True)
|
window.message_e.setFrozen(True)
|
||||||
window.amount_e.setFrozen(True)
|
window.amount_e.setFrozen(True)
|
||||||
|
|
||||||
def request_billing_info(self):
|
|
||||||
billing_info = server.get(self.user_id)
|
|
||||||
billing_address = self.make_billing_address(billing_info['billing_index'])
|
|
||||||
assert billing_address == billing_info['billing_address']
|
|
||||||
self.billing_info = billing_info
|
|
||||||
self.price_per_tx = dict(self.billing_info['price_per_tx'])
|
|
||||||
return True
|
|
||||||
|
|
||||||
def accept_terms_of_use(self, window):
|
def accept_terms_of_use(self, window):
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
window.set_layout(vbox)
|
window.set_layout(vbox)
|
||||||
@@ -649,7 +650,7 @@ class Plugin(BasePlugin):
|
|||||||
tos_e.setText(self.TOS)
|
tos_e.setText(self.TOS)
|
||||||
|
|
||||||
window.connect(window, SIGNAL('twofactor:TOS'), on_result)
|
window.connect(window, SIGNAL('twofactor:TOS'), on_result)
|
||||||
t = threading.Thread(target=request_TOS)
|
t = Thread(target=request_TOS)
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user