Beispiel #1
0
    def findAvailablePort(self):
        for i in range(WalletMgr.__MaxPort):
            port=self.port+i
            if port > WalletMgr.__MaxPort:
                port-=WalletMgr.__MaxPort
            if Utils.arePortsAvailable(port):
                return port
            if Utils.Debug: Utils.Print("Port %d not available for %s" % (port, Utils.GstWalletPath))

        Utils.errorExit("Failed to find free port to use for %s" % (Utils.GstWalletPath))
Beispiel #2
0
    def create(self, name, accounts=None, exitOnError=True):
        wallet=self.wallets.get(name)
        if wallet is not None:
            if Utils.Debug: Utils.Print("Wallet \"%s\" already exists. Returning same." % name)
            return wallet
        p = re.compile(r'\n\"(\w+)\"\n', re.MULTILINE)
        cmdDesc="wallet create"
        cmd="%s %s %s --name %s --to-console" % (Utils.GstClientPath, self.getArgs(), cmdDesc, name)
        if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
        retStr=None
        maxRetryCount=4
        retryCount=0
        while True:
            try:
                retStr=Utils.checkOutput(cmd.split())
                break
            except subprocess.CalledProcessError as ex:
                retryCount+=1
                if retryCount<maxRetryCount:
                    delay=10
                    pgrepCmd=Utils.pgrepCmd(Utils.GstWalletName)
                    psOut=Utils.checkOutput(pgrepCmd.split())
                    portStatus="N/A"
                    if self.isLocal():
                        if Utils.arePortsAvailable(self.port):
                            portStatus="AVAILABLE"
                        else:
                            portStatus="NOT AVAILABLE"
                    if Utils.Debug: Utils.Print("%s was not accepted, delaying for %d seconds and trying again. port %d is %s. %s - {%s}" % (cmdDesc, delay, self.port, pgrepCmd, psOut))
                    time.sleep(delay)
                    continue

                msg=ex.output.decode("utf-8")
                errorMsg="ERROR: Failed to create wallet - %s. %s" % (name, msg)
                if exitOnError:
                    Utils.errorExit("%s" % (errorMsg))
                Utils.Print("%s" % (errorMsg))
                return None

        m=p.search(retStr)
        if m is None:
            if exitOnError:
                Utils.cmdError("could not create wallet %s" % (name))
                Utils.errorExit("Failed  to create wallet %s" % (name))

            Utils.Print("ERROR: wallet password parser failure")
            return None
        p=m.group(1)
        wallet=Wallet(name, p, self.host, self.port)
        self.wallets[name] = wallet

        if accounts:
            self.importKeys(accounts,wallet)

        return wallet
Beispiel #3
0
    def launch(self):
        if not self.walletd:
            Utils.Print(
                "ERROR: Wallet Manager wasn't configured to launch kpaybchaind"
            )
            return False

        if self.isLaunched():
            return True

        if self.isLocal():
            self.port = self.findAvailablePort()

        pgrepCmd = Utils.pgrepCmd(Utils.EosWalletName)
        if Utils.Debug:
            portTaken = False
            if self.isLocal():
                if not Utils.arePortsAvailable(self.port):
                    portTaken = True
            psOut = Utils.checkOutput(pgrepCmd.split(), ignoreError=True)
            if psOut or portTaken:
                statusMsg = ""
                if psOut:
                    statusMsg += " %s - {%s}." % (pgrepCmd, psOut)
                if portTaken:
                    statusMsg += " port %d is NOT available." % (self.port)
                Utils.Print(
                    "Launching %s, note similar processes running. %s" %
                    (Utils.EosWalletName, statusMsg))

        cmd = "%s --data-dir %s --config-dir %s --http-server-address=%s:%d --verbose-http-errors" % (
            Utils.EosWalletPath, WalletMgr.__walletDataDir,
            WalletMgr.__walletDataDir, self.host, self.port)
        if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
        with open(WalletMgr.__walletLogOutFile,
                  'w') as sout, open(WalletMgr.__walletLogErrFile,
                                     'w') as serr:
            popen = subprocess.Popen(cmd.split(), stdout=sout, stderr=serr)
            self.__walletPid = popen.pid

        # Give kpaybchaind time to warm up
        time.sleep(2)

        try:
            if Utils.Debug:
                Utils.Print("Checking if %s launched. %s" %
                            (Utils.EosWalletName, pgrepCmd))
            psOut = Utils.checkOutput(pgrepCmd.split())
            if Utils.Debug:
                Utils.Print("Launched %s. {%s}" % (Utils.EosWalletName, psOut))
        except subprocess.CalledProcessError as ex:
            Utils.errorExit("Failed to launch the wallet manager")

        return True