WalletAppKit: make sure downloadListener is never null

This simplifies the `if (blockingStartup)` and its `else` block. This change makes way
for further simplification.
This commit is contained in:
Sean Gilligan 2022-07-27 13:30:11 -07:00 committed by Andreas Schildbach
parent 4bd79448ee
commit ff674ea605

View file

@ -100,7 +100,7 @@ public class WalletAppKit extends AbstractIdleService {
protected boolean useAutoSave = true; protected boolean useAutoSave = true;
protected PeerAddress[] peerAddresses; protected PeerAddress[] peerAddresses;
protected DownloadProgressTracker downloadListener; protected DownloadProgressTracker downloadListener = new DownloadProgressTracker();
protected boolean autoStop = true; protected boolean autoStop = true;
protected InputStream checkpoints; protected InputStream checkpoints;
protected boolean blockingStartup = true; protected boolean blockingStartup = true;
@ -179,6 +179,7 @@ public class WalletAppKit extends AbstractIdleService {
* too, due to some missing implementation code. * too, due to some missing implementation code.
*/ */
public WalletAppKit setDownloadListener(DownloadProgressTracker listener) { public WalletAppKit setDownloadListener(DownloadProgressTracker listener) {
checkNotNull(listener);
this.downloadListener = listener; this.downloadListener = listener;
return this; return this;
} }
@ -384,15 +385,12 @@ public class WalletAppKit extends AbstractIdleService {
// Make sure we shut down cleanly. // Make sure we shut down cleanly.
installShutdownHook(); installShutdownHook();
// TODO: Be able to use the provided download listener when doing a blocking startup. vPeerGroup.startBlockChainDownload(downloadListener);
final DownloadProgressTracker listener = new DownloadProgressTracker(); downloadListener.await();
vPeerGroup.startBlockChainDownload(listener);
listener.await();
} else { } else {
vPeerGroup.startAsync().whenComplete((result, t) -> { vPeerGroup.startAsync().whenComplete((result, t) -> {
if (t == null) { if (t == null) {
final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener; vPeerGroup.startBlockChainDownload(downloadListener);
vPeerGroup.startBlockChainDownload(l);
} else { } else {
throw new RuntimeException(t); throw new RuntimeException(t);
} }