use of org.adridadou.ethereum.propeller.event.EthereumEventHandler in project eth-propeller-ethj by adridadou.
the class PrivateEthereumFacadeProvider method create.
public EthereumFacade create(PrivateNetworkConfig config, EthereumConfig ethereumConfig) {
final boolean dagCached = new File("cachedDag/mine-dag.dat").exists();
if (config.isResetPrivateBlockchain()) {
deleteFolder(new File(config.getDbName()), true);
}
if (dagCached) {
new File(config.getDbName()).mkdirs();
try {
FileUtils.copyFile(new File("cachedDag/mine-dag.dat"), new File(config.getDbName() + "/mine-dag.dat"));
FileUtils.copyFile(new File("cachedDag/mine-dag-light.dat"), new File(config.getDbName() + "/mine-dag-light.dat"));
} catch (IOException e) {
throw new EthereumApiException("error while copying dag files", e);
}
}
MinerConfig.dbName = config.getDbName();
Ethereum ethereum = EthereumFactory.createEthereum(MinerConfig.class);
EthereumBackend ethereumBackend = new EthereumReal(ethereum);
ethereum.initSyncing();
if (!dagCached) {
try {
new File("cachedDag").mkdirs();
FileUtils.copyFile(new File(config.getDbName() + "/mine-dag.dat"), new File("cachedDag/mine-dag.dat"));
FileUtils.copyFile(new File(config.getDbName() + "/mine-dag-light.dat"), new File("cachedDag/mine-dag-light.dat"));
} catch (IOException e) {
log.warn("couldn't copy files: " + e.getMessage());
}
}
EthereumEventHandler ethereumListener = new EthereumEventHandler();
final EthereumFacade facade = CoreEthereumFacadeProvider.create(ethereumBackend, ethereumConfig);
// This event does not trigger when you are the miner
ethereumListener.onReady();
facade.events().ready().thenAccept((b) -> config.getInitialBalances().entrySet().stream().map(entry -> facade.sendEther(mainAccount, entry.getKey().getAddress(), entry.getValue())).forEach(result -> {
try {
result.get();
} catch (InterruptedException | ExecutionException e) {
throw new EthereumApiException("error while setting the initial balances");
}
}));
return facade;
}
Aggregations