Esempio n. 1
0
def getModuleList(inDir):
    moduleMap = {}
    if not os.path.exists(inDir):
        return moduleMap

    for fn in os.listdir(inDir):
        if not fn.endswith('.py') and not fn.endswith('.sig'):
            continue

        try:
            modName = fn.split('.')[0]
            fullfn = os.path.join(inDir, fn)
            with open(fullfn, 'r') as f:
                fileData = f.read()

            if not modName in moduleMap:
                moduleMap[modName] = {}

            if fn.endswith('.py'):
                moduleMap[modName]['SourceCode'] = fileData
                moduleMap[modName]['SourceDir'] = inDir
                moduleMap[modName]['Filename'] = fn
            elif fn.endswith('.sig'):
                moduleMap[modName]['SigData'] = fileData
        except:
            LOGEXCEPT('Loading plugin %s failed.  Skipping' % fullfn)

    return moduleMap
Esempio n. 2
0
    def __backgroundRequestTopBlock(self):
        self.createProxy()
        self.isMidQuery = True
        try:
            numblks = self.proxy.getinfo()['blocks']
            blkhash = self.proxy.getblockhash(numblks)
            toptime = self.proxy.getblock(blkhash)['time']
            #LOGDEBUG('RPC Call: numBlks=%d, toptime=%d', numblks, toptime)
            # Only overwrite once all outputs are retrieved
            self.lastTopBlockInfo['numblks'] = numblks
            self.lastTopBlockInfo['tophash'] = blkhash
            self.lastTopBlockInfo['toptime'] = toptime
            self.lastTopBlockInfo['error'] = None  # Holds error info

            if len(self.last20queries)==0 or \
                  (RightNow()-self.last20queries[-1][0]) > 0.99:
                # This conditional guarantees last 20 queries spans at least 20s
                self.last20queries.append([RightNow(), numblks])
                self.last20queries = self.last20queries[-20:]
                t0, b0 = self.last20queries[0]
                t1, b1 = self.last20queries[-1]

                # Need at least 10s of data to give meaning answer
                if (t1 - t0) < 10:
                    self.lastTopBlockInfo['blkspersec'] = -1
                else:
                    self.lastTopBlockInfo['blkspersec'] = float(
                        b1 - b0) / float(t1 - t0)

        except ValueError:
            # I believe this happens when you used the wrong password
            LOGEXCEPT('ValueError in bkgd req top blk')
            self.lastTopBlockInfo['error'] = 'ValueError'
        except authproxy.JSONRPCException:
            # This seems to happen when groestlcoind is overwhelmed... not quite ready
            LOGDEBUG('generic jsonrpc exception')
            self.lastTopBlockInfo['error'] = 'JsonRpcException'
        except socket.error:
            # Connection isn't available... is groestlcoind not running anymore?
            LOGDEBUG('generic socket error')
            self.lastTopBlockInfo['error'] = 'SocketError'
        except:
            LOGEXCEPT('generic error')
            self.lastTopBlockInfo['error'] = 'UnknownError'
            raise
        finally:
            self.isMidQuery = False
