/** * Download the blockchain from peers. Convenience that uses a {@link DownloadProgressTracker} for you.<p> * * This method waits until the download is complete. "Complete" is defined as downloading * from at least one peer all the blocks that are in that peer's inventory. */ public void downloadBlockChain() { DownloadProgressTracker listener = new DownloadProgressTracker(); startBlockChainDownload(listener); try { listener.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if (caughtUp) return; if (blocksLeft == 0) { caughtUp = true; doneDownload(); future.set(peer.getBestHeight()); } if (blocksLeft < 0 || originalBlocksLeft <= 0) return; double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int) pct != lastPercent) { progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000)); lastPercent = (int) pct; } }
@Override public void onChainDownloadStarted(Peer peer, int blocksLeft) { if (blocksLeft > 0 && originalBlocksLeft == -1) startDownload(blocksLeft); // Only mark this the first time, because this method can be called more than once during a chain download // if we switch peers during it. if (originalBlocksLeft == -1) originalBlocksLeft = blocksLeft; else log.info("Chain download switched to {}", peer); if (blocksLeft == 0) { doneDownload(); future.set(peer.getBestHeight()); } }
@Override public void onSuccess(@Nullable Object result) { completeExtensionInitiations(vPeerGroup); final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener; vPeerGroup.startBlockChainDownload(l); }
@Override protected void doneDownload() { super.doneDownload(); view.displayDownloadContent(false); refresh(); } });
@Override protected void progress(double pct, int blocksSoFar, Date date) { super.progress(pct, blocksSoFar, date); int percentage = (int) pct; view.displayPercentage(percentage); view.displayProgress(percentage); }
peers.startBlockChainDownload(bListener); bListener.await();
@Override public void onSuccess(@Nullable Object result) { completeExtensionInitiations(vPeerGroup); final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener; vPeerGroup.startBlockChainDownload(l); }
/** * Download the blockchain from peers. Convenience that uses a {@link DownloadProgressTracker} for you.<p> * * This method waits until the download is complete. "Complete" is defined as downloading * from at least one peer all the blocks that are in that peer's inventory. */ public void downloadBlockChain() { DownloadProgressTracker listener = new DownloadProgressTracker(); startBlockChainDownload(listener); try { listener.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if (caughtUp) return; if (blocksLeft == 0) { caughtUp = true; doneDownload(); future.set(peer.getBestHeight()); } if (blocksLeft < 0 || originalBlocksLeft <= 0) return; double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int) pct != lastPercent) { progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000)); lastPercent = (int) pct; } }
@Override public void onChainDownloadStarted(Peer peer, int blocksLeft) { if (blocksLeft > 0 && originalBlocksLeft == -1) startDownload(blocksLeft); // Only mark this the first time, because this method can be called more than once during a chain download // if we switch peers during it. if (originalBlocksLeft == -1) originalBlocksLeft = blocksLeft; else log.info("Chain download switched to {}", peer); if (blocksLeft == 0) { doneDownload(); future.set(peer.getBestHeight()); } }
@Override public void onSuccess(@Nullable Object result) { completeExtensionInitiations(vPeerGroup); final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener; vPeerGroup.startBlockChainDownload(l); }
/** * Download the blockchain from peers. Convenience that uses a {@link DownloadProgressTracker} for you.<p> * * This method waits until the download is complete. "Complete" is defined as downloading * from at least one peer all the blocks that are in that peer's inventory. */ public void downloadBlockChain() { DownloadProgressTracker listener = new DownloadProgressTracker(); startBlockChainDownload(listener); try { listener.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if (caughtUp) return; if (blocksLeft == 0) { caughtUp = true; doneDownload(); future.set(peer.getBestHeight()); } if (blocksLeft < 0 || originalBlocksLeft <= 0) return; double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int) pct != lastPercent) { progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000)); lastPercent = (int) pct; } }
@Override public void onChainDownloadStarted(Peer peer, int blocksLeft) { if (blocksLeft > 0 && originalBlocksLeft == -1) startDownload(blocksLeft); // Only mark this the first time, because this method can be called more than once during a chain download // if we switch peers during it. if (originalBlocksLeft == -1) originalBlocksLeft = blocksLeft; else log.info("Chain download switched to {}", peer); if (blocksLeft == 0) { doneDownload(); future.set(peer.getBestHeight()); } }
@Override public void onSuccess(@Nullable Object result) { completeExtensionInitiations(vPeerGroup); final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener; vPeerGroup.startBlockChainDownload(l); }
/** * Download the blockchain from peers. Convenience that uses a {@link DownloadProgressTracker} for you.<p> * * This method waits until the download is complete. "Complete" is defined as downloading * from at least one peer all the blocks that are in that peer's inventory. */ public void downloadBlockChain() { DownloadProgressTracker listener = new DownloadProgressTracker(); startBlockChainDownload(listener); try { listener.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if (caughtUp) return; if (blocksLeft == 0) { caughtUp = true; if (lastPercent != 100) { lastPercent = 100; progress(lastPercent, blocksLeft, new Date(block.getTimeSeconds() * 1000)); } doneDownload(); future.set(peer.getBestHeight()); return; } if (blocksLeft < 0 || originalBlocksLeft <= 0) return; double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int) pct != lastPercent) { progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000)); lastPercent = (int) pct; } }
@Override public void onChainDownloadStarted(Peer peer, int blocksLeft) { if (blocksLeft > 0 && originalBlocksLeft == -1) startDownload(blocksLeft); // Only mark this the first time, because this method can be called more than once during a chain download // if we switch peers during it. if (originalBlocksLeft == -1) originalBlocksLeft = blocksLeft; else log.info("Chain download switched to {}", peer); if (blocksLeft == 0) { doneDownload(); future.set(peer.getBestHeight()); } }
private static void syncChain() { try { setup(); int startTransactions = wallet.getTransactions(true).size(); DownloadProgressTracker listener = new DownloadProgressTracker(); peers.start(); peers.startBlockChainDownload(listener); try { listener.await(); } catch (InterruptedException e) { System.err.println("Chain download interrupted, quitting ..."); System.exit(1); } int endTransactions = wallet.getTransactions(true).size(); if (endTransactions > startTransactions) { System.out.println("Synced " + (endTransactions - startTransactions) + " transactions."); } } catch (BlockStoreException e) { System.err.println("Error reading block chain file " + chainFileName + ": " + e.getMessage()); e.printStackTrace(); } }