Пример #1
0
def test_mkdir(tmp_path):
    fpath = tmp_path / "test_file"
    f = open(fpath, "w")
    f.close()
    assert not helpers.mkdir(fpath)
    dpath = tmp_path / "test_dir"
    assert helpers.mkdir(dpath)
    assert os.path.isdir(dpath)
    assert helpers.mkdir(dpath)
Пример #2
0
    def assetDirectory(self, coinID):
        """
        Get a directory for asset-specific storage. The directory is a
        subdirectory of the network directory.

        Args:
            coinID (int or str): The BIP-0044 asset ID or a ticker symbol.
        """
        symbol = chains.IDSymbols[chains.parseCoinType(coinID)]
        dirPath = Path(self.netDirectory) / symbol
        helpers.mkdir(dirPath)
        return dirPath
Пример #3
0
 def initLogging(self):
     """
     Initialize logging for the entire app.
     """
     logDir = os.path.join(config.DATA_DIR, "logs")
     helpers.mkdir(logDir)
     logFilePath = os.path.join(logDir, "tinydecred.log")
     helpers.prepareLogging(
         logFilePath, logLvl=self.cfg.logLevel, lvlMap=self.cfg.moduleLevels
     )
     log = helpers.getLogger("APP")
     log.info("configuration file at %s" % config.CONFIG_PATH)
     log.info("data directory at %s" % config.DATA_DIR)
     return log
Пример #4
0
    def __init__(self,
                 walletDir,
                 pw,
                 network,
                 signals=None,
                 allowCreate=False):
        """
        Args:
            dir (str): A directory for wallet database files.
            pw (str): The user password.
            network (str): The network name.
            signals (Signals): A signal processor.
        """
        signals = signals if signals else DefaultSignals
        netParams = nets.parse(network)
        netDir, dbPath, dcrPath = paths(walletDir, netParams.Name)
        if not Path(netDir).exists():
            mkdir(netDir)
        dcrdataDB = database.KeyValueDatabase(dcrPath)
        # The initialized DcrdataBlockchain will not be connected, as that is a
        # blocking operation. It will be called when the wallet is open.
        dcrdataURL = DCRDATA_PATHS[netParams.Name]
        self.dcrdata = DcrdataBlockchain(dcrdataDB, netParams, dcrdataURL)
        chains.registerChain("dcr", self.dcrdata)
        walletExists = Path(dbPath).is_file()
        if not walletExists and not allowCreate:
            raise DecredError("Wallet does not exist at %s", dbPath)

        super().__init__(dbPath)
        # words is only set the first time a wallet is created.
        if not walletExists:
            seed = rando.newKeyRaw()
            self.initialize(seed, pw.encode(), netParams)
            self.words = mnemonic.encode(seed)

        cryptoKey = self.cryptoKey(pw)
        acctMgr = self.accountManager(chains.BipIDs.decred, signals)
        self.account = acctMgr.openAccount(0, cryptoKey)
        self.account.sync()
Пример #5
0
import argparse
import logging
import os
import sys

from appdirs import AppDirs

from decred.dcr import nets
from decred.util import helpers

# Set the data directory in a OS-appropriate location.
_ad = AppDirs("TinyWallet", False)
DATA_DIR = _ad.user_data_dir

helpers.mkdir(DATA_DIR)

# The master configuration file name.
CONFIG_NAME = "tinywallet.conf"
CONFIG_PATH = os.path.join(DATA_DIR, CONFIG_NAME)

# Some decred constants.
MAINNET = nets.mainnet.Name
TESTNET = nets.testnet.Name
SIMNET = nets.simnet.Name

logLevelMap = {
    "critical": logging.CRITICAL,
    "error": logging.ERROR,
    "warning": logging.WARNING,
    "debug": logging.DEBUG,
Пример #6
0
    def __init__(self, qApp):
        """
        Args:
            qApp (QApplication): An initialized QApplication.
        """
        super().__init__()
        self.qApp = qApp
        self.cfg = config.load()
        self.log = self.initLogging()
        self.wallet = None
        # trackedCssItems are CSS-styled elements to be updated if dark mode is
        # enabled/disabled.
        self.trackedCssItems = []
        st = self.sysTray = QtWidgets.QSystemTrayIcon(QtGui.QIcon(DCR.FAVICON))
        self.contextMenu = ctxMenu = QtWidgets.QMenu()
        ctxMenu.addAction("minimize").triggered.connect(self.minimizeApp)
        ctxMenu.addAction("quit").triggered.connect(self.shutdown)
        st.setContextMenu(ctxMenu)
        st.activated.connect(self.sysTrayActivated)

        # The signalRegistry maps a signal to any number of receivers. Signals
        # are routed through a Qt Signal.
        self.signalRegistry = {}
        self.qRawSignal.connect(self.signal_)
        self.blockchainSignals = TinySignals(
            balance=self.balanceSync,
            working=lambda: self.emitSignal(ui.WORKING_SIGNAL),
            done=lambda: self.emitSignal(ui.DONE_SIGNAL),
            spentTickets=lambda: self.emitSignal(ui.SPENT_TICKETS_SIGNAL),
        )

        self.netDirectory = os.path.join(config.DATA_DIR, self.cfg.netParams.Name)

        helpers.mkdir(self.netDirectory)
        self.appDB = database.KeyValueDatabase(
            os.path.join(self.netDirectory, "app.db")
        )
        self.settings = self.appDB.child("settings")
        self.loadSettings()

        dcrdataDB = database.KeyValueDatabase(self.assetDirectory("dcr") / "dcrdata.db")
        # The initialized DcrdataBlockchain will not be connected, as that is a
        # blocking operation. It will be called when the wallet is open.
        self.dcrdata = DcrdataBlockchain(
            dcrdataDB,
            self.cfg.netParams,
            self.settings[DB.dcrdata].decode(),
            skipConnect=True,
        )
        chains.registerChain("dcr", self.dcrdata)

        # appWindow is the main application window. The TinyDialog class has
        # methods for organizing a stack of Screen widgets.
        self.appWindow = screens.TinyDialog(self)

        self.homeSig.connect(self.home_)

        def gohome(screen=None):
            self.homeSig.emit(screen)

        self.home = gohome
        self.homeScreen = None

        self.pwDialog = screens.PasswordDialog()

        self.waitingScreen = screens.WaitingScreen()
        # Set waiting screen as initial home screen.
        self.appWindow.stack(self.waitingScreen)

        self.confirmScreen = screens.ConfirmScreen()

        self.walletSig.connect(self.setWallet_)

        def setwallet(wallet):
            self.walletSig.emit(wallet)

        self.setWallet = setwallet

        self.sysTray.show()
        self.appWindow.show()

        self.initialize()