Skip to content

Commit

Permalink
add possibility to specify a custom path to ton binaries, in nogui mo…
Browse files Browse the repository at this point in the history
…de for now
  • Loading branch information
neodix42 committed Oct 23, 2024
1 parent fd21208 commit 521bae3
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msv
## MyLocalTon usage

`java -jar MyLocalTon-x86-64.jar [nogui] [ton-http-api] [explorer] [ip.addr.xxx.xxx] [test-binaries] [test-tonlib
] [with-validators-N] [debug]`
] [with-validators-N] [custom-binaries=] [debug]`

for ARM64 architecture use:

Expand All @@ -71,6 +71,7 @@ for ARM64 architecture use:
* `explorer` - enables native ton blockchain explorer on start. Runs on port `8000`.
* `ip.addr.xxx.xxx` - used to bind specific IP to MyLocalTon instead of 127.0.0.1.
* `with-validators-N` - used to start MyLocalTon with N additional validators.
* `custom-binaries=absolute-path` - used to start MyLocalTon with custom TON binaries. The folder should contain validator-engine, validator-engine-console, lite-client, fift, func, generate-random-id, create-state, dht-server, tonlibjson, blockchain-explorer binaries and also **smartcont** and lib **folders** in its root folder.
* `debug` - used to start MyLocalTon in debug mode, that produces lots of useful log files.

### Lite-client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ private boolean generateZeroState(Node node) throws IOException {

String createStateResult = new CreateStateExecutor().execute(node, node.getTonBinDir() + "smartcont" + File.separator + "gen-zerostate.fif");

// log.debug("creating zero-state output: {}", createStateResult);
log.debug("creating zero-state output");
log.debug("creating zero-state output: {}", createStateResult);
// log.debug("creating zero-state output");

String mainWalletAddrBoth = sb(createStateResult, "wallet address = ", "(Saving address to file");
String electorSmcAddrBoth = sb(createStateResult, "elector smart contract address = ", "(Saving address to file");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/ton/main/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static void main(MyLocalTonSettings settings, MyLocalTon myLocalTon, Stri

Node genesisNode = settings.getGenesisNode();
genesisNode.extractBinaries();
if (nonNull(settings.getCustomTonBinariesPath())) {
genesisNode.setTonCustomBinDir(settings.getCustomTonBinariesPath());
}

if (!Arrays.asList(args).isEmpty()) {
for (String arg : args) {
Expand Down Expand Up @@ -243,6 +246,7 @@ public static void main(MyLocalTonSettings settings, MyLocalTon myLocalTon, Stri
//creating additional validator node
log.info("creating validator {}", node.getNodeName());
node.setTonLogLevel(settings.getGenesisNode().getTonLogLevel());
node.setTonCustomBinDir(settings.getGenesisNode().getTonCustomBinDir());

//delete unfinished or failed node creation
FileUtils.deleteQuietly(new File(MyLocalTonSettings.MY_APP_DIR + File.separator + node.getNodeName()));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/ton/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.net.InetAddresses;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.ton.actions.MyLocalTon;
import org.ton.settings.MyLocalTonSettings;
Expand Down Expand Up @@ -63,6 +64,12 @@ public static void main(String[] args) throws Throwable {
System.setProperty("java.awt.headless", "true");
}

if (arg.contains("custom-binaries")) {
String path = StringUtils.remove(arg, "custom-binaries=");
settings.setCustomTonBinariesPath(path);
log.info("using custom TON binaries at path {}", path);
}

if (arg.equalsIgnoreCase("ton-http-api")) {
log.info("enabling ton-http-api on start (default port 8081)");
settings.getUiSettings().setEnableTonHttpApi(true);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/GenesisNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class GenesisNode implements Serializable, Node {

String tonLogLevel = "INFO";
public String myLocalTonLogLevel = "INFO";
String tonCustomBinDir;

String validatorPrvKeyHex;
String validatorPrvKeyBase64;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/MyLocalTonSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public MyLocalTonSettings() {
public Map<Long, ValidationParam> elections = new ConcurrentSkipListMap<>();

Boolean veryFirstElections = Boolean.TRUE;
String customTonBinariesPath;

//options - account and keys
@Getter
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/ton/settings/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ default String getTonDbDir() {
}

default String getTonBinDir() {
if (nonNull(getTonCustomBinDir())) {
return getTonCustomBinDir() + File.separator;
}
return CURRENT_DIR + File.separator + MY_LOCAL_TON + File.separator + this.getNodeName() + File.separator + "bin" + File.separator;
}

Expand Down Expand Up @@ -323,4 +326,7 @@ default boolean nodeShutdown() {

void setTonLogLevel(String logLevel);

void setTonCustomBinDir(String path);
String getTonCustomBinDir();

}
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node2.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node2 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node3.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node3 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node4.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node4 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node5.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node5 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node6.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node6 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ton/settings/Node7.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Node7 implements Serializable, Node {
Long validatorSyncBefore = 3600L; // 1h, initial sync download all blocks for last given seconds default=3600, 1 hour

String tonLogLevel = "ERROR";
String tonCustomBinDir;

String validatorMonitoringPubKeyHex;
String validatorMonitoringPubKeyInteger;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/ton/utils/Extractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.lingala.zip4j.ZipFile;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.ton.actions.MyLocalTon;
import org.ton.settings.MyLocalTonSettings;

import java.io.File;
Expand All @@ -15,6 +16,7 @@
import java.nio.file.StandardCopyOption;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

@Slf4j
public class Extractor {
Expand Down Expand Up @@ -58,6 +60,13 @@ private void extractBinaries() throws IOException {
Files.createDirectories(Paths.get(MY_LOCAL_TON_ROOT_DIR + nodeName + File.separator + DB + File.separator + "static"));
Files.createDirectories(Paths.get(MY_LOCAL_TON_ROOT_DIR + nodeName + File.separator + DB + File.separator + "keyring"));
Files.createDirectories(Paths.get(MY_LOCAL_TON_ROOT_DIR + nodeName + File.separator + DB + File.separator + "log"));
if (nonNull(MyLocalTon.getInstance().getSettings().getCustomTonBinariesPath())) {
Files.createDirectories(Paths.get(MyLocalTon.getInstance().getSettings().getCustomTonBinariesPath()+ File.separator + "tonlib-keystore"));
Files.createDirectories(Paths.get(MyLocalTon.getInstance().getSettings().getCustomTonBinariesPath() + File.separator + "wallets"));
Files.createDirectories(Paths.get(MyLocalTon.getInstance().getSettings().getCustomTonBinariesPath()+ File.separator + "zerostate"));
Files.createDirectories(Paths.get(MyLocalTon.getInstance().getSettings().getCustomTonBinariesPath()+ File.separator + "certs"));

}


if (SystemUtils.IS_OS_WINDOWS) {
Expand Down

0 comments on commit 521bae3

Please sign in to comment.