コード例 #1
0
def test_discover(prepareLogger):
    cryptoKey = rando.newKey()
    db = database.KeyValueDatabase(":memory:").child("tmp")
    acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, "dcr",
                                               nets.mainnet, db)
    txs = {}

    class Blockchain:
        params = nets.mainnet
        addrsHaveTxs = lambda addrs: any(a in txs for a in addrs)

    ogChain = chains.chain("dcr")
    chains.registerChain("dcr", Blockchain)
    ogLimit = accounts.ACCOUNT_GAP_LIMIT
    accounts.ACCOUNT_GAP_LIMIT = 2

    acctMgr.discover(cryptoKey)
    assert len(acctMgr.accounts) == 1

    coinExtKey = acctMgr.coinKey(cryptoKey)
    acct2ExtKey = coinExtKey.deriveAccountKey(2).neuter().child(0)
    acct2Addr5 = addrlib.deriveChildAddress(acct2ExtKey, 5, nets.mainnet)
    txs[acct2Addr5] = ["tx"]
    acctMgr.discover(cryptoKey)
    assert len(acctMgr.accounts) == 3

    chains.registerChain("dcr", ogChain)
    accounts.ACCOUNT_GAP_LIMIT = ogLimit
コード例 #2
0
def test_discover(monkeypatch, prepareLogger):
    cryptoKey = rando.newKey()
    db = database.KeyValueDatabase(":memory:").child("tmp")
    acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, "dcr",
                                               nets.mainnet, db)
    txs = {}

    class Blockchain:
        params = nets.mainnet
        addrsHaveTxs = lambda addrs: any(a in txs for a in addrs)

    # Set up globals for test.
    origChain = chains.chain("dcr")
    chains.registerChain("dcr", Blockchain)
    # Set up globals for test.
    monkeypatch.setattr(accounts, "ACCOUNT_GAP_LIMIT", 2)
    monkeypatch.setattr(account, "DefaultGapLimit", 4)

    acctMgr.discover(cryptoKey)
    assert len(acctMgr.accounts) == 1

    coinExtKey = acctMgr.coinKey(cryptoKey)
    acct2ExtKey = coinExtKey.deriveAccountKey(2).neuter().child(0)
    acct2Addr3 = addrlib.deriveChildAddress(acct2ExtKey, 3, nets.mainnet)
    txs[acct2Addr3] = ["tx"]
    acctMgr.discover(cryptoKey)
    assert len(acctMgr.accounts) == 3

    # Restore globals.
    chains.registerChain("dcr", origChain)
コード例 #3
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()
コード例 #4
0
ファイル: conftest.py プロジェクト: yoandresaav/tinydecred
def registerChain(request):
    chains.registerChain("dcr", None)
コード例 #5
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()