2015-06-26 05:29:26 -07:00
import re
import sys
import threading
2013-08-22 03:39:41 -07:00
from PyQt4 . QtGui import *
from PyQt4 . QtCore import *
import PyQt4 . QtCore as QtCore
2014-08-31 06:33:20 -07:00
import electrum
2013-09-11 04:55:49 -07:00
from electrum . i18n import _
2015-06-26 05:29:26 -07:00
from electrum import Wallet
2014-07-01 09:46:11 -07:00
from electrum import bitcoin
from electrum import util
2013-08-29 07:07:55 -07:00
2014-04-19 11:23:27 -07:00
import seed_dialog
2013-08-22 03:39:41 -07:00
from network_dialog import NetworkDialog
2013-09-24 07:57:12 -07:00
from util import *
2013-08-29 07:07:55 -07:00
from amountedit import AmountEdit
2015-06-10 03:40:08 -07:00
from electrum . plugins import always_hook , run_hook
2014-09-13 10:31:05 -07:00
from electrum . mnemonic import prepare_seed
2014-04-29 12:19:42 -07:00
2015-06-27 23:52:16 -07:00
MSG_ENTER_ANYTHING = _ ( " Please enter a seed phrase, a master key, a list of Bitcoin addresses, or a list of private keys " )
MSG_SHOW_MPK = _ ( " Here is your master public key " )
2014-04-29 12:19:42 -07:00
MSG_ENTER_MPK = _ ( " Please enter your master public key " )
2015-06-27 23:52:16 -07:00
MSG_ENTER_SEED_OR_MPK = _ ( " Please enter a seed phrase or a master key (xpub or xprv) " )
2014-04-29 12:19:42 -07:00
MSG_VERIFY_SEED = _ ( " Your seed is important! " ) + " \n " + _ ( " To make sure that you have properly saved your seed, please retype it here. " )
2015-06-26 05:29:26 -07:00
class CosignWidget ( QWidget ) :
size = 120
def __init__ ( self , m , n ) :
QWidget . __init__ ( self )
self . R = QRect ( 0 , 0 , self . size , self . size )
self . setGeometry ( self . R )
self . m = m
self . n = n
def set_n ( self , n ) :
self . n = n
self . update ( )
def set_m ( self , m ) :
self . m = m
self . update ( )
def paintEvent ( self , event ) :
import math
bgcolor = self . palette ( ) . color ( QPalette . Background )
pen = QPen ( bgcolor , 7 , QtCore . Qt . SolidLine )
qp = QPainter ( )
qp . begin ( self )
qp . setPen ( pen )
qp . setRenderHint ( QPainter . Antialiasing )
qp . setBrush ( Qt . gray )
for i in range ( self . n ) :
alpha = int ( 16 * 360 * i / self . n )
alpha2 = int ( 16 * 360 * 1 / self . n )
qp . setBrush ( Qt . green if i < self . m else Qt . gray )
qp . drawPie ( self . R , alpha , alpha2 )
qp . end ( )
2013-08-22 03:39:41 -07:00
class InstallWizard ( QDialog ) :
2015-08-22 02:23:54 -07:00
def __init__ ( self , config , network , storage , parent ) :
QDialog . __init__ ( self , parent )
self . app = parent . app
2013-08-22 03:39:41 -07:00
self . config = config
2013-09-10 05:20:44 -07:00
self . network = network
2013-09-01 06:26:52 -07:00
self . storage = storage
2013-09-12 10:42:00 -07:00
self . setMinimumSize ( 575 , 400 )
2014-08-26 07:23:24 -07:00
self . setMaximumSize ( 575 , 400 )
2015-06-26 05:29:26 -07:00
self . setWindowTitle ( ' Electrum ' + ' - ' + _ ( ' Install Wizard ' ) )
2013-09-12 10:42:00 -07:00
self . connect ( self , QtCore . SIGNAL ( ' accept ' ) , self . accept )
2013-11-03 02:03:45 -08:00
self . stack = QStackedLayout ( )
self . setLayout ( self . stack )
def set_layout ( self , layout ) :
w = QWidget ( )
w . setLayout ( layout )
2014-09-19 11:23:24 -07:00
self . stack . addWidget ( w )
self . stack . setCurrentWidget ( w )
2015-03-07 23:07:30 -08:00
self . show ( )
2013-08-22 03:39:41 -07:00
def restore_or_create ( self ) :
2014-05-09 04:12:07 -07:00
vbox = QVBoxLayout ( )
main_label = QLabel ( _ ( " Electrum could not find an existing wallet. " ) )
vbox . addWidget ( main_label )
2013-09-03 05:32:56 -07:00
grid = QGridLayout ( )
grid . setSpacing ( 5 )
2014-09-05 07:14:40 -07:00
gb1 = QGroupBox ( _ ( " What do you want to do? " ) )
vbox . addWidget ( gb1 )
2014-05-09 04:12:07 -07:00
b1 = QRadioButton ( gb1 )
2013-09-03 05:32:56 -07:00
b1 . setText ( _ ( " Create new wallet " ) )
b1 . setChecked ( True )
2014-05-09 04:12:07 -07:00
b2 = QRadioButton ( gb1 )
2015-03-08 00:14:11 -08:00
b2 . setText ( _ ( " Restore a wallet or import keys " ) )
2014-09-05 07:14:40 -07:00
group1 = QButtonGroup ( )
2014-05-09 04:12:07 -07:00
group1 . addButton ( b1 )
group1 . addButton ( b2 )
2014-09-05 07:14:40 -07:00
vbox . addWidget ( b1 )
vbox . addWidget ( b2 )
2013-09-03 05:32:56 -07:00
2014-09-05 07:14:40 -07:00
gb2 = QGroupBox ( _ ( " Wallet type: " ) )
vbox . addWidget ( gb2 )
2014-05-09 04:12:07 -07:00
group2 = QButtonGroup ( )
2014-09-05 07:14:40 -07:00
self . wallet_types = [
( ' standard ' , _ ( " Standard wallet " ) ) ,
2014-09-05 07:28:53 -07:00
( ' twofactor ' , _ ( " Wallet with two-factor authentication " ) ) ,
2014-09-05 08:25:15 -07:00
( ' multisig ' , _ ( " Multi-signature wallet " ) ) ,
2014-09-05 07:14:40 -07:00
( ' hardware ' , _ ( " Hardware wallet " ) ) ,
]
2014-09-05 07:28:53 -07:00
for i , ( wtype , name ) in enumerate ( self . wallet_types ) :
if not filter ( lambda x : x [ 0 ] == wtype , electrum . wallet . wallet_types ) :
continue
2014-07-01 09:46:11 -07:00
button = QRadioButton ( gb2 )
2014-09-05 07:28:53 -07:00
button . setText ( name )
2014-09-05 07:14:40 -07:00
vbox . addWidget ( button )
2014-07-01 09:46:11 -07:00
group2 . addButton ( button )
group2 . setId ( button , i )
if i == 0 :
button . setChecked ( True )
2014-05-09 04:12:07 -07:00
2013-09-12 10:42:00 -07:00
vbox . addStretch ( 1 )
2014-05-09 04:12:07 -07:00
self . set_layout ( vbox )
2015-04-17 04:13:35 -07:00
vbox . addLayout ( Buttons ( CancelButton ( self ) , OkButton ( self , _ ( ' Next ' ) ) ) )
2014-05-26 09:59:05 -07:00
self . show ( )
self . raise_ ( )
2013-09-12 10:42:00 -07:00
if not self . exec_ ( ) :
2014-05-09 04:12:07 -07:00
return None , None
2014-10-21 10:05:51 -07:00
2014-05-09 04:12:07 -07:00
action = ' create ' if b1 . isChecked ( ) else ' restore '
2014-07-01 09:46:11 -07:00
wallet_type = self . wallet_types [ group2 . checkedId ( ) ] [ 0 ]
return action , wallet_type
2013-08-22 03:39:41 -07:00
2014-09-11 01:43:14 -07:00
def verify_seed ( self , seed , sid , func = None ) :
r = self . enter_seed_dialog ( MSG_VERIFY_SEED , sid , func )
2013-09-03 05:32:56 -07:00
if not r :
return
2014-09-13 10:31:05 -07:00
if prepare_seed ( r ) != prepare_seed ( seed ) :
2013-09-16 20:19:23 -07:00
QMessageBox . warning ( None , _ ( ' Error ' ) , _ ( ' Incorrect seed ' ) , _ ( ' OK ' ) )
2013-08-22 03:39:41 -07:00
return False
else :
return True
2014-04-19 11:23:27 -07:00
def get_seed_text ( self , seed_e ) :
2014-04-22 06:49:32 -07:00
text = unicode ( seed_e . toPlainText ( ) ) . strip ( )
2014-04-22 06:12:36 -07:00
text = ' ' . join ( text . split ( ) )
return text
2013-08-22 03:39:41 -07:00
2014-09-09 02:51:45 -07:00
def is_any ( self , text ) :
2014-06-25 07:45:55 -07:00
return Wallet . is_seed ( text ) or Wallet . is_old_mpk ( text ) or Wallet . is_xpub ( text ) or Wallet . is_xprv ( text ) or Wallet . is_address ( text ) or Wallet . is_private_key ( text )
2013-09-12 10:42:00 -07:00
2014-09-09 02:51:45 -07:00
def is_mpk ( self , text ) :
2014-06-25 07:45:55 -07:00
return Wallet . is_xpub ( text ) or Wallet . is_old_mpk ( text )
2014-05-09 04:49:05 -07:00
2014-09-09 02:51:45 -07:00
def enter_seed_dialog ( self , msg , sid , func = None ) :
if func is None :
func = self . is_any
2014-10-24 06:45:10 -07:00
vbox , seed_e = seed_dialog . enter_seed_box ( msg , self , sid )
2013-09-12 10:42:00 -07:00
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
button = OkButton ( self , _ ( ' Next ' ) )
vbox . addLayout ( Buttons ( CancelButton ( self ) , button ) )
2014-04-19 11:23:27 -07:00
button . setEnabled ( False )
2014-09-09 02:51:45 -07:00
seed_e . textChanged . connect ( lambda : button . setEnabled ( func ( self . get_seed_text ( seed_e ) ) ) )
2013-11-03 02:03:45 -08:00
self . set_layout ( vbox )
2013-09-12 10:42:00 -07:00
if not self . exec_ ( ) :
return
2014-04-19 11:23:27 -07:00
return self . get_seed_text ( seed_e )
2013-08-22 03:39:41 -07:00
2014-05-12 01:53:04 -07:00
def multi_mpk_dialog ( self , xpub_hot , n ) :
2014-05-09 07:27:12 -07:00
vbox = QVBoxLayout ( )
2015-06-27 15:47:25 -07:00
scroll = QScrollArea ( )
scroll . setEnabled ( True )
scroll . setWidgetResizable ( True )
vbox . addWidget ( scroll )
w = QWidget ( )
scroll . setWidget ( w )
innerVbox = QVBoxLayout ( )
w . setLayout ( innerVbox )
2015-02-02 04:54:03 -08:00
vbox0 = seed_dialog . show_seed_box ( MSG_SHOW_MPK , xpub_hot , ' hot ' )
2015-06-27 15:47:25 -07:00
innerVbox . addLayout ( vbox0 )
2014-05-12 01:53:04 -07:00
entries = [ ]
for i in range ( n ) :
2015-06-27 23:52:16 -07:00
msg = _ ( " Please enter the master public key of cosigner " ) + ' %d ' % ( i + 1 )
vbox2 , seed_e2 = seed_dialog . enter_seed_box ( msg , self , ' cold ' )
2015-06-27 15:47:25 -07:00
innerVbox . addLayout ( vbox2 )
2014-05-12 01:53:04 -07:00
entries . append ( seed_e2 )
2014-05-09 07:27:12 -07:00
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
button = OkButton ( self , _ ( ' Next ' ) )
vbox . addLayout ( Buttons ( CancelButton ( self ) , button ) )
2014-05-09 07:27:12 -07:00
button . setEnabled ( False )
2014-09-09 02:51:45 -07:00
f = lambda : button . setEnabled ( map ( lambda e : Wallet . is_xpub ( self . get_seed_text ( e ) ) , entries ) == [ True ] * len ( entries ) )
2014-05-12 01:53:04 -07:00
for e in entries :
e . textChanged . connect ( f )
2014-05-09 07:27:12 -07:00
self . set_layout ( vbox )
if not self . exec_ ( ) :
2014-05-12 01:53:04 -07:00
return
return map ( lambda e : self . get_seed_text ( e ) , entries )
2014-05-09 07:27:12 -07:00
2014-05-12 01:53:04 -07:00
def multi_seed_dialog ( self , n ) :
2014-04-19 11:23:27 -07:00
vbox = QVBoxLayout ( )
2015-06-27 15:47:25 -07:00
scroll = QScrollArea ( )
scroll . setEnabled ( True )
scroll . setWidgetResizable ( True )
vbox . addWidget ( scroll )
w = QWidget ( )
scroll . setWidget ( w )
innerVbox = QVBoxLayout ( )
w . setLayout ( innerVbox )
2014-11-10 15:09:22 -08:00
vbox1 , seed_e1 = seed_dialog . enter_seed_box ( MSG_ENTER_SEED_OR_MPK , self , ' hot ' )
2015-06-27 15:47:25 -07:00
innerVbox . addLayout ( vbox1 )
2014-05-12 01:53:04 -07:00
entries = [ seed_e1 ]
for i in range ( n ) :
2014-11-10 15:09:22 -08:00
vbox2 , seed_e2 = seed_dialog . enter_seed_box ( MSG_ENTER_SEED_OR_MPK , self , ' cold ' )
2015-06-27 15:47:25 -07:00
innerVbox . addLayout ( vbox2 )
2014-05-12 01:53:04 -07:00
entries . append ( seed_e2 )
2014-04-19 11:23:27 -07:00
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
button = OkButton ( self , _ ( ' Next ' ) )
vbox . addLayout ( Buttons ( CancelButton ( self ) , button ) )
2014-04-19 11:23:27 -07:00
button . setEnabled ( False )
2014-09-09 02:51:45 -07:00
f = lambda : button . setEnabled ( map ( lambda e : self . is_any ( self . get_seed_text ( e ) ) , entries ) == [ True ] * len ( entries ) )
2014-05-12 01:53:04 -07:00
for e in entries :
e . textChanged . connect ( f )
2014-04-19 11:23:27 -07:00
self . set_layout ( vbox )
if not self . exec_ ( ) :
2014-10-21 10:05:51 -07:00
return
2014-05-12 01:53:04 -07:00
return map ( lambda e : self . get_seed_text ( e ) , entries )
2014-04-05 01:34:51 -07:00
2013-09-30 07:53:51 -07:00
def waiting_dialog ( self , task , msg = _ ( " Electrum is generating your addresses, please wait. " ) ) :
2013-09-12 10:42:00 -07:00
def target ( ) :
task ( )
self . emit ( QtCore . SIGNAL ( ' accept ' ) )
2013-11-03 02:03:45 -08:00
vbox = QVBoxLayout ( )
2013-09-12 10:42:00 -07:00
self . waiting_label = QLabel ( msg )
vbox . addWidget ( self . waiting_label )
2013-11-03 02:03:45 -08:00
self . set_layout ( vbox )
2013-09-12 10:42:00 -07:00
t = threading . Thread ( target = target )
t . start ( )
self . exec_ ( )
2013-09-03 09:35:46 -07:00
2013-08-22 03:39:41 -07:00
def network_dialog ( self ) :
2014-08-27 05:01:05 -07:00
# skip this if config already exists
if self . config . get ( ' server ' ) is not None :
return
2014-10-21 10:05:51 -07:00
2013-09-03 05:32:56 -07:00
grid = QGridLayout ( )
grid . setSpacing ( 5 )
2013-10-03 10:09:08 -07:00
label = QLabel ( _ ( " Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfil the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random if you have a preference though feel free to select a server manually. " ) + " \n \n " \
2013-10-09 18:54:52 -07:00
+ _ ( " How do you want to connect to a server: " ) + " " )
2013-09-30 07:53:51 -07:00
label . setWordWrap ( True )
2013-09-03 05:32:56 -07:00
grid . addWidget ( label , 0 , 0 )
gb = QGroupBox ( )
b1 = QRadioButton ( gb )
b1 . setText ( _ ( " Auto connect " ) )
b1 . setChecked ( True )
b2 = QRadioButton ( gb )
b2 . setText ( _ ( " Select server manually " ) )
2013-10-03 10:09:08 -07:00
#b3 = QRadioButton(gb)
#b3.setText(_("Stay offline"))
2013-09-03 05:32:56 -07:00
grid . addWidget ( b1 , 1 , 0 )
grid . addWidget ( b2 , 2 , 0 )
2013-10-03 10:09:08 -07:00
#grid.addWidget(b3,3,0)
2013-09-03 05:32:56 -07:00
2013-11-03 02:03:45 -08:00
vbox = QVBoxLayout ( )
2013-09-03 05:32:56 -07:00
vbox . addLayout ( grid )
2013-09-12 10:42:00 -07:00
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
vbox . addLayout ( Buttons ( CancelButton ( self ) , OkButton ( self , _ ( ' Next ' ) ) ) )
2013-09-12 10:42:00 -07:00
2013-11-03 02:03:45 -08:00
self . set_layout ( vbox )
2013-09-12 10:42:00 -07:00
if not self . exec_ ( ) :
2013-09-03 05:32:56 -07:00
return
2014-10-21 10:05:51 -07:00
2013-09-03 05:32:56 -07:00
if b2 . isChecked ( ) :
2013-09-10 09:27:32 -07:00
return NetworkDialog ( self . network , self . config , None ) . do_exec ( )
2014-08-27 05:01:05 -07:00
else :
2015-05-25 00:18:52 -07:00
self . config . set_key ( ' auto_connect ' , True , True )
2013-09-03 05:32:56 -07:00
return
2014-10-21 10:05:51 -07:00
2014-04-28 07:06:59 -07:00
def show_message ( self , msg , icon = None ) :
2014-04-06 12:38:53 -07:00
vbox = QVBoxLayout ( )
2014-04-28 07:06:59 -07:00
self . set_layout ( vbox )
if icon :
logo = QLabel ( )
logo . setPixmap ( icon )
vbox . addWidget ( logo )
2014-04-06 12:38:53 -07:00
vbox . addWidget ( QLabel ( msg ) )
vbox . addStretch ( 1 )
2015-03-23 00:09:08 -07:00
vbox . addLayout ( Buttons ( CloseButton ( self ) ) )
2014-10-21 10:05:51 -07:00
if not self . exec_ ( ) :
2014-04-06 12:38:53 -07:00
return None
2014-04-28 07:06:59 -07:00
2014-09-05 07:14:40 -07:00
def choice ( self , title , msg , choices ) :
vbox = QVBoxLayout ( )
self . set_layout ( vbox )
vbox . addWidget ( QLabel ( title ) )
gb2 = QGroupBox ( msg )
vbox . addWidget ( gb2 )
group2 = QButtonGroup ( )
for i , c in enumerate ( choices ) :
button = QRadioButton ( gb2 )
button . setText ( c [ 1 ] )
vbox . addWidget ( button )
group2 . addButton ( button )
group2 . setId ( button , i )
if i == 0 :
button . setChecked ( True )
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
vbox . addLayout ( Buttons ( CancelButton ( self ) , OkButton ( self , _ ( ' Next ' ) ) ) )
2014-09-05 07:14:40 -07:00
if not self . exec_ ( ) :
return
wallet_type = choices [ group2 . checkedId ( ) ] [ 0 ]
return wallet_type
2015-06-26 05:29:26 -07:00
def multisig_choice ( self ) :
vbox = QVBoxLayout ( )
self . set_layout ( vbox )
vbox . addWidget ( QLabel ( _ ( " Multi Signature Wallet " ) ) )
cw = CosignWidget ( 2 , 2 )
vbox . addWidget ( cw , 1 )
vbox . addWidget ( QLabel ( _ ( " Please choose the number of signatures needed to unlock funds in your wallet " ) + ' : ' ) )
m_edit = QSpinBox ( )
n_edit = QSpinBox ( )
m_edit . setValue ( 2 )
n_edit . setValue ( 2 )
n_edit . setMinimum ( 2 )
n_edit . setMaximum ( 15 )
m_edit . setMinimum ( 1 )
m_edit . setMaximum ( 2 )
n_edit . valueChanged . connect ( m_edit . setMaximum )
n_edit . valueChanged . connect ( cw . set_n )
m_edit . valueChanged . connect ( cw . set_m )
hbox = QHBoxLayout ( )
hbox . addWidget ( QLabel ( _ ( ' Require ' ) ) )
hbox . addWidget ( m_edit )
hbox . addWidget ( QLabel ( _ ( ' of ' ) ) )
hbox . addWidget ( n_edit )
hbox . addWidget ( QLabel ( _ ( ' signatures ' ) ) )
hbox . addStretch ( 1 )
vbox . addLayout ( hbox )
vbox . addStretch ( 1 )
vbox . addLayout ( Buttons ( CancelButton ( self ) , OkButton ( self , _ ( ' Next ' ) ) ) )
if not self . exec_ ( ) :
return
m = int ( m_edit . value ( ) )
n = int ( n_edit . value ( ) )
wallet_type = ' %d of %d ' % ( m , n )
return wallet_type
2014-08-26 07:23:24 -07:00
def question ( self , msg , yes_label = _ ( ' OK ' ) , no_label = _ ( ' Cancel ' ) , icon = None ) :
2014-04-06 12:38:53 -07:00
vbox = QVBoxLayout ( )
2014-04-28 07:06:59 -07:00
self . set_layout ( vbox )
if icon :
logo = QLabel ( )
logo . setPixmap ( icon )
vbox . addWidget ( logo )
2014-08-26 07:23:24 -07:00
label = QLabel ( msg )
label . setWordWrap ( True )
vbox . addWidget ( label )
2014-04-06 12:38:53 -07:00
vbox . addStretch ( 1 )
2015-03-14 04:28:19 -07:00
vbox . addLayout ( Buttons ( CancelButton ( self , no_label ) , OkButton ( self , yes_label ) ) )
2014-10-21 10:05:51 -07:00
if not self . exec_ ( ) :
2014-04-06 12:38:53 -07:00
return None
return True
2013-08-22 03:39:41 -07:00
2014-04-06 12:38:53 -07:00
def show_seed ( self , seed , sid ) :
2015-02-02 04:54:03 -08:00
vbox = seed_dialog . show_seed_box_msg ( seed , sid )
2015-03-14 04:28:19 -07:00
vbox . addLayout ( Buttons ( CancelButton ( self ) , OkButton ( self , _ ( " Next " ) ) ) )
2013-11-03 02:03:45 -08:00
self . set_layout ( vbox )
2013-11-12 13:55:42 -08:00
return self . exec_ ( )
2013-08-22 03:39:41 -07:00
2014-04-21 13:09:15 -07:00
def password_dialog ( self ) :
2013-09-12 10:42:00 -07:00
msg = _ ( " Please choose a password to encrypt your wallet keys. " ) + ' \n ' \
+ _ ( " Leave these fields empty if you want to disable encryption. " )
from password_dialog import make_password_dialog , run_password_dialog
2014-04-21 13:09:15 -07:00
self . set_layout ( make_password_dialog ( self , None , msg ) )
return run_password_dialog ( self , None , self ) [ 2 ]
2013-08-22 03:39:41 -07:00
2015-04-20 01:33:32 -07:00
def run ( self , action , wallet_type ) :
2014-05-09 07:27:12 -07:00
2015-04-20 01:33:32 -07:00
if action in [ ' create ' , ' restore ' ] :
2014-09-05 07:14:40 -07:00
if wallet_type == ' multisig ' :
2015-06-26 05:29:26 -07:00
wallet_type = self . multisig_choice ( )
2014-09-05 07:14:40 -07:00
if not wallet_type :
return
elif wallet_type == ' hardware ' :
2014-09-05 07:41:51 -07:00
hardware_wallets = map ( lambda x : ( x [ 1 ] , x [ 2 ] ) , filter ( lambda x : x [ 0 ] == ' hardware ' , electrum . wallet . wallet_types ) )
2014-09-05 07:14:40 -07:00
wallet_type = self . choice ( _ ( " Hardware Wallet " ) , ' Select your hardware wallet ' , hardware_wallets )
if not wallet_type :
return
2014-09-05 07:41:51 -07:00
elif wallet_type == ' twofactor ' :
wallet_type = ' 2fa '
2014-08-21 10:13:26 -07:00
if action == ' create ' :
2014-09-19 05:30:16 -07:00
self . storage . put ( ' wallet_type ' , wallet_type , False )
2014-08-21 10:13:26 -07:00
2014-07-01 09:46:11 -07:00
if action is None :
2014-04-06 12:38:53 -07:00
return
2014-08-21 10:13:26 -07:00
2014-07-01 09:46:11 -07:00
if action == ' restore ' :
wallet = self . restore ( wallet_type )
if not wallet :
2014-04-06 12:38:53 -07:00
return
2014-07-01 09:46:11 -07:00
action = None
2014-08-21 10:13:26 -07:00
else :
2014-07-01 09:46:11 -07:00
wallet = Wallet ( self . storage )
action = wallet . get_action ( )
# fixme: password is only needed for multiple accounts
password = None
2014-05-09 07:27:12 -07:00
2015-06-10 03:40:08 -07:00
# load wallet in plugins
2015-06-11 00:36:19 -07:00
always_hook ( ' installwizard_load_wallet ' , wallet , self )
2015-06-10 03:40:08 -07:00
2014-07-01 09:46:11 -07:00
while action is not None :
util . print_error ( " installwizard: " , wallet , action )
2014-04-06 12:38:53 -07:00
2014-07-01 09:46:11 -07:00
if action == ' create_seed ' :
2015-05-09 23:31:31 -07:00
lang = self . config . get ( ' language ' )
seed = wallet . make_seed ( lang )
2014-07-01 09:46:11 -07:00
if not self . show_seed ( seed , None ) :
return
if not self . verify_seed ( seed , None ) :
return
password = self . password_dialog ( )
wallet . add_seed ( seed , password )
2014-08-29 05:11:59 -07:00
wallet . create_master_keys ( password )
2013-08-22 03:39:41 -07:00
2015-06-26 05:29:26 -07:00
elif action == ' add_cosigners ' :
n = int ( re . match ( ' ( \ d+)of( \ d+) ' , wallet . wallet_type ) . group ( 2 ) )
2014-08-13 07:05:43 -07:00
xpub1 = wallet . master_public_keys . get ( " x1/ " )
2015-06-26 05:29:26 -07:00
r = self . multi_mpk_dialog ( xpub1 , n - 1 )
2014-07-01 09:46:11 -07:00
if not r :
return
2015-06-26 05:29:26 -07:00
for i , xpub in enumerate ( r ) :
wallet . add_master_public_key ( " x %d / " % ( i + 2 ) , xpub )
2014-06-02 12:54:53 -07:00
2014-07-01 09:46:11 -07:00
elif action == ' create_accounts ' :
2014-12-31 10:21:54 -08:00
wallet . create_main_account ( password )
2014-05-09 07:27:12 -07:00
self . waiting_dialog ( wallet . synchronize )
2014-07-01 09:46:11 -07:00
else :
2015-04-18 05:59:46 -07:00
f = always_hook ( ' get_wizard_action ' , self , wallet , action )
2014-10-21 10:05:51 -07:00
if not f :
2014-08-26 07:23:24 -07:00
raise BaseException ( ' unknown wizard action ' , action )
r = f ( wallet , self )
if not r :
return
2014-04-29 02:45:39 -07:00
2014-07-01 09:46:11 -07:00
# next action
action = wallet . get_action ( )
2014-05-09 07:27:12 -07:00
2014-07-01 09:46:11 -07:00
if self . network :
if self . network . interfaces :
self . network_dialog ( )
else :
QMessageBox . information ( None , _ ( ' Warning ' ) , _ ( ' You are offline ' ) , _ ( ' OK ' ) )
self . network . stop ( )
self . network = None
2013-11-12 13:55:42 -08:00
2014-07-01 09:46:11 -07:00
# start wallet threads
wallet . start_threads ( self . network )
2014-04-28 08:30:48 -07:00
if action == ' restore ' :
2014-07-01 09:46:11 -07:00
self . waiting_dialog ( lambda : wallet . restore ( self . waiting_label . setText ) )
if self . network :
2014-08-21 00:49:34 -07:00
msg = _ ( " Recovery successful " ) if wallet . is_found ( ) else _ ( " No transactions found for this seed " )
2014-07-01 09:46:11 -07:00
else :
2014-08-21 00:49:34 -07:00
msg = _ ( " This wallet was restored offline. It may contain more addresses than displayed. " )
QMessageBox . information ( None , _ ( ' Information ' ) , msg , _ ( ' OK ' ) )
2014-07-01 09:46:11 -07:00
return wallet
def restore ( self , t ) :
2013-12-13 08:30:34 -08:00
2014-04-19 11:23:27 -07:00
if t == ' standard ' :
2014-04-29 12:19:42 -07:00
text = self . enter_seed_dialog ( MSG_ENTER_ANYTHING , None )
2014-04-29 10:33:42 -07:00
if not text :
return
2014-08-21 01:27:30 -07:00
if Wallet . is_xprv ( text ) :
2014-06-25 07:45:55 -07:00
password = self . password_dialog ( )
wallet = Wallet . from_xprv ( text , password , self . storage )
elif Wallet . is_old_mpk ( text ) :
wallet = Wallet . from_old_mpk ( text , self . storage )
elif Wallet . is_xpub ( text ) :
wallet = Wallet . from_xpub ( text , self . storage )
2014-04-29 12:04:16 -07:00
elif Wallet . is_address ( text ) :
wallet = Wallet . from_address ( text , self . storage )
elif Wallet . is_private_key ( text ) :
2015-01-22 15:06:17 -08:00
password = self . password_dialog ( )
wallet = Wallet . from_private_key ( text , password , self . storage )
2014-08-21 01:27:30 -07:00
elif Wallet . is_seed ( text ) :
password = self . password_dialog ( )
2015-04-03 02:27:57 -07:00
wallet = Wallet . from_seed ( text , password , self . storage )
2014-04-19 11:23:27 -07:00
else :
2014-08-21 00:49:34 -07:00
raise BaseException ( ' unknown wallet type ' )
2014-04-19 11:23:27 -07:00
2015-06-26 05:29:26 -07:00
elif re . match ( ' ( \ d+)of( \ d+) ' , t ) :
n = int ( re . match ( ' ( \ d+)of( \ d+) ' , t ) . group ( 2 ) )
key_list = self . multi_seed_dialog ( n - 1 )
2015-04-03 02:27:57 -07:00
if not key_list :
2014-05-12 01:53:04 -07:00
return
2015-04-03 02:27:57 -07:00
password = self . password_dialog ( ) if any ( map ( lambda x : Wallet . is_seed ( x ) or Wallet . is_xprv ( x ) , key_list ) ) else None
2015-06-27 13:12:15 -07:00
wallet = Wallet . from_multisig ( key_list , password , self . storage , t )
2014-05-12 01:53:04 -07:00
2014-04-20 01:42:13 -07:00
else :
2015-06-11 00:56:38 -07:00
self . storage . put ( ' wallet_type ' , t , False )
# call the constructor to load the plugin (side effect)
Wallet ( self . storage )
2015-04-18 05:59:46 -07:00
wallet = always_hook ( ' installwizard_restore ' , self , self . storage )
2014-07-12 10:41:57 -07:00
if not wallet :
2015-06-11 00:56:38 -07:00
util . print_error ( " no wallet " )
2014-07-12 10:41:57 -07:00
return
2014-04-19 11:23:27 -07:00
2014-07-01 09:46:11 -07:00
# create first keys offline
self . waiting_dialog ( wallet . synchronize )
2014-10-21 10:05:51 -07:00
2014-07-01 09:46:11 -07:00
return wallet