diff --git a/core/src/main/java/bisq/core/btc/nodes/BtcNodeConverter.java b/core/src/main/java/bisq/core/btc/nodes/BtcNodeConverter.java
index 7740b17e35..ce94e16d34 100644
--- a/core/src/main/java/bisq/core/btc/nodes/BtcNodeConverter.java
+++ b/core/src/main/java/bisq/core/btc/nodes/BtcNodeConverter.java
@@ -55,8 +55,7 @@ class BtcNodeConverter {
PeerAddress convertOnionHost(BtcNode node) {
// no DNS lookup for onion addresses
String onionAddress = Objects.requireNonNull(node.getOnionAddress());
- PeerAddress result = new PeerAddress(onionAddress, node.getPort());
- return result;
+ return new PeerAddress(onionAddress, node.getPort());
}
@Nullable
@@ -69,7 +68,7 @@ class BtcNodeConverter {
if (address != null) {
result = create(address, port);
} else {
- log.warn("Lookup failed, no address for node", node);
+ log.warn("Lookup failed, no address for node {}", node);
}
}
return result;
@@ -85,7 +84,7 @@ class BtcNodeConverter {
if (address != null) {
result = create(proxy, address, port);
} else {
- log.warn("Lookup failed, no address for node", node);
+ log.warn("Lookup failed, no address for node {}", node);
}
}
return result;
diff --git a/core/src/main/java/bisq/core/btc/setup/BisqKeyChainFactory.java b/core/src/main/java/bisq/core/btc/setup/BisqKeyChainFactory.java
index 5c31e0d64c..7c576a3c84 100644
--- a/core/src/main/java/bisq/core/btc/setup/BisqKeyChainFactory.java
+++ b/core/src/main/java/bisq/core/btc/setup/BisqKeyChainFactory.java
@@ -26,7 +26,6 @@ import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.wallet.KeyChainGroupStructure;
import org.bitcoinj.wallet.Protos;
-import org.bitcoinj.wallet.UnreadableWalletException;
import com.google.common.collect.ImmutableList;
@@ -63,12 +62,12 @@ public class BisqKeyChainFactory extends DefaultKeyChainFactory {
}
@Override
- public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isFollowingKey, boolean isMarried, Script.ScriptType outputScriptType) throws UnreadableWalletException {
+ public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isFollowingKey, boolean isMarried, Script.ScriptType outputScriptType) {
throw new UnsupportedOperationException("Bisq is not supposed to use this");
}
@Override
- public DeterministicKeyChain makeSpendingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isMarried, Script.ScriptType outputScriptType) throws UnreadableWalletException {
+ public DeterministicKeyChain makeSpendingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isMarried, Script.ScriptType outputScriptType) {
throw new UnsupportedOperationException("Bisq is not supposed to use this");
}
}
diff --git a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java
index 13f18dd4f7..48d1d9e922 100644
--- a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java
+++ b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java
@@ -20,6 +20,7 @@ package bisq.core.btc.setup;
import bisq.core.btc.nodes.LocalBitcoinNode;
import bisq.core.btc.nodes.ProxySocketFactory;
import bisq.core.btc.wallet.BisqRiskAnalysis;
+
import bisq.common.config.Config;
import com.google.common.collect.*;
@@ -54,9 +55,7 @@ import static com.google.common.base.Preconditions.*;
/**
*
Utility class that wraps the boilerplate needed to set up a new SPV bitcoinj app. Instantiate it with a directory
* and file prefix, optionally configure a few things, then use startAsync and optionally awaitRunning. The object will
- * construct and configure a {@link BlockChain}, {@link SPVBlockStore}, {@link Wallet} and {@link PeerGroup}. Depending
- * on the value of the blockingStartup property, startup will be considered complete once the block chain has fully
- * synchronized, so it can take a while.
+ * construct and configure a {@link BlockChain}, {@link SPVBlockStore}, {@link Wallet} and {@link PeerGroup}.
*
*
To add listeners and modify the objects that are constructed, you can either do that by overriding the
* {@link #onSetupCompleted()} method (which will run on a background thread) and make your changes there,
@@ -92,16 +91,12 @@ public class WalletConfig extends AbstractIdleService {
protected volatile File vBtcWalletFile;
protected volatile File vBsqWalletFile;
- protected boolean useAutoSave = true;
protected PeerAddress[] peerAddresses;
protected DownloadProgressTracker downloadListener;
- protected boolean autoStop = true;
protected InputStream checkpoints;
- protected boolean blockingStartup = true;
protected String userAgent, version;
protected WalletProtobufSerializer.WalletFactory walletFactory;
@Nullable protected DeterministicSeed restoreFromSeed;
- @Nullable protected DeterministicKey restoreFromKey;
@Nullable protected PeerDiscovery discovery;
protected volatile Context context;
@@ -124,8 +119,7 @@ public class WalletConfig extends AbstractIdleService {
/**
* Creates a new WalletConfig, with the given {@link Context}. Files will be stored in the given directory.
*/
- public WalletConfig(Context context,
- File directory, String filePrefix) {
+ private WalletConfig(Context context, File directory, String filePrefix) {
this.context = context;
this.params = checkNotNull(context.getParams());
this.directory = checkDir(directory);
@@ -170,29 +164,15 @@ public class WalletConfig extends AbstractIdleService {
return setPeerNodes(new PeerAddress(params, localHost, params.getPort()));
}
- /** If true, the wallet will save itself to disk automatically whenever it changes. */
- public WalletConfig setAutoSave(boolean value) {
- checkState(state() == State.NEW, "Cannot call after startup");
- useAutoSave = value;
- return this;
- }
-
/**
* If you want to learn about the sync process, you can provide a listener here. For instance, a
- * {@link DownloadProgressTracker} is a good choice. This has no effect unless setBlockingStartup(false) has been called
- * too, due to some missing implementation code.
+ * {@link DownloadProgressTracker} is a good choice.
*/
public WalletConfig setDownloadListener(DownloadProgressTracker listener) {
this.downloadListener = listener;
return this;
}
- /** If true, will register a shutdown hook to stop the library. Defaults to true. */
- public WalletConfig setAutoStop(boolean autoStop) {
- this.autoStop = autoStop;
- return this;
- }
-
/**
* If set, the file is expected to contain a checkpoints file calculated with BuildCheckpoints. It makes initial
* block sync faster for new users - please refer to the documentation on the bitcoinj website
@@ -205,17 +185,6 @@ public class WalletConfig extends AbstractIdleService {
return this;
}
- /**
- * If true (the default) then the startup of this service won't be considered complete until the network has been
- * brought up, peer connections established and the block chain synchronised. Therefore {@link #awaitRunning()} can
- * potentially take a very long time. If false, then startup is considered complete once the network activity
- * begins and peer connections/block chain sync will continue in the background.
- */
- public WalletConfig setBlockingStartup(boolean blockingStartup) {
- this.blockingStartup = blockingStartup;
- return this;
- }
-
/**
* Sets the string that will appear in the subver field of the version message.
* @param userAgent A short string that should be the name of your app, e.g. "My Wallet"
@@ -227,14 +196,6 @@ public class WalletConfig extends AbstractIdleService {
return this;
}
- /**
- * Sets a wallet factory which will be used when the kit creates a new wallet.
- */
- public WalletConfig setWalletFactory(WalletProtobufSerializer.WalletFactory walletFactory) {
- this.walletFactory = walletFactory;
- return this;
- }
-
/**
* If a seed is set here then any existing wallet that matches the file name will be renamed to a backup name,
* the chain file will be deleted, and the wallet object will be instantiated with the given seed instead of
@@ -248,19 +209,6 @@ public class WalletConfig extends AbstractIdleService {
return this;
}
- /**
- * If an account key is set here then any existing wallet that matches the file name will be renamed to a backup name,
- * the chain file will be deleted, and the wallet object will be instantiated with the given key instead of
- * a fresh seed being created. This is intended for restoring a wallet from an account key. To implement restore
- * you would shut down the existing appkit, if any, then recreate it with the key given by the user, then start
- * up the new kit. The next time your app starts it should work as normal (that is, don't keep calling this each
- * time).
- */
- public WalletConfig restoreWalletFromKey(DeterministicKey accountKey) {
- this.restoreFromKey = accountKey;
- return this;
- }
-
/**
* Sets the peer discovery class to use. If none is provided then DNS is used, which is a reasonable default.
*/
@@ -269,16 +217,6 @@ public class WalletConfig extends AbstractIdleService {
return this;
}
- /**
- *
Override this to return wallet extensions if any are necessary.
- *
- *
When this is called, chain(), store(), and peerGroup() will return the created objects, however they are not
- * initialized/started.
- */
- protected List provideWalletExtensions() throws Exception {
- return ImmutableList.of();
- }
-
/**
* This method is invoked on a background thread after all objects are initialised, but before the peer group
* or block chain download is started. You can tweak the objects configuration here.
@@ -287,49 +225,17 @@ public class WalletConfig extends AbstractIdleService {
// Meant to be overridden by subclasses
}
- /**
- * Tests to see if the spvchain file has an operating system file lock on it. Useful for checking if your app
- * is already running. If another copy of your app is running and you start the appkit anyway, an exception will
- * be thrown during the startup process. Returns false if the chain file does not exist or is a directory.
- */
- public boolean isChainFileLocked() throws IOException {
- RandomAccessFile file2 = null;
- try {
- File file = new File(directory, filePrefix + ".spvchain");
- if (!file.exists())
- return false;
- if (file.isDirectory())
- return false;
- file2 = new RandomAccessFile(file, "rw");
- FileLock lock = file2.getChannel().tryLock();
- if (lock == null)
- return true;
- lock.release();
- return false;
- } finally {
- if (file2 != null)
- file2.close();
- }
- }
-
@Override
protected void startUp() throws Exception {
// Runs in a separate thread.
Context.propagate(context);
- // bitcoinj's WalletAppKit creates the wallet directory if it was not created already,
- // but WalletConfig should not do that.
- // if (!directory.exists()) {
- // if (!directory.mkdirs()) {
- // throw new IOException("Could not create directory " + directory.getAbsolutePath());
- // }
- // }
log.info("Starting up with directory = {}", directory);
try {
File chainFile = new File(directory, filePrefix + ".spvchain");
boolean chainFileExists = chainFile.exists();
String btcPrefix = "_BTC";
vBtcWalletFile = new File(directory, filePrefix + btcPrefix + ".wallet");
- boolean shouldReplayWallet = (vBtcWalletFile.exists() && !chainFileExists) || restoreFromSeed != null || restoreFromKey != null;
+ boolean shouldReplayWallet = (vBtcWalletFile.exists() && !chainFileExists) || restoreFromSeed != null;
vBtcWallet = createOrLoadWallet(shouldReplayWallet, vBtcWalletFile, false);
vBtcWallet.allowSpendingUnconfirmedTransactions();
vBtcWallet.setRiskAnalyzer(new BisqRiskAnalysis.Analyzer());
@@ -341,8 +247,8 @@ public class WalletConfig extends AbstractIdleService {
// Initiate Bitcoin network objects (block store, blockchain and peer group)
vStore = new SPVBlockStore(params, chainFile);
- if (!chainFileExists || restoreFromSeed != null || restoreFromKey != null) {
- if (checkpoints == null && !Utils.isAndroidRuntime()) {
+ if (!chainFileExists || restoreFromSeed != null) {
+ if (checkpoints == null) {
checkpoints = CheckpointManager.openStream(params);
}
@@ -355,12 +261,6 @@ public class WalletConfig extends AbstractIdleService {
log.info("Clearing the chain file in preparation for restore.");
vStore.clear();
}
- } else if (restoreFromKey != null) {
- time = restoreFromKey.getCreationTimeSeconds();
- if (chainFileExists) {
- log.info("Clearing the chain file in preparation for restore.");
- vStore.clear();
- }
} else {
time = vBtcWallet.getEarliestKeyCreationTime();
}
@@ -398,32 +298,20 @@ public class WalletConfig extends AbstractIdleService {
vPeerGroup.addWallet(vBsqWallet);
onSetupCompleted();
- if (blockingStartup) {
- vPeerGroup.start();
- // Make sure we shut down cleanly.
- installShutdownHook();
- //completeExtensionInitiations(vPeerGroup);
+ Futures.addCallback((ListenableFuture>) vPeerGroup.startAsync(), new FutureCallback