Skip to content

Commit

Permalink
feat(genesis): allows external genesis file
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajpiar committed Mar 5, 2024
1 parent b46e6b2 commit 0c7582c
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -81,7 +86,7 @@ public GenesisLoaderImpl(
activationConfig,
stateRootHandler,
trieStore,
GenesisLoaderImpl.class.getResourceAsStream("/genesis/" + genesisFile),
loadGenesisFile(genesisFile),
initialNonce,
isRsk,
useRskip92Encoding,
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 0c7582c

Please sign in to comment.