Skip to content

Commit ea7b0c8

Browse files
committed
remove ton binaries from ton4j repo, used package installers to get ones.
Instead of specifying a path to a binary/library all builders try find the installed one. Info on how to install ton binaries - https://github.com/ton-blockchain/packages. update commons-io.
1 parent 1dfdd50 commit ea7b0c8

File tree

33 files changed

+2645
-2706
lines changed

33 files changed

+2645
-2706
lines changed

emulator/src/main/java/org/ton/java/emulator/tvm/TvmEmulator.java

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,8 @@
2222
public class TvmEmulator {
2323

2424
/**
25-
* If not specified then emulator shared library must be located in:<br>
26-
*
27-
* <ul>
28-
* <li><code>jna.library.path</code> User-customizable path
29-
* <li><code>jna.platform.library.path</code> Platform-specific paths
30-
* <li>On OSX, ~/Library/Frameworks, /Library/Frameworks, and /System/Library/Frameworks will be
31-
* searched for a framework with a name corresponding to that requested. Absolute paths to
32-
* frameworks are also accepted, either ending at the framework name (sans ".framework") or
33-
* the full path to the framework shared library (e.g. CoreServices.framework/CoreServices).
34-
* <li>Context class loader classpath. Deployed native libraries may be installed on the
35-
* classpath under ${os-prefix}/LIBRARY_FILENAME, where ${os-prefix} is the OS/Arch prefix
36-
* returned by Platform.getNativeLibraryResourcePrefix(). If bundled in a jar file, the
37-
* resource will be extracted to jna.tmpdir for loading, and later removed.
38-
* </ul>
39-
*
40-
* <br>
41-
* Java Tonlib looking for following filenames in above locations:<br>
42-
*
43-
* <ul>
44-
* <li>libemulator-linux-x86_64.so and libemulator-linux-arm64.so
45-
* <li>emulator.dll and emulator-arm.dll
46-
* <li>libemulator-mac-x86-64.dylib and libemulator-mac-arm64.dylib
47-
* <ul>
25+
* If not specified then tries to find emulator in system folder, more info <a
26+
* href="https://github.com/ton-blockchain/packages">here</a>
4827
*/
4928
private String pathToEmulatorSharedLib;
5029

@@ -64,35 +43,13 @@ public static TvmEmulatorBuilder builder() {
6443
private static class CustomTvmEmulatorBuilder extends TvmEmulatorBuilder {
6544
@Override
6645
public TvmEmulator build() {
67-
String emulatorName;
68-
Utils.OS os = Utils.getOS();
69-
switch (os) {
70-
case LINUX:
71-
emulatorName = "libemulator-linux-x86_64.so";
72-
break;
73-
case LINUX_ARM:
74-
emulatorName = "libemulator-linux-arm64.so";
75-
break;
76-
case WINDOWS:
77-
emulatorName = "emulator.dll";
78-
break;
79-
case WINDOWS_ARM:
80-
emulatorName = "emulator-arm.dll";
81-
break;
82-
case MAC:
83-
emulatorName = "libemulator-mac-x86-64.dylib";
84-
break;
85-
case MAC_ARM64:
86-
emulatorName = "libemulator-mac-arm64.dylib";
87-
break;
88-
case UNKNOWN:
89-
throw new Error("Operating system is not supported!");
90-
default:
91-
throw new IllegalArgumentException("Unknown operating system: " + os);
92-
}
9346

9447
if (isNull(super.pathToEmulatorSharedLib)) {
95-
super.pathToEmulatorSharedLib = emulatorName;
48+
if ((Utils.getOS() == Utils.OS.WINDOWS) || (Utils.getOS() == Utils.OS.WINDOWS_ARM)) {
49+
super.pathToEmulatorSharedLib = Utils.detectAbsolutePath("emulator", true);
50+
} else {
51+
super.pathToEmulatorSharedLib = Utils.detectAbsolutePath("libemulator", true);
52+
}
9653
}
9754

9855
super.tvmEmulatorI = Native.load(super.pathToEmulatorSharedLib, TvmEmulatorI.class);

emulator/src/main/java/org/ton/java/emulator/tx/TxEmulator.java

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,8 @@
1212
import org.ton.java.utils.Utils;
1313

1414
/**
15-
*
16-
*
17-
* <pre>
18-
* If not specified then emulator shared library must be located in:
19-
* <ul>
20-
* <li><code>jna.library.path</code> User-customizable path</li>
21-
* <li><code>jna.platform.library.path</code> Platform-specific paths</li>
22-
* <li>On OSX, ~/Library/Frameworks, /Library/Frameworks, and /System/Library/Frameworks will be searched for a framework with a name corresponding to that requested. Absolute paths to frameworks are also accepted, either ending at the framework name (sans ".framework") or the full path to the framework shared library (e.g. CoreServices.framework/CoreServices).</li>
23-
* <li>Context class loader classpath. Deployed native libraries may be installed on the classpath under ${os-prefix}/LIBRARY_FILENAME, where ${os-prefix} is the OS/Arch prefix returned by Platform.getNativeLibraryResourcePrefix(). If bundled in a jar file, the resource will be extracted to jna.tmpdir for loading, and later removed.</li>
24-
* </ul>
25-
*
26-
* Java Tonlib looking for following filenames in above locations:<br>
27-
* <ul>
28-
* <li>libemulator-linux-x86-64.so and libemulator-linux-arm64.so</li>
29-
* <li>emulator.dll and emulator-arm.dll</li>
30-
* <li>libemulator-mac-x86-64.dylib and libemulator-mac-arm64.dylib</li>
31-
* <ul>
32-
* </pre>
15+
* If not specified then tries to find emulator in system folder, more info <a
16+
* href="https://github.com/ton-blockchain/packages">here</a>
3317
*/
3418
@Log
3519
@Builder
@@ -51,35 +35,13 @@ public static TxEmulatorBuilder builder() {
5135
private static class CustomEmulatorBuilder extends TxEmulatorBuilder {
5236
@Override
5337
public TxEmulator build() {
54-
String emulatorName;
55-
Utils.OS os = Utils.getOS();
56-
switch (os) {
57-
case LINUX:
58-
emulatorName = "libemulator-linux-x86-64.so";
59-
break;
60-
case LINUX_ARM:
61-
emulatorName = "libemulator-linux-arm64.so";
62-
break;
63-
case WINDOWS:
64-
emulatorName = "emulator.dll";
65-
break;
66-
case WINDOWS_ARM:
67-
emulatorName = "emulator-arm.dll";
68-
break;
69-
case MAC:
70-
emulatorName = "libemulator-mac-x86-64.dylib";
71-
break;
72-
case MAC_ARM64:
73-
emulatorName = "libemulator-mac-arm64.dylib";
74-
break;
75-
case UNKNOWN:
76-
throw new Error("Operating system is not supported!");
77-
default:
78-
throw new IllegalArgumentException("Unknown operating system: " + os);
79-
}
8038

8139
if (isNull(super.pathToEmulatorSharedLib)) {
82-
super.pathToEmulatorSharedLib = emulatorName;
40+
if ((Utils.getOS() == Utils.OS.WINDOWS) || (Utils.getOS() == Utils.OS.WINDOWS_ARM)) {
41+
super.pathToEmulatorSharedLib = Utils.detectAbsolutePath("emulator", true);
42+
} else {
43+
super.pathToEmulatorSharedLib = Utils.detectAbsolutePath("libemulator", true);
44+
}
8345
}
8446

8547
super.txEmulatorI = Native.load(super.pathToEmulatorSharedLib, TxEmulatorI.class);
@@ -90,12 +52,6 @@ public TxEmulator build() {
9052
throw new Error("Config is not set");
9153
}
9254

93-
String ss = super.txEmulatorI.emulator_version();
94-
System.out.println("version = " + ss);
95-
96-
long s = super.txEmulator = super.txEmulatorI.emulator_config_create(super.configBoc);
97-
System.out.println("s = " + s);
98-
9955
super.txEmulator =
10056
super.txEmulatorI.transaction_emulator_create(
10157
super.configBoc, super.verbosityLevel.ordinal());
@@ -208,6 +164,7 @@ public boolean setConfig(String configBoc) {
208164

209165
/**
210166
* Creates Config object from base64 encoded BoC
167+
*
211168
* @param configBoc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
212169
* @return Pointer to Config object or nullptr in case of error
213170
*/
@@ -217,6 +174,7 @@ public long createConfig(String configBoc) {
217174

218175
/**
219176
* Destroy Config object
177+
*
220178
* @param config Pointer to Config object
221179
*/
222180
public void destroyConfig(long config) {

emulator/src/test/java/org/ton/java/emulator/TestTvmEmulator.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public static void setUpBeforeClass() {
5858

5959
log.info("pubKey {}", Utils.bytesToHex(keyPair.getPublicKey()));
6060
log.info("prvKey {}", Utils.bytesToHex(keyPair.getSecretKey()));
61-
tonlib = Tonlib.builder()
62-
.pathToTonlibSharedLib("/home/neodix/gitProjects/ton-neodix/build/tonlib/libtonlibjson.so")
63-
.testnet(true).ignoreCache(false).build();
61+
tonlib = Tonlib.builder().testnet(true).ignoreCache(false).build();
6462

6563
walletV4R2 = WalletV4R2.builder().tonlib(tonlib).keyPair(keyPair).walletId(42).build();
6664

@@ -77,7 +75,6 @@ public static void setUpBeforeClass() {
7775

7876
tvmEmulator =
7977
TvmEmulator.builder()
80-
.pathToEmulatorSharedLib("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so")
8178
.codeBoc(code.toBase64())
8279
.dataBoc(data.toBase64())
8380
.verbosityLevel(TvmVerbosityLevel.UNLIMITED)
@@ -88,7 +85,8 @@ public static void setUpBeforeClass() {
8885
@Test
8986
public void testInitTvmEmulator() {
9087
// TvmEmulatorI tvmEmulatorI = Native.load("emulator.dll", TvmEmulatorI.class);
91-
TvmEmulatorI tvmEmulatorI = Native.load("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so", TvmEmulatorI.class);
88+
TvmEmulatorI tvmEmulatorI =
89+
Native.load(Utils.detectAbsolutePath("emulator", true), TvmEmulatorI.class);
9290
long emulator =
9391
tvmEmulatorI.tvm_emulator_create(
9492
walletV4R2.getStateInit().getCode().toBase64(),
@@ -157,7 +155,7 @@ public void testTvmEmulatorEmulateRunMethod() {
157155
.storeRef(
158156
CellBuilder.beginCell()
159157
.storeRef(stack.toCell()) // c7 ^VmStack
160-
// .storeRef(getLibs()) // libs ^Cell
158+
// .storeRef(getLibs()) // libs ^Cell
161159
.endCell())
162160
.storeUint(Utils.calculateMethodId("seqno"), 32) // method-id - seqno
163161
.endCell()
@@ -670,7 +668,6 @@ public void testTvmEmulatorSendInternalMessageCustomContract() throws IOExceptio
670668

671669
tvmEmulator =
672670
TvmEmulator.builder()
673-
.pathToEmulatorSharedLib("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so")
674671
.codeBoc(codeCell.toBase64())
675672
.dataBoc(dataCell.toBase64())
676673
.verbosityLevel(TvmVerbosityLevel.UNLIMITED)

0 commit comments

Comments
 (0)