def setupTheBDM(): TheBDM.setBlocking(True) if not TheBDM.getState()==BDM_BLOCKCHAIN_READY: masterWallet.registerWallet() TheBDM.setOnlineMode(True) # Only executed on the first call if blockchain not loaded yet. LOGINFO('Blockchain loading') while not TheBDM.getState()==BDM_BLOCKCHAIN_READY: LOGINFO('Blockchain Not Ready Yet %s' % TheBDM.getState()) time.sleep(2)
def updateOnCoinControl(self): useAllAddr = (self.altBalance == None) wlt = self.main.walletMap[self.getSelectedWltID()] fullBal = wlt.getBalance('Spendable') if useAllAddr: self.dispID.setText(wlt.uniqueIDB58) self.dispName.setText(wlt.labelName) self.dispDescr.setText(wlt.labelDescr) if fullBal == 0: self.dispBal.setText('0.0', color='TextRed', bold=True) else: self.dispBal.setValueText(fullBal, wBold=True) else: self.dispID.setText(wlt.uniqueIDB58 + '*') self.dispName.setText(wlt.labelName + '*') self.dispDescr.setText('*Coin Control Subset*', color='TextBlue', bold=True) self.dispBal.setText(coin2str(self.altBalance, maxZeros=0), color='TextBlue') rawValTxt = str(self.dispBal.text()) self.dispBal.setText(rawValTxt + ' <font color="%s">(of %s)</font>' % \ (htmlColor('DisableFG'), coin2str(fullBal, maxZeros=0))) if not TheBDM.getState() == BDM_BLOCKCHAIN_READY: self.dispBal.setText('(available when online)', color='DisableFG') self.repaint() if self.coinControlCallback: self.coinControlCallback(self.sourceAddrList, self.altBalance)
def setUpClass(self): global doneShuttingDownBDM doneShuttingDownBDM = False # Handle both calling the this test from the context of the test directory # and calling this test from the context of the main directory. # The latter happens if you run all of the tests in the directory if os.path.exists(TIAB_ZIPFILE_NAME): tiabZipPath = TIAB_ZIPFILE_NAME elif os.path.exists(os.path.join('pytest',TIAB_ZIPFILE_NAME)): tiabZipPath = (os.path.join('pytest',TIAB_ZIPFILE_NAME)) else: self.fail(NEED_TIAB_MSG) self.tiab = TiabSession(tiabZipPath=tiabZipPath) newTheBDM() self.armoryHomeDir = os.path.join(self.tiab.tiabDirectory,'tiab','armory') TheBDM.setSatoshiDir(os.path.join(self.tiab.tiabDirectory,'tiab','1','testnet3')) TheBDM.setArmoryDBDir(os.path.join(self.tiab.tiabDirectory,'tiab','armory','databases')) TheBDM.goOnline(armoryDBDir=self.armoryHomeDir) i = 0 while not TheBDM.getState()==BDM_BLOCKCHAIN_READY: time.sleep(2) i += 1 if i >= 60: raise RuntimeError("Timeout waiting for TheBDM to get into BlockchainReady state.")
def __init__(self, parent, main): super(WalletWizard, self).__init__(parent, main) self.newWallet = None self.isBackupCreated = False self.setWindowTitle(tr("Wallet Creation Wizard")) self.setOption(QWizard.HaveFinishButtonOnEarlyPages, on=True) self.setOption(QWizard.IgnoreSubTitles, on=True) # Page 1: Create Wallet self.walletCreationPage = WalletCreationPage(self) self.addPage(self.walletCreationPage) # Page 2: Set Passphrase self.setPassphrasePage = SetPassphrasePage(self) self.addPage(self.setPassphrasePage) # Page 3: Verify Passphrase self.verifyPassphrasePage = VerifyPassphrasePage(self) self.addPage(self.verifyPassphrasePage) # Page 4: Create Paper Backup self.walletBackupPage = WalletBackupPage(self) self.addPage(self.walletBackupPage) # Page 5: Create Watching Only Wallet -- but only if expert, or offline self.hasCWOWPage = False if self.main.usermode == USERMODE.Expert or TheBDM.getState() == BDM_OFFLINE: self.hasCWOWPage = True self.createWOWPage = CreateWatchingOnlyWalletPage(self) self.addPage(self.createWOWPage) self.setButtonLayout([QWizard.BackButton, QWizard.Stretch, QWizard.NextButton, QWizard.FinishButton])
def __init__(self, parent, main): super(WalletWizard, self).__init__(parent, main) self.newWallet = None self.isBackupCreated = False self.setWindowTitle(tr("Wallet Creation Wizard")) self.setOption(QWizard.HaveFinishButtonOnEarlyPages, on=True) self.setOption(QWizard.IgnoreSubTitles, on=True) self.walletCreationId, self.manualEntropyId, self.setPassphraseId, self.verifyPassphraseId, self.walletBackupId, self.WOWId = range( 6) # Page 1: Create Wallet self.walletCreationPage = WalletCreationPage(self) self.setPage(self.walletCreationId, self.walletCreationPage) # Page 1.5: Add manual entropy self.manualEntropyPage = ManualEntropyPage(self) self.setPage(self.manualEntropyId, self.manualEntropyPage) # Page 2: Set Passphrase self.setPassphrasePage = SetPassphrasePage(self) self.setPage(self.setPassphraseId, self.setPassphrasePage) # Page 3: Verify Passphrase self.verifyPassphrasePage = VerifyPassphrasePage(self) self.setPage(self.verifyPassphraseId, self.verifyPassphrasePage) # Page 4: Create Paper Backup self.walletBackupPage = WalletBackupPage(self) self.setPage(self.walletBackupId, self.walletBackupPage) # Page 5: Create Watching Only Wallet -- but only if expert, or offline self.hasCWOWPage = False if self.main.usermode == USERMODE.Expert or TheBDM.getState( ) == BDM_OFFLINE: self.hasCWOWPage = True self.createWOWPage = CreateWatchingOnlyWalletPage(self) self.setPage(self.WOWId, self.createWOWPage) self.setButtonLayout([ QWizard.BackButton, QWizard.Stretch, QWizard.NextButton, QWizard.FinishButton ])
def updateWalletTable(self): numWallets = len(self.main.walletMap) self.wltTable.setRowCount(numWallets) self.wltTable.setColumnCount(4) row = 0 for wltID, wltObj in self.main.walletMap.iteritems(): wltValueBTC = '(...)' wltValueUSD = '(...)' if TheBDM.getState() == BDM_BLOCKCHAIN_READY: convertVal = float(self.lastSellStr.replace(',', '')) wltBal = wltObj.getBalance('Total') wltValueBTC = coin2str(wltBal, maxZeros=2) wltValueUSD = '$' + self.addCommasToPrice( '%0.2f' % (wltBal * convertVal / 1e8)) rowItems = [] rowItems.append(QTableWidgetItem(wltID)) rowItems.append(QTableWidgetItem(wltObj.labelName)) rowItems.append(QTableWidgetItem(wltValueBTC)) rowItems.append(QTableWidgetItem(wltValueUSD)) rowItems[-2].setTextAlignment(Qt.AlignRight) rowItems[-1].setTextAlignment(Qt.AlignRight) rowItems[-2].setFont(GETFONT('Fixed', 10)) rowItems[-1].setFont(GETFONT('Fixed', 10)) for i, item in enumerate(rowItems): self.wltTable.setItem(row, i, item) item.setFlags(Qt.NoItemFlags) self.wltTable.setHorizontalHeaderItem( 0, QTableWidgetItem(tr('Wallet ID'))) self.wltTable.setHorizontalHeaderItem( 1, QTableWidgetItem(tr('Wallet Name'))) self.wltTable.setHorizontalHeaderItem( 2, QTableWidgetItem(tr('BTC Balance'))) self.wltTable.setHorizontalHeaderItem( 3, QTableWidgetItem(tr('USD ($) Value'))) self.wltTable.verticalHeader().hide() row += 1
def updateOnWalletChange(self, ignoredInt=None): """ "ignoredInt" is because the signals should call this function with the selected index of the relevant container, but we grab it again anyway using getSelectedWltID() """ wltID = self.getSelectedWltID() if len(wltID) > 0: wlt = self.main.walletMap[wltID] self.dispID.setText(wltID) self.dispName.setText(wlt.labelName) self.dispDescr.setText(wlt.labelDescr) self.selectedID = wltID if not TheBDM.getState() == BDM_BLOCKCHAIN_READY: self.dispBal.setText('-' * 12) else: bal = wlt.getBalance('Spendable') balStr = coin2str(wlt.getBalance('Spendable'), maxZeros=1) if bal <= self.balAtLeast: self.dispBal.setText('<font color="red"><b>%s</b></font>' % balStr) else: self.dispBal.setText('<b>' + balStr + '</b>') if self.selectWltCallback: self.selectWltCallback(wlt) self.repaint() # Reset the coin control variables after a new wallet is selected if self.coinControlCallback: self.altBalance = None self.sourceAddrList = None self.btnCoinCtrl.setEnabled(wlt.getBalance('Spendable') > 0) self.lblCoinCtrl.setText('Source: All addresses' if wlt.getBalance('Spendable')>0 else\ 'Source: 0 addresses' ) self.updateOnCoinControl()
def updateOnWalletChange(self, ignoredInt=None): """ "ignoredInt" is because the signals should call this function with the selected index of the relevant container, but we grab it again anyway using getSelectedWltID() """ wltID = self.getSelectedWltID() if len(wltID) > 0: wlt = self.main.walletMap[wltID] self.dispID.setText(wltID) self.dispName.setText(wlt.labelName) self.dispDescr.setText(wlt.labelDescr) self.selectedID = wltID if not TheBDM.getState() == BDM_BLOCKCHAIN_READY: self.dispBal.setText('-' * 12) else: bal = wlt.getBalance('Spendable') balStr = coin2str(wlt.getBalance('Spendable'), maxZeros=1) if bal <= self.balAtLeast: self.dispBal.setText('<font color="red"><b>%s</b></font>' % balStr) else: self.dispBal.setText('<b>' + balStr + '</b>') if self.selectWltCallback: self.selectWltCallback(wlt) self.repaint() # Reset the coin control variables after a new wallet is selected if self.coinControlCallback: self.altBalance = None self.sourceAddrList = None self.btnCoinCtrl.setEnabled(wlt.getBalance('Spendable')>0) self.lblCoinCtrl.setText('Source: All addresses' if wlt.getBalance('Spendable')>0 else\ 'Source: 0 addresses' ) self.updateOnCoinControl()
def updateWalletTable(self): numWallets = len(self.main.walletMap) self.wltTable.setRowCount(numWallets) self.wltTable.setColumnCount(4) row = 0 for wltID, wltObj in self.main.walletMap.iteritems(): wltValueBTC = "(...)" wltValueUSD = "(...)" if TheBDM.getState() == BDM_BLOCKCHAIN_READY: convertVal = float(self.lastSellStr.replace(",", "")) wltBal = wltObj.getBalance("Total") wltValueBTC = coin2str(wltBal, maxZeros=2) wltValueUSD = "$" + self.addCommasToPrice("%0.2f" % (wltBal * convertVal / 1e8)) rowItems = [] rowItems.append(QTableWidgetItem(wltID)) rowItems.append(QTableWidgetItem(wltObj.labelName)) rowItems.append(QTableWidgetItem(wltValueBTC)) rowItems.append(QTableWidgetItem(wltValueUSD)) rowItems[-2].setTextAlignment(Qt.AlignRight) rowItems[-1].setTextAlignment(Qt.AlignRight) rowItems[-2].setFont(GETFONT("Fixed", 10)) rowItems[-1].setFont(GETFONT("Fixed", 10)) for i, item in enumerate(rowItems): self.wltTable.setItem(row, i, item) item.setFlags(Qt.NoItemFlags) self.wltTable.setHorizontalHeaderItem(0, QTableWidgetItem(tr("Wallet ID"))) self.wltTable.setHorizontalHeaderItem(1, QTableWidgetItem(tr("Wallet Name"))) self.wltTable.setHorizontalHeaderItem(2, QTableWidgetItem(tr("BTC Balance"))) self.wltTable.setHorizontalHeaderItem(3, QTableWidgetItem(tr("USD ($) Value"))) self.wltTable.verticalHeader().hide() row += 1
if run_LoadBlockchain_Async: """ By setting blocking=False, most calls to TheBDM will return immediately, after queuing the BDM to execute the operation in the background. You have to check back later to see when it's done. However, even when blocking is false, any functions that return data must block so the data can be returned. If you are in asynchronous mode, and don't want to ever wait for anything, always check TheBDM.getState()==BDM_BLOCKCHAIN_READY before requesting data that will force blocking. """ start = RightNow() TheBDM.setBlocking(False) TheBDM.setOnlineMode(True) sleep(2) print 'Waiting for blockchain loading to finish', while not TheBDM.getState()==BDM_BLOCKCHAIN_READY: print '.', sys.stdout.flush() sleep(2) print 'Loading blockchain took %0.1f sec' % (RightNow() - start) topBlock = TheBDM.getTopBlockHeight() print '\n\nCurrent Top Block is:', topBlock TheBDM.blockchain().top().pprint() ################################################################################ if run_LoadBlockchain_Block: start = RightNow() TheBDM.setBlocking(True) TheBDM.setOnlineMode(True) # The setOnlineMode should block until blockchain loading is complete
if run_LoadBlockchain_Async: """ By setting blocking=False, most calls to TheBDM will return immediately, after queuing the BDM to execute the operation in the background. You have to check back later to see when it's done. However, even when blocking is false, any functions that return data must block so the data can be returned. If you are in asynchronous mode, and don't want to ever wait for anything, always check TheBDM.getState()==BDM_BLOCKCHAIN_READY before requesting data that will force blocking. """ start = RightNow() TheBDM.setBlocking(False) TheBDM.setOnlineMode(True) sleep(2) print 'Waiting for blockchain loading to finish', while not TheBDM.getState() == BDM_BLOCKCHAIN_READY: print '.', sys.stdout.flush() sleep(2) print 'Loading blockchain took %0.1f sec' % (RightNow() - start) topBlock = TheBDM.getTopBlockHeight() print '\n\nCurrent Top Block is:', topBlock TheBDM.blockchain().top().pprint() ################################################################################ if run_LoadBlockchain_Block: start = RightNow() TheBDM.setBlocking(True) TheBDM.setOnlineMode(True) # The setOnlineMode should block until blockchain loading is complete