Esempio n. 3
0
    def launchBitcoindAndGuardian(self):

        pargs = [self.executable]

        if USE_TESTNET:
            pargs.append('-testnet')
        elif USE_REGTEST:
            pargs.append('-regtest')

        pargs.append('-datadir=%s' % self.satoshiHome)

        try:
            # Don't want some strange error in this size-check to abort loading
            blocksdir = os.path.join(self.satoshiHome, 'blocks')
            sz = long(0)
            if os.path.exists(blocksdir):
                for fn in os.listdir(blocksdir):
                    fnpath = os.path.join(blocksdir, fn)
                    sz += long(os.path.getsize(fnpath))

            if sz < 5 * GIGABYTE:
                if SystemSpecs.Memory > 9.0:
                    pargs.append('-dbcache=2000')
                elif SystemSpecs.Memory > 5.0:
                    pargs.append('-dbcache=1000')
                elif SystemSpecs.Memory > 3.0:
                    pargs.append('-dbcache=500')
        except:
            LOGEXCEPT('Failed size check of blocks directory')

        kargs = {}
        if OS_WINDOWS:
            import win32process
            kargs['shell'] = True
            kargs['creationflags'] = win32process.CREATE_NO_WINDOW

        # Startup bitcoind and get its process ID (along with our own)
        argStr = " ".join(astr for astr in pargs)
        LOGWARN('Spawning bitcoind with command: ' + argStr)
        self.bitcoind = launchProcess(pargs, **kargs)

        self.btcdpid = self.bitcoind.pid
        self.selfpid = os.getpid()

        LOGINFO('PID of bitcoind: %d', self.btcdpid)
        LOGINFO('PID of armory:   %d', self.selfpid)

        # Startup guardian process -- it will watch Armory's PID
        gpath = self.getGuardianPath()
        pargs = [gpath, str(self.selfpid), str(self.btcdpid)]
        if not OS_WINDOWS:
            pargs.insert(0, 'python')
        launchProcess(pargs, **kargs)
Esempio n. 4
0
   def launchBitcoindAndGuardian(self):

      pargs = [self.executable]

      if USE_TESTNET:
         testhome = self.satoshiHome[:]
         if self.satoshiHome.endswith('/testnet3/'):
            pargs.append('-datadir=%s' % self.satoshiHome[:-10])
         elif self.satoshiHome.endswith('/testnet3'):
            pargs.append('-datadir=%s' % self.satoshiHome[:-9])
         pargs.append('-testnet')
      else:
         pargs.append('-datadir=%s' % self.satoshiHome)
      try:
         # Don't want some strange error in this size-check to abort loading
         blocksdir = os.path.join(self.satoshiHome, 'blocks')
         sz = long(0)
         if os.path.exists(blocksdir):
            for fn in os.listdir(blocksdir):
               fnpath = os.path.join(blocksdir, fn)
               sz += long(os.path.getsize(fnpath))

         if sz < 5*GIGABYTE:
            if SystemSpecs.Memory>9.0:
               pargs.append('-dbcache=2000')
            elif SystemSpecs.Memory>5.0:
               pargs.append('-dbcache=1000')
            elif SystemSpecs.Memory>3.0:
               pargs.append('-dbcache=500')
      except:
         LOGEXCEPT('Failed size check of blocks directory')


      # Startup bitcoind and get its process ID (along with our own)
      self.bitcoind = launchProcess(pargs)

      self.btcdpid  = self.bitcoind.pid
      self.selfpid  = os.getpid()

      LOGINFO('PID of bitcoind: %d',  self.btcdpid)
      LOGINFO('PID of armory:   %d',  self.selfpid)

      # Startup guardian process -- it will watch Armory's PID
      gpath = self.getGuardianPath()
      pargs = [gpath, str(self.selfpid), str(self.btcdpid)]
      if not OS_WINDOWS:
         pargs.insert(0, 'python')
      launchProcess(pargs)
Esempio n. 5
0
 def updateDustLimit():
     try:
         self.dustTableModel.updateDustList(
             self.getSelectedWlt(), str2coin(self.dustLimitText.text()))
         self.beGoneDustButton.setEnabled(
             len(self.dustTableModel.dustTxOutlist) > 0)
         if self.dustTableModel.wlt:
             self.lblHeader.setText(
                 tr("""<b>Dust Outputs for Wallet: %s</b>""" %
                    self.dustTableModel.wlt.labelName))
     except NegativeValueError:
         pass
     except TooMuchPrecisionError:
         pass
     except:
         LOGEXCEPT("Unexpected exception")
         pass
