def setupTheBDM(): TheBDM.setBlocking(True) if not TheBDM.isInitialized(): TheBDM.registerWallet(masterWallet) TheBDM.setOnlineMode(True) # Only executed on the first call if blockchain not loaded yet. LOGINFO('Blockchain loading') while not TheBDM.getBDMState()=='BlockchainReady': LOGINFO('Blockchain Not Ready Yet %s' % TheBDM.getBDMState()) 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.getBDMState() == 'BlockchainReady': self.dispBal.setText('(available when online)', color='DisableFG') self.repaint() if self.coinControlCallback: self.coinControlCallback(self.sourceAddrList, self.altBalance)
def setUpClass(self): # 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) # Need to destroy whatever BDM may have been created automatically CppBlockUtils.BlockDataManager().DestroyBDM() newTheBDM() TheBDM.setDaemon(True) TheBDM.start() TheBDM.setSatoshiDir( os.path.join(self.tiab.tiabDirectory, 'tiab', '1', 'testnet3')) self.armoryHomeDir = os.path.join(self.tiab.tiabDirectory, 'tiab', 'armory') TheBDM.setLevelDBDir( os.path.join(self.tiab.tiabDirectory, 'tiab', 'armory', 'databases')) TheBDM.setBlocking(True) TheBDM.setOnlineMode(wait=True) i = 0 while not TheBDM.getBDMState() == 'BlockchainReady' and i < 10: time.sleep(2) i += 1 if i >= 10: raise RuntimeError( "Timeout waiting for TheBDM to get into BlockchainReady state." )
def createNewWalletFromWizard(self): self.newWallet = PyBtcWallet().createNewWallet( \ securePassphrase=self.setPassphrasePage.pageFrame.getPassphrase(), \ kdfTargSec=self.walletCreationPage.pageFrame.getKdfSec(), \ kdfMaxMem=self.walletCreationPage.pageFrame.getKdfBytes(), \ shortLabel=self.walletCreationPage.pageFrame.getName(), \ longLabel=self.walletCreationPage.pageFrame.getDescription(), \ doRegisterWithBDM=False, \ extraEntropy=self.main.getExtraEntropyForKeyGen()) self.newWallet.unlock(securePassphrase=SecureBinaryData( self.setPassphrasePage.pageFrame.getPassphrase())) # We always want to fill the address pool, right away. fillpool = lambda: self.newWallet.fillAddressPool(doRegister=False) DlgExecLongProcess(fillpool, 'Creating Wallet...', self, self).exec_() # Reopening from file helps make sure everything is correct -- don't # let the user use a wallet that triggers errors on reading it wltpath = self.newWallet.walletPath walletFromDisk = PyBtcWallet().readWalletFile(wltpath) self.main.addWalletToApplication(walletFromDisk, walletIsNew=True) if TheBDM.getBDMState() in ('Uninitialized', 'Offline'): TheBDM.registerWallet(walletFromDisk, isFresh=True, wait=False) else: self.main.newWalletList.append([walletFromDisk, True])
def createNewWalletFromWizard(self): self.newWallet = PyBtcWallet().createNewWallet( \ securePassphrase=self.setPassphrasePage.pageFrame.getPassphrase(), \ kdfTargSec=self.walletCreationPage.pageFrame.getKdfSec(), \ kdfMaxMem=self.walletCreationPage.pageFrame.getKdfBytes(), \ shortLabel=self.walletCreationPage.pageFrame.getName(), \ longLabel=self.walletCreationPage.pageFrame.getDescription(), \ doRegisterWithBDM=False, \ extraEntropy=self.main.getExtraEntropyForKeyGen()) self.newWallet.unlock(securePassphrase= SecureBinaryData(self.setPassphrasePage.pageFrame.getPassphrase())) # We always want to fill the address pool, right away. fillPoolProgress = DlgProgress(self, self.main, HBar=1, \ Title="Creating Wallet") fillPoolProgress.exec_(self.newWallet.fillAddressPool, doRegister=False, Progress=fillPoolProgress.UpdateHBar) # Reopening from file helps make sure everything is correct -- don't # let the user use a wallet that triggers errors on reading it wltpath = self.newWallet.walletPath walletFromDisk = PyBtcWallet().readWalletFile(wltpath) self.main.addWalletToApplication(walletFromDisk, walletIsNew=True) if TheBDM.getBDMState() in ('Uninitialized', 'Offline'): TheBDM.registerWallet(walletFromDisk, isFresh=True, wait=False) else: self.main.newWalletList.append([walletFromDisk, True])
def setUpClass(self): # This is not a UI so no need to worry about the main thread being blocked. # Any UI that uses this Daemon can put the call to the Daemon on it's own thread. TheBDM.setBlocking(True) TheBDM.setOnlineMode(True) while not TheBDM.getBDMState() == 'BlockchainReady': time.sleep(2)
def setUpClass(self): # This is not a UI so no need to worry about the main thread being blocked. # Any UI that uses this Daemon can put the call to the Daemon on it's own thread. TheBDM.setBlocking(True) TheBDM.setOnlineMode(True) while not TheBDM.getBDMState()=='BlockchainReady': time.sleep(2)
def setUpClass(self): # 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) # Need to destroy whatever BDM may have been created automatically CppBlockUtils.BlockDataManager().DestroyBDM() newTheBDM() TheBDM.setDaemon(True) TheBDM.start() TheBDM.setSatoshiDir(os.path.join(self.tiab.tiabDirectory,'tiab','1','testnet3')) self.armoryHomeDir = os.path.join(self.tiab.tiabDirectory,'tiab','armory') TheBDM.setLevelDBDir(os.path.join(self.tiab.tiabDirectory,'tiab','armory','databases')) TheBDM.setBlocking(True) TheBDM.setOnlineMode(wait=True) i = 0 while not TheBDM.getBDMState()=='BlockchainReady' and i < 10: time.sleep(2) i += 1 if i >= 10: raise RuntimeError("Timeout waiting for TheBDM to get into BlockchainReady state.")
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.getBDMState() == 'BlockchainReady': 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.getBDMState() == 'BlockchainReady': 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.getBDMState()=='BlockchainReady': 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