forked from Qortal/qortal
Move default blockchain.json into resources
This commit is contained in:
parent
a4f2cf50b0
commit
94fceeb34a
@ -1,9 +1,7 @@
|
|||||||
package org.qora.block;
|
package org.qora.block;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.MathContext;
|
import java.math.MathContext;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -122,7 +120,8 @@ public class BlockChain {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fileInstance(String filename) {
|
/** Use blockchain config read from <tt>path</tt> + <tt>filename</tt>, or use resources-based default if <tt>filename</tt> is <tt>null</tt>. */
|
||||||
|
public static void fileInstance(String path, String filename) {
|
||||||
JAXBContext jc;
|
JAXBContext jc;
|
||||||
Unmarshaller unmarshaller;
|
Unmarshaller unmarshaller;
|
||||||
|
|
||||||
@ -147,15 +146,30 @@ public class BlockChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlockChain blockchain = null;
|
BlockChain blockchain = null;
|
||||||
|
StreamSource jsonSource;
|
||||||
|
|
||||||
LOGGER.info("Using blockchain config file: " + filename);
|
if (filename != null) {
|
||||||
|
LOGGER.info("Using blockchain config file: " + path + filename);
|
||||||
|
|
||||||
// Create the StreamSource by creating Reader to the JSON input
|
File jsonFile = new File(path + filename);
|
||||||
try (Reader settingsReader = new FileReader(filename)) {
|
|
||||||
StreamSource json = new StreamSource(settingsReader);
|
|
||||||
|
|
||||||
|
if (!jsonFile.exists()) {
|
||||||
|
LOGGER.error("Blockchain config file not found: " + path + filename);
|
||||||
|
throw new RuntimeException("Blockchain config file not found: " + path + filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonSource = new StreamSource(jsonFile);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Using default, resources-based blockchain config");
|
||||||
|
|
||||||
|
ClassLoader classLoader = BlockChain.class.getClassLoader();
|
||||||
|
InputStream in = classLoader.getResourceAsStream("blockchain.json");
|
||||||
|
jsonSource = new StreamSource(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Attempt to unmarshal JSON stream to BlockChain config
|
// Attempt to unmarshal JSON stream to BlockChain config
|
||||||
blockchain = unmarshaller.unmarshal(json, BlockChain.class).getValue();
|
blockchain = unmarshaller.unmarshal(jsonSource, BlockChain.class).getValue();
|
||||||
} catch (UnmarshalException e) {
|
} catch (UnmarshalException e) {
|
||||||
Throwable linkedException = e.getLinkedException();
|
Throwable linkedException = e.getLinkedException();
|
||||||
if (linkedException instanceof XMLMarshalException) {
|
if (linkedException instanceof XMLMarshalException) {
|
||||||
@ -166,15 +180,9 @@ public class BlockChain {
|
|||||||
|
|
||||||
LOGGER.error("Unable to process blockchain config file", e);
|
LOGGER.error("Unable to process blockchain config file", e);
|
||||||
throw new RuntimeException("Unable to process blockchain config file", e);
|
throw new RuntimeException("Unable to process blockchain config file", e);
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
LOGGER.error("Blockchain config file not found: " + filename);
|
|
||||||
throw new RuntimeException("Blockchain config file not found: " + filename);
|
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
LOGGER.error("Unable to process blockchain config file", e);
|
LOGGER.error("Unable to process blockchain config file", e);
|
||||||
throw new RuntimeException("Unable to process blockchain config file", e);
|
throw new RuntimeException("Unable to process blockchain config file", e);
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.error("Unable to process blockchain config file", e);
|
|
||||||
throw new RuntimeException("Unable to process blockchain config file", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate config
|
// Validate config
|
||||||
|
@ -72,7 +72,7 @@ public class Settings {
|
|||||||
private int maxPeers = 30;
|
private int maxPeers = 30;
|
||||||
|
|
||||||
// Which blockchains this node is running
|
// Which blockchains this node is running
|
||||||
private String blockchainConfig = "blockchain.json";
|
private String blockchainConfig = null; // use default from resources
|
||||||
private boolean useBitcoinTestNet = false;
|
private boolean useBitcoinTestNet = false;
|
||||||
|
|
||||||
// Repository related
|
// Repository related
|
||||||
@ -176,7 +176,7 @@ public class Settings {
|
|||||||
instance = settings;
|
instance = settings;
|
||||||
|
|
||||||
// Now read blockchain config
|
// Now read blockchain config
|
||||||
BlockChain.fileInstance(settings.getUserPath() + settings.getBlockchainConfig());
|
BlockChain.fileInstance(settings.getUserPath(), settings.getBlockchainConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate() {
|
private void validate() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user