From 586a2478fcc7d65f9913026289b4613c3823c612 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 9 Aug 2023 15:35:46 -0400 Subject: [PATCH] update monero binaries in app directory #655 --- common/src/main/java/haveno/common/file/FileUtil.java | 11 +++++++++++ .../java/haveno/core/api/CoreMoneroNodeService.java | 2 +- core/src/main/java/haveno/core/app/HavenoSetup.java | 8 +++++--- .../java/haveno/core/xmr/wallet/XmrWalletService.java | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/haveno/common/file/FileUtil.java b/common/src/main/java/haveno/common/file/FileUtil.java index 97116ad0..d0a4d614 100644 --- a/common/src/main/java/haveno/common/file/FileUtil.java +++ b/common/src/main/java/haveno/common/file/FileUtil.java @@ -25,6 +25,7 @@ import org.apache.commons.io.IOUtils; import javax.annotation.Nullable; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -175,6 +176,16 @@ public class FileUtil { } } + public static boolean resourceEqualToFile(String resourcePath, + File destinationFile) throws ResourceNotFoundException, IOException { + try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(resourcePath)) { + if (inputStream == null) { + throw new ResourceNotFoundException(resourcePath); + } + return IOUtils.contentEquals(inputStream, new FileInputStream(destinationFile)); + } + } + public static void renameFile(File oldFile, File newFile) throws IOException { if (Utilities.isWindows()) { // Work around an issue on Windows whereby you can't rename over existing files. diff --git a/core/src/main/java/haveno/core/api/CoreMoneroNodeService.java b/core/src/main/java/haveno/core/api/CoreMoneroNodeService.java index 10924411..eb86bd7a 100644 --- a/core/src/main/java/haveno/core/api/CoreMoneroNodeService.java +++ b/core/src/main/java/haveno/core/api/CoreMoneroNodeService.java @@ -40,7 +40,7 @@ import java.util.List; @Singleton public class CoreMoneroNodeService { - public static final String MONEROD_DIR = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_LOCAL ? System.getProperty("user.dir") + File.separator + ".localnet" : Config.appDataDir().getAbsolutePath(); + public static final String MONEROD_DIR = Config.appDataDir().getAbsolutePath(); public static final String MONEROD_NAME = Utilities.isWindows() ? "monerod.exe" : "monerod"; public static final String MONEROD_PATH = MONEROD_DIR + File.separator + MONEROD_NAME; private static final String MONEROD_DATADIR = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_LOCAL ? MONEROD_DIR + File.separator + Config.baseCurrencyNetwork().toString().toLowerCase() + File.separator + "node1" : null; // use default directory unless local diff --git a/core/src/main/java/haveno/core/app/HavenoSetup.java b/core/src/main/java/haveno/core/app/HavenoSetup.java index fef2f905..a93cea8a 100644 --- a/core/src/main/java/haveno/core/app/HavenoSetup.java +++ b/core/src/main/java/haveno/core/app/HavenoSetup.java @@ -340,7 +340,8 @@ public class HavenoSetup { private void maybeInstallDependencies() { try { File monerodFile = new File(CoreMoneroNodeService.MONEROD_PATH); - if (!monerodFile.exists()) { + String monerodResourcePath = "bin/" + CoreMoneroNodeService.MONEROD_NAME; + if (!monerodFile.exists() || !FileUtil.resourceEqualToFile(monerodResourcePath, monerodFile)) { log.info("Installing monerod"); monerodFile.getParentFile().mkdirs(); FileUtil.resourceToFile("bin/" + CoreMoneroNodeService.MONEROD_NAME, monerodFile); @@ -348,10 +349,11 @@ public class HavenoSetup { } File moneroWalletFile = new File(XmrWalletService.MONERO_WALLET_RPC_PATH); - if (!moneroWalletFile.exists()) { + String moneroWalletResourcePath = "bin/" + XmrWalletService.MONERO_WALLET_RPC_NAME; + if (!moneroWalletFile.exists() || !FileUtil.resourceEqualToFile(moneroWalletResourcePath, moneroWalletFile)) { log.info("Installing monero-wallet-rpc"); moneroWalletFile.getParentFile().mkdirs(); - FileUtil.resourceToFile("bin/" + XmrWalletService.MONERO_WALLET_RPC_NAME, moneroWalletFile); + FileUtil.resourceToFile(moneroWalletResourcePath, moneroWalletFile); moneroWalletFile.setExecutable(true); } } catch (Exception e) { diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 516abd50..d2bbbd94 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -86,7 +86,7 @@ public class XmrWalletService { public static final int NUM_BLOCKS_UNLOCK = 10; private static final MoneroNetworkType MONERO_NETWORK_TYPE = getMoneroNetworkType(); private static final MoneroWalletRpcManager MONERO_WALLET_RPC_MANAGER = new MoneroWalletRpcManager(); - public static final String MONERO_WALLET_RPC_DIR = Config.baseCurrencyNetwork().isTestnet() ? System.getProperty("user.dir") + File.separator + ".localnet" : Config.appDataDir().getAbsolutePath(); // .localnet contains monero-wallet-rpc and wallet files + public static final String MONERO_WALLET_RPC_DIR = Config.appDataDir().getAbsolutePath(); public static final String MONERO_WALLET_RPC_NAME = Utilities.isWindows() ? "monero-wallet-rpc.exe" : "monero-wallet-rpc"; public static final String MONERO_WALLET_RPC_PATH = MONERO_WALLET_RPC_DIR + File.separator + MONERO_WALLET_RPC_NAME; private static final String MONERO_WALLET_RPC_USERNAME = "haveno_user";