#NEWLINE# def _load_wallet( self ) : #NEWLINE# #INDENT# def get_wallet( ) : #NEWLINE# #INDENT# path = self . config . get_wallet_path ( ) #NEWLINE# storage = WalletStorage ( path ) #NEWLINE# wallet = Wallet ( storage ) #NEWLINE# if ( not storage . file_exists ) : #NEWLINE# #INDENT# self . first_run = True #NEWLINE# seed = wallet . make_seed ( ) #NEWLINE# wallet . add_seed ( seed , None ) #NEWLINE# wallet . create_master_keys ( None ) #NEWLINE# wallet . create_main_account ( ) #NEWLINE# wallet . synchronize ( ) #NEWLINE# #UNINDENT# self . wallet = wallet #NEWLINE# #UNINDENT# blockchain_caught_d = defer . Deferred ( ) #NEWLINE# def check_caught_up( ) : #NEWLINE# #INDENT# local_height = self . network . get_local_height ( ) #NEWLINE# remote_height = self . network . get_server_height ( ) #NEWLINE# if ( ( remote_height != 0 ) and ( ( remote_height - local_height ) <= 5 ) ) : #NEWLINE# #INDENT# msg = '' #NEWLINE# if ( self . _caught_up_counter != 0 ) : #NEWLINE# #INDENT# msg += 'All caught up. ' #NEWLINE# #UNINDENT# msg += 'Wallet loaded.' #NEWLINE# alert . info ( msg ) #NEWLINE# self . _catch_up_check . stop ( ) #NEWLINE# self . _catch_up_check = None #NEWLINE# blockchain_caught_d . callback ( True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( remote_height != 0 ) : #NEWLINE# #INDENT# past_blocks_behind = self . blocks_behind_alert #NEWLINE# self . blocks_behind_alert = ( remote_height - local_height ) #NEWLINE# if ( self . blocks_behind_alert < past_blocks_behind ) : #NEWLINE# #INDENT# self . _lag_counter = 0 #NEWLINE# self . is_lagging = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _lag_counter += 1 #NEWLINE# if ( self . _lag_counter >= 900 ) : #NEWLINE# #INDENT# self . is_lagging = True #NEWLINE# #UNINDENT# #UNINDENT# if ( self . blocks_behind_alert > self . max_behind ) : #NEWLINE# #INDENT# self . max_behind = self . blocks_behind_alert #NEWLINE# #UNINDENT# self . catchup_progress = int ( ( 100 * ( self . blocks_behind_alert / ( 5 + self . max_behind ) ) ) ) #NEWLINE# if ( self . _caught_up_counter == 0 ) : #NEWLINE# #INDENT# alert . info ( 'Catching up to the blockchain...showing blocks left...' ) #NEWLINE# #UNINDENT# if ( ( self . _caught_up_counter % 30 ) == 0 ) : #NEWLINE# #INDENT# alert . info ( '%d...' , ( remote_height - local_height ) ) #NEWLINE# #UNINDENT# self . _caught_up_counter += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . _catch_up_check = task . LoopingCall ( check_caught_up ) #NEWLINE# d = threads . deferToThread ( self ) #NEWLINE# d . addCallback ( self . _save_wallet ) #NEWLINE# d . addCallback ( ( lambda _ : self . wallet . start_threads ( self . network ) ) ) #NEWLINE# d . addCallback ( ( lambda _ : self . _catch_up_check . start ( 0.1 ) ) ) #NEWLINE# d . addCallback ( ( lambda _ : blockchain_caught_d ) ) #NEWLINE# return d