diff --git a/rskj-core/src/main/java/org/ethereum/core/genesis/GenesisLoaderImpl.java b/rskj-core/src/main/java/org/ethereum/core/genesis/GenesisLoaderImpl.java index 75c53643711..0c2bc0354bc 100644 --- a/rskj-core/src/main/java/org/ethereum/core/genesis/GenesisLoaderImpl.java +++ b/rskj-core/src/main/java/org/ethereum/core/genesis/GenesisLoaderImpl.java @@ -41,9 +41,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -81,7 +86,7 @@ public GenesisLoaderImpl( activationConfig, stateRootHandler, trieStore, - GenesisLoaderImpl.class.getResourceAsStream("/genesis/" + genesisFile), + loadGenesisFile(genesisFile), initialNonce, isRsk, useRskip92Encoding, @@ -230,6 +235,25 @@ private void setupPrecompiledContractsStorage(Repository repository) { } } + public static InputStream loadGenesisFile(String fileName) { + InputStream inputStream = GenesisLoaderImpl.class.getResourceAsStream("/genesis/" + fileName); + + if (inputStream != null) { + return inputStream; + } + + Path filePath = Paths.get(fileName); + if (Files.exists(filePath)) { + try { + return new FileInputStream(filePath.toFile()); + } catch (FileNotFoundException e) { + logger.error(e.getLocalizedMessage()); + } + } + + return null; + } + public static void loadGenesisInitalState(Repository repository, Genesis genesis) { // first we need to create the accounts, which creates also the associated ContractDetails for (RskAddress accounts : genesis.getAccounts().keySet()) {