From ce7c2c1c062fe3bdc92e16ef160b3d4a4f2e8e95 Mon Sep 17 00:00:00 2001 From: Satya Date: Thu, 19 Dec 2024 22:15:51 +0800 Subject: [PATCH] feat: #68 Added "up" command. NPM macos initial layout --- .../cardano/yacicli/CustomShellRunner.java | 35 +++++ .../cardano/yacicli/YaciCliApplication.java | 50 ------- .../commands/general/DownloadCommand.java | 125 +++++++++++++++--- .../config/ApplicationConfig.java | 35 +++++ .../localcluster/ogmios/OgmiosCommands.java | 18 +-- .../localcluster/ogmios/OgmiosService.java | 31 +---- .../yacistore/YaciStoreCommands.java | 8 +- .../yacistore/YaciStoreService.java | 21 +-- .../config/application.properties | 34 +++++ .../config/download.properties | 12 ++ .../config/node.properties | 99 ++++++++++++++ npm/yaci-devkit-macos-arm64/package.json | 17 +++ npm/yaci-devkit/package-lock.json | 23 +++- npm/yaci-devkit/package.json | 3 +- npm/yaci-devkit/start.mjs | 22 ++- 15 files changed, 400 insertions(+), 133 deletions(-) create mode 100644 applications/cli/src/main/java/com/bloxbean/cardano/yacicli/CustomShellRunner.java create mode 100644 npm/yaci-devkit-macos-arm64/config/application.properties create mode 100644 npm/yaci-devkit-macos-arm64/config/download.properties create mode 100644 npm/yaci-devkit-macos-arm64/config/node.properties create mode 100644 npm/yaci-devkit-macos-arm64/package.json diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/CustomShellRunner.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/CustomShellRunner.java new file mode 100644 index 0000000..864e513 --- /dev/null +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/CustomShellRunner.java @@ -0,0 +1,35 @@ +package com.bloxbean.cardano.yacicli; + +import lombok.RequiredArgsConstructor; +import org.springframework.boot.ApplicationArguments; +import org.springframework.core.annotation.Order; +import org.springframework.shell.ShellRunner; +import org.springframework.shell.jline.InteractiveShellRunner; +import org.springframework.shell.jline.NonInteractiveShellRunner; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Order(-100) +public class CustomShellRunner implements ShellRunner { + private final NonInteractiveShellRunner nonInteractiveShellRunner; + private final InteractiveShellRunner interactiveShellRunner; + + @Override + public boolean canRun(ApplicationArguments args) { + return true; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + boolean canRun = nonInteractiveShellRunner.canRun(args); + if (canRun) + nonInteractiveShellRunner.run(args); + + var interactive = args.containsOption("i") || args.containsOption("interactive"); + + if (interactive) { + interactiveShellRunner.run(args); + } + } +} diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/YaciCliApplication.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/YaciCliApplication.java index 9940c21..95ceda5 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/YaciCliApplication.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/YaciCliApplication.java @@ -1,25 +1,11 @@ package com.bloxbean.cardano.yacicli; -import com.bloxbean.cardano.yacicli.localcluster.ClusterConfig; import com.bloxbean.cardano.yacicli.localcluster.config.GenesisConfig; -import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.ApplicationArguments; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.shell.jline.NonInteractiveShellRunner; -import org.springframework.stereotype.Component; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; @SpringBootApplication @EnableConfigurationProperties(GenesisConfig.class) @@ -32,42 +18,6 @@ public static void main(String[] args) { .run(args); } - @Component - public class InitBean{ - ClusterConfig clusterConfig; - NonInteractiveShellRunner nonInteractiveShellRunner; - - public InitBean(ClusterConfig clusterConfig, NonInteractiveShellRunner nonInteractiveShellRunner) { - this.clusterConfig = clusterConfig; - this.nonInteractiveShellRunner = nonInteractiveShellRunner; - } - - @PostConstruct - public void initialize() throws IOException { - Path path = Path.of(clusterConfig.getCLIBinFolder()); - if (!Files.exists(path)) - Files.createDirectories(path); - - nonInteractiveShellRunner.setCommandsFromInputArgs(commandsFromInputArgs); - } - } - - //Used to parse multiple comma separate commands for NonInteractiveShellRunner - private Function> commandsFromInputArgs = args -> { - if (args.getSourceArgs().length == 0) { - return Collections.emptyList(); - } - - String raw = Arrays.stream(args.getSourceArgs()) - .collect(Collectors.joining(" ")); - String[] commands = raw.split(","); - for (String cmd: commands) { - if (log.isDebugEnabled()) - log.debug("Command: " + cmd); - } - return Arrays.asList(commands); - }; - @PreDestroy public void onShutDown() { } diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java index a903e8e..a7361b3 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java @@ -2,53 +2,138 @@ import com.bloxbean.cardano.yacicli.commands.common.DownloadService; import com.bloxbean.cardano.yacicli.commands.common.Groups; +import com.bloxbean.cardano.yacicli.localcluster.ClusterCommands; +import com.bloxbean.cardano.yacicli.localcluster.config.ApplicationConfig; +import com.bloxbean.cardano.yacicli.localcluster.profiles.GenesisProfile; import lombok.RequiredArgsConstructor; +import org.springframework.shell.Availability; import org.springframework.shell.standard.*; -import static com.bloxbean.cardano.yacicli.util.ConsoleWriter.error; -import static com.bloxbean.cardano.yacicli.util.ConsoleWriter.writeLn; +import java.util.ArrayList; +import java.util.Arrays; + +import static com.bloxbean.cardano.yacicli.util.ConsoleWriter.*; @ShellComponent @ShellCommandGroup(Groups.GENERAL_CMD_GROUP) @RequiredArgsConstructor public class DownloadCommand { + private final ApplicationConfig applicationConfig; private final DownloadService downloadService; + private final ClusterCommands clusterCommands; @ShellMethod(value = "Download", key = "download") - @ShellMethodAvailability("generalCmdAvailability") - public void download( - @ShellOption(value = {"--component", "-c"}, defaultValue = "all", help = "node,ogmios,kupo,yaci-store,yaci-store-jar") String component, + @ShellMethodAvailability({"nonDockerCommandAvailability"}) + public boolean download( + @ShellOption(value = {"--component", "-c"}, defaultValue = "all", help = "Provide list of components separated by space. Components: node,ogmios,kupo,yaci-store,yaci-store-jar") String[] components, @ShellOption(value = {"-o", "--overwrite"}, defaultValue = "false", help = "Overwrite existing installation. default: false") boolean overwrite ) { try { - - if (component == null) { + if (components == null) { writeLn(error("Component is not provided. Please provide the component to download")); - return; + return false; } - if (component.equals("node")) { + var componentList = Arrays.asList(components); + boolean validComponent = false; + + if (componentList.contains("all") || componentList.contains("node")) { downloadService.downloadNode(overwrite); - } else if (component.equals("yaci-store")) { + validComponent = true; + } + + if (componentList.contains("all") || componentList.contains("yaci-store")) { downloadService.downloadYaciStoreNative(overwrite); - } else if (component.equals("yaci-store-jar")) { + validComponent = true; + } + + if (componentList.contains("all") || componentList.contains("yaci-store-jar")) { downloadService.downloadYaciStoreJar(overwrite); - } else if (component.equals("ogmios")) { - downloadService.downloadOgmios(overwrite); - } else if (component.equals("kupo")) { - downloadService.downloadKupo(overwrite); - } else if (component.equals("all")) { - downloadService.downloadNode(overwrite); - downloadService.downloadYaciStoreNative(overwrite); + validComponent = true; + } + + if (componentList.contains("all") || componentList.contains("ogmios")) { downloadService.downloadOgmios(overwrite); + validComponent = true; + } + + if (componentList.contains("all") || componentList.contains("kupo")) { downloadService.downloadKupo(overwrite); - } else { - writeLn(error("Invalid component : " + component)); + validComponent = true; + } + + if (!validComponent) { + writeLn(error("Invalid components : " + componentList)); + return false; } } catch (Exception e) { writeLn(error("Error downloading component : " + e.getMessage())); + return false; + } + + return true; + } + + @ShellMethod(value = "Download and Start DevNet with other selected components", key = "up") + @ShellMethodAvailability({"nonDockerCommandAvailability"}) + public void downloadAndStart( + @ShellOption(value = {"--component", "-c"}, defaultValue = "node", help = "Provide list of components separated by space. Components: node,ogmios,kupo,yaci-store,yaci-store-jar") String[] components, + @ShellOption(value = {"-o", "--overwrite"}, defaultValue = "false", help = "Overwrite existing installation. default: false") boolean overwrite, + @ShellOption(value = {"-n", "--name"}, defaultValue = "default", help = "Node Name") String clusterName, + @ShellOption(value = {"--port"}, help = "Node port (Used with --create option only)", defaultValue = "3001") int port, + @ShellOption(value = {"--submit-api-port"}, help = "Submit Api Port", defaultValue = "8090") int submitApiPort, + @ShellOption(value = {"-s", "--slot-length"}, help = "Slot Length in sec. (0.1 to ..)", defaultValue = "1") double slotLength, + @ShellOption(value = {"-b", "--block-time"}, help = "Block time in sec. (1 - 20)", defaultValue = "1") double blockTime, + @ShellOption(value = {"-e", "--epoch-length"}, help = "No of slots in an epoch", defaultValue = "600") int epochLength, + @ShellOption(value = {"--genesis-profile"}, defaultValue = ShellOption.NULL, + help = "Use a pre-defined genesis profile (Options: zero_fee, zero_min_utxo_value, zero_fee_and_min_utxo_value)") GenesisProfile genesisProfile, + @ShellOption(value = {"--enable-yaci-store"}, defaultValue = "false", help = "Enable Yaci Store. This will also enable Ogmios for Tx Evaluation") boolean enableYaciStore, + @ShellOption(value = {"--enable-kupomios"}, defaultValue = "false", help= "Enable Ogmios and Kupo") boolean enableKupomios, + @ShellOption(value = {"--interactive"}, defaultValue="false", help="To start in interactive mode when 'up' command is passed as an arg to yaci-cli") boolean interactive, + @ShellOption(value = {"--tail"}, defaultValue="false", help="To tail the network when 'up' command is passed as an arg to yaci-cli. Only works in non-interactive mode.") boolean tail + ) { + + if (components == null) + components = new String[0]; + + var componentList = new ArrayList<>(Arrays.asList(components)); + + if (enableYaciStore) { + applicationConfig.setYaciStoreEnabled(true); + applicationConfig.setOgmiosEnabled(true); + } else if (enableKupomios){ + applicationConfig.setOgmiosEnabled(true); + applicationConfig.setKupoEnabled(true); } + + if (enableYaciStore) { + if (!componentList.contains("yaci-store")) + componentList.add("yaci-store"); + if (!componentList.contains("ogmios")) { + componentList.add("ogmios"); + } + } else if (enableKupomios) { + if (!componentList.contains("ogmios")) + componentList.add("ogmios"); + if (!componentList.contains("kupo")) + componentList.add("kupo"); + } + + var status = download(componentList.toArray(new String[0]), overwrite); + if (status) { + clusterCommands.createCluster(clusterName, port, submitApiPort, slotLength, blockTime, epochLength, + true, true, null, genesisProfile, false); + + if (!interactive && tail) + clusterCommands.ltail(true, true, true, true, true, true, null, null); + } + } + + public Availability nonDockerCommandAvailability() { + return !applicationConfig.isDocker() + ? Availability.available() + : Availability.unavailable("This command is only supported in non-Docker mode."); } } diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/config/ApplicationConfig.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/config/ApplicationConfig.java index 5d6f773..fc18b63 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/config/ApplicationConfig.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/config/ApplicationConfig.java @@ -1,14 +1,22 @@ package com.bloxbean.cardano.yacicli.localcluster.config; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent; import org.springframework.context.event.EventListener; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component +@RequiredArgsConstructor @Getter public class ApplicationConfig { + public final static String YACI_STORE_ENABLED = "yaci.store.enabled"; + private final static String OGMIOS_ENABLED = "ogmios.enabled"; + private final static String KUPO_ENABLED = "kupo.enabled"; + + private final Environment environment; @Value("${is.docker:false}") private boolean isDocker; @@ -19,4 +27,31 @@ public class ApplicationConfig { public void onApplicationEvent(final ServletWebServerInitializedEvent event) { adminPort = event.getWebServer().getPort(); } + + public boolean isYaciStoreEnabled() { + var enabled = environment.getProperty(YACI_STORE_ENABLED, Boolean.class); + return enabled != null? enabled: false; + } + + public void setYaciStoreEnabled(boolean flag) { + System.setProperty(YACI_STORE_ENABLED, String.valueOf(flag)); + } + + public boolean isOgmiosEnabled() { + var enabled = environment.getProperty(OGMIOS_ENABLED, Boolean.class); + return enabled != null? enabled: false; + } + + public void setOgmiosEnabled(boolean flag) { + System.setProperty(OGMIOS_ENABLED, String.valueOf(flag)); + } + + public boolean isKupoEnabled() { + var enabled = environment.getProperty(KUPO_ENABLED, Boolean.class); + return enabled != null? enabled: false; + } + + public void setKupoEnabled(boolean flag) { + System.setProperty(KUPO_ENABLED, String.valueOf(flag)); + } } diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosCommands.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosCommands.java index 95fc7c6..2890e5d 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosCommands.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosCommands.java @@ -2,6 +2,7 @@ import com.bloxbean.cardano.yacicli.commands.common.Groups; import com.bloxbean.cardano.yacicli.common.CommandContext; +import com.bloxbean.cardano.yacicli.localcluster.config.ApplicationConfig; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.shell.Availability; @@ -17,6 +18,7 @@ @RequiredArgsConstructor @Slf4j public class OgmiosCommands { + private final ApplicationConfig appConfig; private final OgmiosService ogmiosService; @ShellMethod(value = "Show recent Ogmios logs", key = "ogmios-logs") @@ -33,33 +35,33 @@ public void showKupoLogs() { @ShellMethod(value = "Enable Ogmios & Kupo") public void enableKupomios() { - ogmiosService.setEnableOgmios(true); - ogmiosService.setEnableKupo(true); + appConfig.setOgmiosEnabled(true); + appConfig.setKupoEnabled(true); writeLn(infoLabel("OK", "Ogmios/Kupo Status: Enable")); } @ShellMethod(value = "Disble Ogmios & Kupo", key ={ "disable-kupomios", "disable-ogmios-kupo"}) public void disableOgmiosKupo() { - ogmiosService.setEnableOgmios(false); - ogmiosService.setEnableKupo(false); + appConfig.setOgmiosEnabled(false); + appConfig.setKupoEnabled(false); writeLn(infoLabel("OK", "Ogmios/Kupo Status: Disable")); } @ShellMethod(value = "Enable Ogmios") public void enableOgmios() { - ogmiosService.setEnableOgmios(true); + appConfig.setOgmiosEnabled(true); writeLn(infoLabel("OK", "Ogmios Status: Enable")); } @ShellMethod(value = "Disble Ogmios") public void disableOgmios() { - ogmiosService.setEnableOgmios(false); + appConfig.setOgmiosEnabled(false); writeLn(infoLabel("OK", "Ogmios Status: Disable")); } @ShellMethod(value = "Check if Ogmios is enabled or disabled") public void checkOgmiosStatus() { - if (ogmiosService.isEnableOgmios()) + if (appConfig.isOgmiosEnabled()) writeLn(info("Ogmios Status: Enable")); else writeLn(info("Ogmios Status: disable")); @@ -67,7 +69,7 @@ public void checkOgmiosStatus() { @ShellMethod(value = "Check if Kupo is enabled or disabled") public void checkKupoStatus() { - if (ogmiosService.isEnableKupo()) + if (appConfig.isKupoEnabled()) writeLn(info("Kupo Status: Enable")); else writeLn(info("Kupo Status: disable")); diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosService.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosService.java index b81cc9a..3b2d86f 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosService.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/ogmios/OgmiosService.java @@ -4,6 +4,7 @@ import com.bloxbean.cardano.yacicli.localcluster.ClusterInfo; import com.bloxbean.cardano.yacicli.localcluster.ClusterPortInfoHelper; import com.bloxbean.cardano.yacicli.localcluster.ClusterService; +import com.bloxbean.cardano.yacicli.localcluster.config.ApplicationConfig; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterCreated; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterDeleted; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterStarted; @@ -16,7 +17,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @@ -34,18 +34,13 @@ @RequiredArgsConstructor @Slf4j public class OgmiosService { + private final ApplicationConfig appConfig; private final ClusterService clusterService; private final ClusterConfig clusterConfig; private final ClusterPortInfoHelper clusterPortInfoHelper; private List processes = new ArrayList<>(); - @Value("${ogmios.enabled:false}") - private boolean enableOgmios; - - @Value("${kupo.enabled:false}") - private boolean enableKupo; - @Autowired private TemplateEngine templateEngine; @@ -59,7 +54,7 @@ public class OgmiosService { public void handleClusterStarted(ClusterStarted clusterStarted) { ogmiosLogs.clear(); kupoLogs.clear(); - if (!enableOgmios && !enableKupo) + if (!appConfig.isOgmiosEnabled() && !appConfig.isKupoEnabled()) return; if (!clusterStarted.getClusterName().equals("default")) { @@ -73,7 +68,7 @@ public void handleClusterStarted(ClusterStarted clusterStarted) { throw new IllegalStateException("Cluster info not found for cluster: " + clusterStarted.getClusterName() + ". Please check if the cluster is created."); - if (enableOgmios) { + if (appConfig.isOgmiosEnabled()) { if (!ogmiosPortAvailabilityCheck(clusterInfo, (msg) -> writeLn(msg))) return; @@ -82,7 +77,7 @@ public void handleClusterStarted(ClusterStarted clusterStarted) { processes.add(process); } - if (enableKupo) { + if (appConfig.isKupoEnabled()) { if (!kupoPortAvailabilityCheck(clusterInfo, (msg) -> writeLn(msg))) return; @@ -291,20 +286,4 @@ public void showLogs(Consumer consumer) { } } } - - public boolean isEnableOgmios() { - return enableOgmios; - } - - public void setEnableOgmios(boolean enableOgmios) { - this.enableOgmios = enableOgmios; - } - - public boolean isEnableKupo() { - return enableKupo; - } - - public void setEnableKupo(boolean enableKupo) { - this.enableKupo = enableKupo; - } } diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreCommands.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreCommands.java index 6f9b746..558554f 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreCommands.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreCommands.java @@ -3,6 +3,7 @@ import com.bloxbean.cardano.yacicli.commands.common.Groups; import com.bloxbean.cardano.yacicli.common.CommandContext; import com.bloxbean.cardano.yacicli.localcluster.ClusterConfig; +import com.bloxbean.cardano.yacicli.localcluster.config.ApplicationConfig; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.shell.Availability; @@ -15,6 +16,7 @@ @RequiredArgsConstructor @Slf4j public class YaciStoreCommands { + private final ApplicationConfig appConfig; private final YaciStoreService yaciStoreService; private final YaciStoreCustomDbHelper yaciStoreCustomDbHelper; @@ -26,19 +28,19 @@ public void showLogs() { @ShellMethod(value = "Enable Yaci Store") public void enableYaciStore() { - yaciStoreService.setEnableYaciStore(true); + appConfig.setYaciStoreEnabled(true); writeLn(infoLabel("OK", "Yaci Store Status: Enable")); } @ShellMethod(value = "Disble Yaci Store") public void disableYaciStore() { - yaciStoreService.setEnableYaciStore(false); + appConfig.setYaciStoreEnabled(false); writeLn(infoLabel("OK", "Yaci Store Status: Disable")); } @ShellMethod(value = "Check if Yaci Store is enable or disable") public void checkYaciStoreStatus() { - if (yaciStoreService.isEnableYaciStore()) + if (appConfig.isYaciStoreEnabled()) writeLn(info("Yaci Store Status: Enable")); else writeLn(info("Yaci Store Status: disable")); diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java index 569c634..a561f9a 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java @@ -6,6 +6,7 @@ import com.bloxbean.cardano.yacicli.localcluster.ClusterConfig; import com.bloxbean.cardano.yacicli.localcluster.ClusterInfo; import com.bloxbean.cardano.yacicli.localcluster.ClusterService; +import com.bloxbean.cardano.yacicli.localcluster.config.ApplicationConfig; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterDeleted; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterStarted; import com.bloxbean.cardano.yacicli.localcluster.events.ClusterStopped; @@ -14,7 +15,6 @@ import com.google.common.collect.EvictingQueue; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @@ -35,6 +35,7 @@ @RequiredArgsConstructor @Slf4j public class YaciStoreService { + private final ApplicationConfig appConfig; private final ClusterService clusterService; private final ClusterConfig clusterConfig; private final JreResolver jreResolver; @@ -43,12 +44,6 @@ public class YaciStoreService { private List processes = new ArrayList<>(); - @Value("${yaci.store.enabled:false}") - private boolean enableYaciStore; - - @Value("${is.docker:false}") - private boolean isDocker; - @Value("${yaci.store.mode:java}") private String yaciStoreMode; @@ -57,7 +52,7 @@ public class YaciStoreService { @EventListener public void handleClusterStarted(ClusterStarted clusterStarted) { logs.clear(); - if (!enableYaciStore) + if (!appConfig.isYaciStoreEnabled()) return; if (!clusterStarted.getClusterName().equals("default")) { @@ -115,7 +110,7 @@ private Process startStoreApp(ClusterInfo clusterInfo, Era era) throws IOExcepti } } - if (!isDocker) { + if (!appConfig.isDocker()) { yaciStoreConfigBuilder.build(clusterInfo); } @@ -310,12 +305,4 @@ public void showLogs(Consumer consumer) { } } } - - public boolean isEnableYaciStore() { - return enableYaciStore; - } - - public void setEnableYaciStore(boolean enableYaciStore) { - this.enableYaciStore = enableYaciStore; - } } diff --git a/npm/yaci-devkit-macos-arm64/config/application.properties b/npm/yaci-devkit-macos-arm64/config/application.properties new file mode 100644 index 0000000..b56712a --- /dev/null +++ b/npm/yaci-devkit-macos-arm64/config/application.properties @@ -0,0 +1,34 @@ +spring.config.import=optional:file:./config/node.properties,optional:file:./config/download.properties + +#admin endpoint ports +server.port=10000 + +#Set the path to the directory where all yaci-cli related files are stored including cardano-node binary. +#Default is the user_home/.yaci-cli +#yaci.cli.home=/Users/satya/yacicli + +ogmios.enabled=false +kupo.enabled=false +yaci.store.enabled=false + +yaci.store.mode=native + +bp.create.enabled=true + +## Default ports +#ogmios.port=1337 +#kupo.port=1442 +#yaci.store.port=8080 +#socat.port=3333 +#prometheus.port=12798 + + +###################################################### +#To configure an external database for Yaci Store (Indexer), +# uncomment the following properties and provide the required values +#Only PostgreSQL is supported for now for external database +###################################################### + +#yaci.store.db.url=jdbc:postgresql://localhost:5433/yaci_indexer?currentSchema=dev +#yaci.store.db.username=user +#yaci.store.db.password= diff --git a/npm/yaci-devkit-macos-arm64/config/download.properties b/npm/yaci-devkit-macos-arm64/config/download.properties new file mode 100644 index 0000000..aa40db0 --- /dev/null +++ b/npm/yaci-devkit-macos-arm64/config/download.properties @@ -0,0 +1,12 @@ +#Please specify either the version or the full url for the following components +node.version=10.1.2 +ogmios.version=6.9.0 +kupo.version=2.9.0 +yaci.store.version=0.1.1-graalvm-preview1 +yaci.store.jar.version=0.1.0 + +#node.url= +#ogmios.url= +#kupo.url= +#yaci.store.url= +#yaci.store.jar.url= diff --git a/npm/yaci-devkit-macos-arm64/config/node.properties b/npm/yaci-devkit-macos-arm64/config/node.properties new file mode 100644 index 0000000..4fabd1a --- /dev/null +++ b/npm/yaci-devkit-macos-arm64/config/node.properties @@ -0,0 +1,99 @@ +#protocolMagic=42 +#maxKESEvolutions=60 +#securityParam=80 +#slotsPerKESPeriod=129600 +#updateQuorum=1 +#peerSharing=true + +## Shelley Genesis +#maxLovelaceSupply=45000000000000000 +#poolPledgeInfluence=0 +#decentralisationParam=0 +#eMax=18 +#keyDeposit=2000000 +#maxBlockBodySize=65536 +#maxBlockHeaderSize=1100 +#maxTxSize=16384 +#minFeeA=44 +#minFeeB=155381 +#minPoolCost=340000000 +#minUTxOValue=1000000 +#nOpt=100 +#poolDeposit=500000000 + +#protocolMajorVer=8 +#protocolMinorVer=0 +#monetaryExpansionRate=0.003f +#treasuryGrowthRate=0.20f + +##Default addresses +#initialAddresses[0].address=addr_test1qzx9hu8j4ah3auytk0mwcupd69hpc52t0cw39a65ndrah86djs784u92a3m5w475w3w35tyd6v3qumkze80j8a6h5tuqq5xe8y +#initialAddresses[0].balance=450000000 +#initialAddresses[0].staked=true +# +#initialAddresses[1].address=addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82 +#initialAddresses[1].balance=250000000 +#initialAddresses[1].staked=false + +##Alonzo +#collateralPercentage=150 +#prMem=5.77e-2 +#prSteps=7.21e-5 +#lovelacePerUTxOWord=34482 +#maxBlockExUnitsMem=62000000 +#maxBlockExUnitsSteps=20000000000 +#maxCollateralInputs=3 +#maxTxExUnitsMem=14000000 +#maxTxExUnitsSteps=10000000000 +#maxValueSize=5000 + +##Conway +#pvtcommitteeNormal=0.51f +#pvtCommitteeNoConfidence=0.51f +#pvtHardForkInitiation=0.51f +#pvtMotionNoConfidence=0.51f +#pvtPPSecurityGroup=0.51f + +#dvtMotionNoConfidence=0.51f +#dvtCommitteeNormal=0.51f +#dvtCommitteeNoConfidence=0.51f +#dvtUpdateToConstitution=0.51f +#dvtHardForkInitiation=0.51f +#dvtPPNetworkGroup=0.51f +#dvtPPEconomicGroup=0.51f +#dvtPPTechnicalGroup=0.51f +#dvtPPGovGroup=0.51f +#dvtTreasuryWithdrawal=0.51f + +#committeeMinSize=0 +#committeeMaxTermLength=200 +#govActionLifetime=10 +#govActionDeposit=1000000000 +#dRepDeposit=2000000 +#dRepActivity=20 + +#constitutionScript=7713eb6a46b67bfa1ca082f2b410b0a4e502237d03f7a0b7cbf1b025 +#constitutionUrl=https://devkit.yaci.xyz/constitution.json +#constitutionDataHash=f89cc2469ce31c3dfda2f3e0b56c5c8b4ee4f0e5f66c30a3f12a95298b01179e + +## CC Members +#ccMembers[0].hash=scriptHash-8fc13431159fdda66347a38c55105d50d77d67abc1c368b876d52ad1 +#ccMembers[0].term=340 + +######################################################################################################## +# Workaround for : https://github.com/bloxbean/yaci-devkit/issues/65 +# +# The following parameters are enabled for a V2 cost model-related issue where there are 10 extra elements if the devnet +# is started with the Conway era at epoch 0. The following parameters are enabled to configure the Conway era hard fork (HF) at epoch 1. +# The network will start in the Babbage era and then hard fork (HF) to the Conway era at epoch 1. + +# The shiftStartTimeBehind=true flag is enabled to shift the start time of the network to a time behind the current time by adjusting security parameter +# which changes the stability window. This is to speed up the process of reaching the Conway era. +# +# This should only be done in a development environment because if the stability window is larger than the epoch length, the reward/treasury calculations will be incorrect or ignored. +# Therefore, for a real multi-node network, you should start the network at the current time and allow it to reach the Conway era at epoch 1. +# So, the shiftStartTimeBehind flag should be "false" for non-development / multi-node networks. +# +######################################################################################################### +conwayHardForkAtEpoch=1 +shiftStartTimeBehind=true diff --git a/npm/yaci-devkit-macos-arm64/package.json b/npm/yaci-devkit-macos-arm64/package.json new file mode 100644 index 0000000..f43c400 --- /dev/null +++ b/npm/yaci-devkit-macos-arm64/package.json @@ -0,0 +1,17 @@ +{ + "name": "@bloxbean/yaci-devkit-macos-arm64", + "version": "0.10.0", + "main": "yaci-cli", + "files": [ + "yaci-cli", + "config" + ], + "license": "MIT", + "engines": { + "node": ">= 12" + }, + "bin": { + "yaci-devkit-linux-x64": "./yaci-cli" + }, + "repository": "github:bloxbean/yaci-devkit" +} diff --git a/npm/yaci-devkit/package-lock.json b/npm/yaci-devkit/package-lock.json index 915b02e..0a3c828 100644 --- a/npm/yaci-devkit/package-lock.json +++ b/npm/yaci-devkit/package-lock.json @@ -9,20 +9,33 @@ "version": "0.10.0", "license": "MIT", "dependencies": { - "@bloxbean/yaci-devkit-linux-x64": "file:../yaci-devkit-linux-x64" + "@bloxbean/yaci-devkit-linux-x64": "file:../yaci-devkit-linux-x64", + "@bloxbean/yaci-devkit-macos-arm64": "file:../yaci-devkit-macos-arm64" }, "bin": { - "yaci-devkit-foo": "index.js" + "yaci-devkit": "start.mjs" }, "devDependencies": { "@types/node": "^22.10.2", "typescript": ">=5.0.0" }, "engines": { - "node": ">= 18" + "node": ">=20.8.0" } }, "../yaci-devkit-linux-x64": { + "name": "@bloxbean/yaci-devkit-linux-x64", + "version": "0.10.0", + "license": "MIT", + "bin": { + "yaci-devkit-linux-x64": "yaci-cli" + }, + "engines": { + "node": ">= 12" + } + }, + "../yaci-devkit-macos-arm64": { + "name": "@bloxbean/yaci-devkit-macos-arm64", "version": "0.10.0", "license": "MIT", "bin": { @@ -36,6 +49,10 @@ "resolved": "../yaci-devkit-linux-x64", "link": true }, + "node_modules/@bloxbean/yaci-devkit-macos-arm64": { + "resolved": "../yaci-devkit-macos-arm64", + "link": true + }, "node_modules/@types/node": { "version": "22.10.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz", diff --git a/npm/yaci-devkit/package.json b/npm/yaci-devkit/package.json index 4602e61..f88c7ae 100644 --- a/npm/yaci-devkit/package.json +++ b/npm/yaci-devkit/package.json @@ -10,7 +10,8 @@ "yaci-devkit": "./start.mjs" }, "dependencies": { - "@bloxbean/yaci-devkit-linux-x64": "file:../yaci-devkit-linux-x64" + "@bloxbean/yaci-devkit-linux-x64": "file:../yaci-devkit-linux-x64", + "@bloxbean/yaci-devkit-macos-arm64": "file:../yaci-devkit-macos-arm64" }, "devDependencies": { "@types/node": "^22.10.2", diff --git a/npm/yaci-devkit/start.mjs b/npm/yaci-devkit/start.mjs index 0bb5515..cc46c72 100755 --- a/npm/yaci-devkit/start.mjs +++ b/npm/yaci-devkit/start.mjs @@ -3,26 +3,28 @@ import { spawn } from "node:child_process"; import { platform } from "node:os"; import { fileURLToPath } from 'node:url'; +import { dirname, resolve } from 'node:path'; +import { createHash } from "node:crypto"; const osType = platform(); /** * Find the script for the corresponding os-specific package. - * + * * Note: it's tempting to solve this in a few ways that are actually bad: * 1. Call `npx