Move 'rpcHost' option handling to Config

This commit is contained in:
Chris Beams 2019-12-17 15:26:58 +01:00
parent b4d4ca4fbe
commit 182f472394
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
6 changed files with 17 additions and 11 deletions

View file

@ -66,6 +66,7 @@ public class Config {
public static final String NUM_CONNECTIONS_FOR_BTC = "numConnectionsForBtc";
public static final String RPC_USER = "rpcUser";
public static final String RPC_PASSWORD = "rpcPassword";
public static final String RPC_HOST = "rpcHost";
private static final Logger log = LoggerFactory.getLogger(Config.class);
@ -129,6 +130,7 @@ public class Config {
private final int numConnectionsForBtc;
private final String rpcUser;
private final String rpcPassword;
private final String rpcHost;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -453,6 +455,11 @@ public class Config {
.withRequiredArg()
.defaultsTo("");
ArgumentAcceptingOptionSpec<String> rpcHostOpt =
parser.accepts(RPC_HOST, "Bitcoind rpc host")
.withRequiredArg()
.defaultsTo("");
try {
OptionSet cliOpts = parser.parse(args);
@ -542,6 +549,7 @@ public class Config {
this.numConnectionsForBtc = options.valueOf(numConnectionsForBtcOpt);
this.rpcUser = options.valueOf(rpcUserOpt);
this.rpcPassword = options.valueOf(rpcPasswordOpt);
this.rpcHost = options.valueOf(rpcHostOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -813,4 +821,8 @@ public class Config {
public String getRpcPassword() {
return rpcPassword;
}
public String getRpcHost() {
return rpcHost;
}
}

View file

@ -57,7 +57,7 @@ public class BisqEnvironment extends StandardEnvironment {
protected boolean isBitcoinLocalhostNodeRunning;
protected final String
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
genesisTxId, genesisBlockHeight, genesisTotalSupply,
daoActivated;
@ -69,7 +69,6 @@ public class BisqEnvironment extends StandardEnvironment {
@SuppressWarnings("ConstantConditions")
public BisqEnvironment(PropertySource commandLineProperties) {
//DaoOptionKeys
rpcHost = getProperty(commandLineProperties, DaoOptionKeys.RPC_HOST, "");
rpcPort = getProperty(commandLineProperties, DaoOptionKeys.RPC_PORT, "");
rpcBlockNotificationPort = getProperty(commandLineProperties, DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, "");
rpcBlockNotificationHost = getProperty(commandLineProperties, DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, "");
@ -96,7 +95,6 @@ public class BisqEnvironment extends StandardEnvironment {
private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{
setProperty(DaoOptionKeys.RPC_HOST, rpcHost);
setProperty(DaoOptionKeys.RPC_PORT, rpcPort);
setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, rpcBlockNotificationPort);
setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, rpcBlockNotificationHost);

View file

@ -285,10 +285,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(boolean.class);
//RpcOptionKeys
parser.accepts(DaoOptionKeys.RPC_HOST,
"Bitcoind rpc host")
.withRequiredArg();
parser.accepts(DaoOptionKeys.RPC_PORT,
"Bitcoind rpc port")
.withRequiredArg();

View file

@ -225,7 +225,7 @@ public class DaoModule extends AppModule {
// Options
bindConstant().annotatedWith(named(Config.RPC_USER)).to(config.getRpcUser());
bindConstant().annotatedWith(named(Config.RPC_PASSWORD)).to(config.getRpcPassword());
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_HOST)).to(environment.getRequiredProperty(DaoOptionKeys.RPC_HOST));
bindConstant().annotatedWith(named(Config.RPC_HOST)).to(config.getRpcHost());
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_PORT)).to(environment.getRequiredProperty(DaoOptionKeys.RPC_PORT));
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT))
.to(environment.getRequiredProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT));

View file

@ -24,7 +24,6 @@ public class DaoOptionKeys {
public static final String RPC_PORT = "rpcPort";
public static final String RPC_BLOCK_NOTIFICATION_PORT = "rpcBlockNotificationPort";
public static final String RPC_BLOCK_NOTIFICATION_HOST = "rpcBlockNotificationHost";
public static final String RPC_HOST = "rpcHost";
public static final String DUMP_BLOCKCHAIN_DATA = "dumpBlockchainData";
public static final String FULL_DAO_NODE = "fullDaoNode";

View file

@ -24,6 +24,7 @@ import bisq.core.user.Preferences;
import bisq.common.UserThread;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import bisq.common.handlers.ResultHandler;
import bisq.common.util.Utilities;
@ -92,7 +93,7 @@ public class RpcService {
@SuppressWarnings("WeakerAccess")
@Inject
public RpcService(Preferences preferences,
@Named(DaoOptionKeys.RPC_HOST) String rpcHost,
@Named(Config.RPC_HOST) String rpcHost,
@Named(DaoOptionKeys.RPC_PORT) String rpcPort,
@Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockPort,
@Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) String rpcBlockHost) {
@ -100,7 +101,7 @@ public class RpcService {
this.rpcPassword = preferences.getRpcPw();
// mainnet is 8332, testnet 18332, regtest 18443
boolean isHostSet = rpcHost != null && !rpcHost.isEmpty();
boolean isHostSet = !rpcHost.isEmpty();
boolean isPortSet = rpcPort != null && !rpcPort.isEmpty();
boolean isMainnet = BaseCurrencyNetwork.CURRENT_NETWORK.isMainnet();
boolean isTestnet = BaseCurrencyNetwork.CURRENT_NETWORK.isTestnet();