Esempio n. 6
0
    def findBitcoind(self, extraSearchPaths=[]):
        self.foundExe = []

        searchPaths = list(extraSearchPaths)  # create a copy

        if OS_WINDOWS:
            # Making sure the search path argument comes with /daemon and /Bitcoin on Windows

            searchPaths.extend(
                [os.path.join(sp, 'Groestlcoin') for sp in searchPaths])
            searchPaths.extend(
                [os.path.join(sp, 'daemon') for sp in searchPaths])

            possBaseDir = []

            from platform import machine
            if '64' in machine():
                possBaseDir.append(os.getenv("ProgramW6432"))
                possBaseDir.append(os.getenv('PROGRAMFILES(X86)'))
            else:
                possBaseDir.append(os.getenv('PROGRAMFILES'))

            # check desktop for links

            home = os.path.expanduser('~')
            desktop = os.path.join(home, 'Desktop')

            if os.path.exists(desktop):
                dtopfiles = os.listdir(desktop)
                for path in [os.path.join(desktop, fn) for fn in dtopfiles]:
                    if 'groestlcoin' in path.lower() and path.lower().endswith(
                            '.lnk'):
                        import win32com.client
                        shell = win32com.client.Dispatch('WScript.Shell')
                        targ = shell.CreateShortCut(path).Targetpath
                        targDir = os.path.dirname(targ)
                        LOGINFO('Found Groestlcoin-Qt link on desktop: %s',
                                targDir)
                        possBaseDir.append(targDir)

            # Also look in default place in ProgramFiles dirs

            # Now look at a few subdirs of the
            searchPaths.extend(possBaseDir)
            searchPaths.extend([
                os.path.join(p, 'Groestlcoin', 'daemon') for p in possBaseDir
            ])
            searchPaths.extend(
                [os.path.join(p, 'daemon') for p in possBaseDir])
            searchPaths.extend(
                [os.path.join(p, 'Groestlcoin') for p in possBaseDir])

            for p in searchPaths:
                testPath = os.path.join(p, 'groestlcoind.exe')
                if os.path.exists(testPath):
                    self.foundExe.append(testPath)

        else:
            # In case this was a downloaded copy, make sure we traverse to bin/64 dir
            searchPaths.extend(
                [os.path.join(p, 'bin') for p in extraSearchPaths])
            if SystemSpecs.IsX64:
                searchPaths.extend(
                    [os.path.join(p, 'bin/64') for p in extraSearchPaths])
            else:
                searchPaths.extend(
                    [os.path.join(p, 'bin/32') for p in extraSearchPaths])

            searchPaths.extend(['/usr/lib/groestlcoin/'])
            searchPaths.extend(os.getenv("PATH").split(':'))

            for p in searchPaths:
                testPath = os.path.join(p, 'groestlcoind')
                if os.path.exists(testPath):
                    self.foundExe.append(testPath)

            try:
                locs = subprocess_check_output(['whereis',
                                                'groestlcoind']).split()
                if len(locs) > 1:
                    locs = filter(
                        lambda x: os.path.basename(x) == 'groestlcoind', locs)
                    LOGINFO('"whereis" returned: %s', str(locs))
                    self.foundExe.extend(locs)
            except:
                LOGEXCEPT('Error executing "whereis" command')

        # For logging purposes, check that the first answer matches one of the
        # extra search paths.  There should be some kind of notification that
        # their supplied search path was invalid and we are using something else.
        if len(self.foundExe) > 0 and len(extraSearchPaths) > 0:
            foundIt = False
            for p in extraSearchPaths:
                if self.foundExe[0].startswith(p):
                    foundIt = True

            if not foundIt:
                LOGERROR(
                    'Groestlcoind could not be found in the specified installation:'
                )
                for p in extraSearchPaths:
                    LOGERROR('   %s', p)
                LOGERROR('Groestlcoind is being started from:')
                LOGERROR('   %s', self.foundExe[0])

        return self.foundExe
Esempio n. 7
0
 def injectShutdownFunc(self):
     try:
         self.main.writeSetting('DustLedgerCols',
                                saveTableView(self.dustTableView))
     except:
         LOGEXCEPT('Strange error during shutdown')