def derive_change_address(self) -> WalletAddress: new_address = WalletAddress( self.watch_only_wallet.xpub, self.watch_only_wallet.base_keypath, len(self.watch_only_wallet.change_addresses), True) self.watch_only_wallet.change_addresses[str(new_address)] = new_address WalletFile.save(self.watch_only_wallet) return new_address
def persist_spend(self, selection: CoinSelection): for utxo in map_coin_selection_to_utxos(selection, self.watch_only_wallet): utxo.is_awaiting_spend = True if selection.change_value > 0: self.watch_only_wallet.last_change_address.is_fresh = False self.watch_only_wallet.refresh_balances() WalletFile.save(self.watch_only_wallet)
def derive_external_address(self, label) -> WalletAddress: new_address = WalletAddress( self.watch_only_wallet.xpub, self.watch_only_wallet.base_keypath, len(self.watch_only_wallet.external_addresses), label=label) self.watch_only_wallet.external_addresses[str( new_address)] = new_address WalletFile.save(self.watch_only_wallet) return new_address
def _sync_to_blockchain(self): most_recent_block = self.blockchain_client.get_most_recent_block() if most_recent_block == self.watch_only_wallet.current_block: return while self.blockchain_client.block_is_orphan( self.watch_only_wallet.current_block): self.purge_orphaned_block(self.watch_only_wallet.current_block) for address in self.watch_only_wallet.addresses: self.update_address_utxos(address) self.watch_only_wallet.current_block = most_recent_block self.watch_only_wallet.refresh_balances() WalletFile.save(self.watch_only_wallet)
def purge_orphaned_block(self, orphan: Block): for address in self.watch_only_wallet.addresses: if address.utxos: address.utxos = [ utxo for utxo in address.utxos if utxo.block.hash != orphan.hash ] if not address.utxos: address.is_fresh = self.blockchain_client.address_is_fresh( address) self.watch_only_wallet.current_block = self.blockchain_client.get_block_by_hash( self.watch_only_wallet.current_block.prev_hash) self.watch_only_wallet.refresh_balances() WalletFile.save(self.watch_only_wallet)