def test_purge_block(mock_client):
    watch_only_wallet = WatchOnlyWallet()
    controller = MainController(watch_only_wallet)
    controller.blockchain_client = mock_client
    watch_only_wallet.load(*WalletFile.load())
    controller._sync_to_blockchain()
    watch_only_wallet.refresh_balances()
    # Tx_ins from the orphaned block should not show up in our balance
    assert watch_only_wallet.spendable_balance_satoshis == 0
    assert watch_only_wallet.incoming_balance_satoshis == 888
    # Current block should be the most recent valid block
    assert watch_only_wallet.current_block == valid_block_4
    # Addresses that received a tx_in in an orphaned block should count as fresh
    assert list(watch_only_wallet.external_addresses.values())[0].is_fresh
Пример #2
0
    def __init__(self, watch_only_wallet: WatchOnlyWallet):
        super().__init__()
        self.network = Config.get_network()
        bitcointx.select_chain_params(self.network)

        self.watch_only_wallet = watch_only_wallet
        self.blockchain_client = BlockchainClient(self.network)
        self.fee_estimation_client = FeeEstimationClient()
        self.tx_broadcast_client = TxBroadcastClient(self.network)
        self.serial_client = SerialClient(self.network)

        # Wallet is already set up
        if WalletFile.exists():
            self.watch_only_wallet.load(*WalletFile.load())
        # Wallet already got HD keys from the hardware wallet, but haven't
        # properly recovered balances on this side
        elif HardwareWalletFile.exists():
            self.recover_wallet(HardwareWalletFile.load_candidate_wallets(),
                                HardwareWalletFile.load_master_fingerprint())