Move 'genesisBlockHeight' option handling to Config

This commit is contained in:
Chris Beams 2019-12-17 18:22:12 +01:00
parent 6ea146444f
commit ca5b260806
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
6 changed files with 18 additions and 12 deletions

View file

@ -73,6 +73,7 @@ public class Config {
public static final String DUMP_BLOCKCHAIN_DATA = "dumpBlockchainData";
public static final String FULL_DAO_NODE = "fullDaoNode";
public static final String GENESIS_TX_ID = "genesisTxId";
public static final String GENESIS_BLOCK_HEIGHT = "genesisBlockHeight";
private static final Logger log = LoggerFactory.getLogger(Config.class);
@ -144,6 +145,7 @@ public class Config {
private final boolean fullDaoNode;
private final boolean fullDaoNodeOptionSetExplicitly;
private final String genesisTxId;
private final int genesisBlockHeight;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -504,6 +506,13 @@ public class Config {
.withRequiredArg()
.defaultsTo("");
ArgumentAcceptingOptionSpec<Integer> genesisBlockHeightOpt =
parser.accepts(GENESIS_BLOCK_HEIGHT,
"Genesis transaction block height when not using the hard coded one")
.withRequiredArg()
.ofType(int.class)
.defaultsTo(-1);
try {
OptionSet cliOpts = parser.parse(args);
@ -600,6 +609,7 @@ public class Config {
this.fullDaoNode = options.valueOf(fullDaoNodeOpt);
this.fullDaoNodeOptionSetExplicitly = options.has(fullDaoNodeOpt);
this.genesisTxId = options.valueOf(genesisTxIdOpt);
this.genesisBlockHeight = options.valueOf(genesisBlockHeightOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -899,4 +909,8 @@ public class Config {
public String getGenesisTxId() {
return genesisTxId;
}
public int getGenesisBlockHeight() {
return genesisBlockHeight;
}
}

View file

@ -20,6 +20,7 @@ package bisq.core.app;
import bisq.core.dao.DaoOptionKeys;
import bisq.common.BisqException;
import bisq.common.config.Config;
import org.springframework.core.env.JOptCommandLinePropertySource;
import org.springframework.core.env.MutablePropertySources;
@ -57,7 +58,7 @@ public class BisqEnvironment extends StandardEnvironment {
protected boolean isBitcoinLocalhostNodeRunning;
protected final String
genesisBlockHeight, genesisTotalSupply,
genesisTotalSupply,
daoActivated;
public BisqEnvironment(OptionSet options) {
@ -68,7 +69,6 @@ public class BisqEnvironment extends StandardEnvironment {
@SuppressWarnings("ConstantConditions")
public BisqEnvironment(PropertySource commandLineProperties) {
//DaoOptionKeys
genesisBlockHeight = getProperty(commandLineProperties, DaoOptionKeys.GENESIS_BLOCK_HEIGHT, "-1");
genesisTotalSupply = getProperty(commandLineProperties, DaoOptionKeys.GENESIS_TOTAL_SUPPLY, "-1");
daoActivated = getProperty(commandLineProperties, DaoOptionKeys.DAO_ACTIVATED, "true");
@ -88,7 +88,6 @@ public class BisqEnvironment extends StandardEnvironment {
private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{
setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight);
setProperty(DaoOptionKeys.GENESIS_TOTAL_SUPPLY, genesisTotalSupply);
setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);
}

View file

@ -285,10 +285,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(boolean.class);
//RpcOptionKeys
parser.accepts(DaoOptionKeys.GENESIS_BLOCK_HEIGHT,
format("Genesis transaction block height when not using the hard coded one (default: %s)", "-1"))
.withRequiredArg();
parser.accepts(DaoOptionKeys.GENESIS_TOTAL_SUPPLY,
format("Genesis total supply when not using the hard coded one (default: %s)", "-1"))
.withRequiredArg();

View file

@ -199,9 +199,7 @@ public class DaoModule extends AppModule {
// Genesis
bindConstant().annotatedWith(named(Config.GENESIS_TX_ID)).to(config.getGenesisTxId());
Integer genesisBlockHeight = environment.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, Integer.class, -1);
bind(Integer.class).annotatedWith(Names.named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT)).toInstance(genesisBlockHeight);
bindConstant().annotatedWith(named(Config.GENESIS_BLOCK_HEIGHT)).to(config.getGenesisBlockHeight());
Long genesisTotalSupply = environment.getProperty(DaoOptionKeys.GENESIS_TOTAL_SUPPLY, Long.class, -1L);
bind(Long.class).annotatedWith(Names.named(DaoOptionKeys.GENESIS_TOTAL_SUPPLY)).toInstance(genesisTotalSupply);

View file

@ -22,7 +22,6 @@ package bisq.core.dao;
*/
public class DaoOptionKeys {
public static final String GENESIS_BLOCK_HEIGHT = "genesisBlockHeight";
public static final String GENESIS_TOTAL_SUPPLY = "genesisTotalSupply";
public static final String DAO_ACTIVATED = "daoActivated";
}

View file

@ -106,7 +106,7 @@ public class GenesisTxInfo {
@Inject
public GenesisTxInfo(@Named(Config.GENESIS_TX_ID) String genesisTxId,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) Integer genesisBlockHeight,
@Named(Config.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight,
@Named(DaoOptionKeys.GENESIS_TOTAL_SUPPLY) Long genesisTotalSupply) {
BaseCurrencyNetwork baseCurrencyNetwork = BaseCurrencyNetwork.CURRENT_NETWORK;
boolean isMainnet = baseCurrencyNetwork.isMainnet();