Skip to content

Commit

Permalink
support --xmrBlockchainPath startup flag for local Monero node
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 16, 2025
1 parent 88b6bed commit b571b39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
20 changes: 15 additions & 5 deletions common/src/main/java/haveno/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class Config {
public static final String BYPASS_MEMPOOL_VALIDATION = "bypassMempoolValidation";
public static final String PASSWORD_REQUIRED = "passwordRequired";
public static final String UPDATE_XMR_BINARIES = "updateXmrBinaries";
public static final String XMR_BLOCKCHAIN_PATH = "xmrBlockchainPath";

// Default values for certain options
public static final int UNSPECIFIED_PORT = -1;
Expand Down Expand Up @@ -206,6 +207,7 @@ public enum UseTorForXmr {
public final boolean bypassMempoolValidation;
public final boolean passwordRequired;
public final boolean updateXmrBinaries;
public final String xmrBlockchainPath;

// Properties derived from options but not exposed as options themselves
public final File torDir;
Expand Down Expand Up @@ -630,6 +632,13 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
.ofType(boolean.class)
.defaultsTo(true);

ArgumentAcceptingOptionSpec<String> xmrBlockchainPathOpt =
parser.accepts(XMR_BLOCKCHAIN_PATH,
"Path to Monero blockchain when using local Monero node")
.withRequiredArg()
.ofType(String.class)
.defaultsTo("");

try {
CompositeOptionSet options = new CompositeOptionSet();

Expand Down Expand Up @@ -743,6 +752,7 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
this.bypassMempoolValidation = options.valueOf(bypassMempoolValidationOpt);
this.passwordRequired = options.valueOf(passwordRequiredOpt);
this.updateXmrBinaries = options.valueOf(updateXmrBinariesOpt);
this.xmrBlockchainPath = options.valueOf(xmrBlockchainPathOpt);
} catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0),
Expand All @@ -752,11 +762,11 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
}

// Create all appDataDir subdirectories and assign to their respective properties
File btcNetworkDir = mkdir(appDataDir, baseCurrencyNetwork.name().toLowerCase());
this.keyStorageDir = mkdir(btcNetworkDir, "keys");
this.storageDir = mkdir(btcNetworkDir, "db");
this.torDir = mkdir(btcNetworkDir, "tor");
this.walletDir = mkdir(btcNetworkDir, "wallet");
File xmrNetworkDir = mkdir(appDataDir, baseCurrencyNetwork.name().toLowerCase());
this.keyStorageDir = mkdir(xmrNetworkDir, "keys");
this.storageDir = mkdir(xmrNetworkDir, "db");
this.torDir = mkdir(xmrNetworkDir, "tor");
this.walletDir = mkdir(xmrNetworkDir, "wallet");

// Assign values to special-case static fields
APP_DATA_DIR_VALUE = appDataDir;
Expand Down
15 changes: 11 additions & 4 deletions core/src/main/java/haveno/core/api/XmrLocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,18 @@ public void start(XmrNodeSettings settings) throws IOException {

var args = new ArrayList<>(MONEROD_ARGS);

var dataDir = settings.getBlockchainPath();
if (dataDir == null || dataDir.isEmpty()) {
dataDir = MONEROD_DATADIR;
var dataDir = "";
if (config.xmrBlockchainPath == null || config.xmrBlockchainPath.isEmpty()) {
dataDir = settings.getBlockchainPath();
if (dataDir == null || dataDir.isEmpty()) {
dataDir = MONEROD_DATADIR;
}
} else {
dataDir = config.xmrBlockchainPath; // startup config overrides settings
}
if (dataDir != null && !dataDir.isEmpty()) {
args.add("--data-dir=" + dataDir);
}
if (dataDir != null) args.add("--data-dir=" + dataDir);

var bootstrapUrl = settings.getBootstrapUrl();
if (bootstrapUrl != null && !bootstrapUrl.isEmpty()) {
Expand Down

0 comments on commit b571b39

Please sign in to comment.