ElectrumMultiWallet extends SmartMultiWallet implements WalletExtension, StratumChain.Listener { @VisibleForTesting void subscribeToKeys() { final NetworkParameters params = wallet.getParams(); List<DeterministicKeyChain> chains = wallet.getKeychain().getDeterministicKeyChains(); Set<Address> addresses = Sets.newHashSet(); for (DeterministicKeyChain chain : chains) { chain.maybeLookAhead(); if (chain instanceof AddressableKeyChain) { for (ByteString bytes : ((AddressableKeyChain) chain).getP2SHHashes()) { addresses.add(Address.fromP2SHHash(params, bytes.toByteArray())); } } else { for (ECKey ecKey : chain.getLeafKeys()) { DeterministicKey key = (DeterministicKey) ecKey; addresses.add(key.toAddress(params)); } } } for (final Address address : addresses) { final String addressString = address.toString(); downloadFutures.put(addressString, SettableFuture.<Integer>create()); client.subscribe(address); } downloadFuture = Futures.allAsList(downloadFutures.values()); Futures.addCallback(downloadFuture, new FutureCallback<List<Integer>>() { @Override public void onSuccess(List<Integer> result) { isHistorySynced = true; notifyHeight(store.getHeight()); } @Override public void onFailure(Throwable t) { log.error("failed to sync history", t); } }); } ElectrumMultiWallet(SmartWallet wallet, File baseDirectory);  ElectrumMultiWallet(SmartWallet wallet); @Override void addEventListener(MultiWalletEventListener listener, Executor executor); void setCheckpoints(CheckpointManager checkpoints); void setInitialStore(URL url); @Override boolean removeEventListener(MultiWalletEventListener listener); @Override Set<Transaction> getTransactions(); @Override Transaction getTransaction(Sha256Hash hash); @Override Map<Sha256Hash, Transaction> getTransactionPool(WalletTransaction.Pool pool); @Override void markKeysAsUsed(Transaction tx); @Override void completeTx(Wallet.SendRequest req); @Override void commitTx(Transaction tx); @Override List<TransactionOutput> calculateAllSpendCandidates(boolean excludeImmatureCoinbases, boolean excludeUnsignable); @Override ListenableFuture<Transaction> broadcastTransaction(final Transaction tx); @Override void start(); @Override void startAsync(); @Override void stopAsync(); void stop(); @Override void resetBlockchain(); void safeAwaitClientTerminated(); @Override void awaitDownload(); @Override String getWalletExtensionID(); @Override boolean isWalletExtensionMandatory(); @Override byte[] serializeWalletExtension(); @Override void deserializeWalletExtension(Wallet containingWallet, byte[] data); @Override void onHeight(long height, Block block, boolean isSynced); int currentHeight(); @Override boolean isSynced(); @Override List<VersionMessage> getPeers(); @Override List<StoredBlock> getRecentBlocks(int maxBlocks); static final String EXTENSION_ID; static final int CHECKPOINT_TIME_BUFFER; }
@Test public void testSubscribeToKeys() throws Exception { SettableFuture<StratumMessage> future = SettableFuture.create(); StratumSubscription subscription = new StratumSubscription(future); expect(client.subscribe(isA(Address.class))) .andReturn(subscription).times(26); control.replay(); multiWallet.subscribeToKeys(); control.verify(); }