diff --git a/README.md b/README.md index c6f9b817..a9d2baca 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ found [here](https://github.com/ton-blockchain/ton/actions). ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 smartcontract @@ -22,7 +21,6 @@ found [here](https://github.com/ton-blockchain/ton/actions). ## Jitpack [![JitPack][jitpack-svg]][jitpack] ```xml - jitpack.io @@ -32,7 +30,6 @@ found [here](https://github.com/ton-blockchain/ton/actions). ``` ```xml - io.github.neodix42 ton4j @@ -50,6 +47,8 @@ You can use each submodule individually. Click the module below to get more deta * [Mnemonic](mnemonic/README.md) - helpful methods for generating deterministic keys for TON blockchain. * [Emulator](emulator/README.md) - wrapper for using with external precompiled emulator shared library. * [Liteclient](liteclient/README.md) - wrapper for using with external precompiled lite-client binary. +* [Fift](fift/README.md) - wrapper for using with external precompiled fift binary. +* [Func](func/README.md) - wrapper for using with external precompiled func binary. * [TonConnect](tonconnect/README.md) - implementation of Ton Connect standard. * [Utils](utils/README.md) - create private and public keys, convert data, etc. diff --git a/address/README.md b/address/README.md index 9646ab91..253d7f92 100644 --- a/address/README.md +++ b/address/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 address diff --git a/bitstring/README.md b/bitstring/README.md index eaaf537f..a7a026ff 100644 --- a/bitstring/README.md +++ b/bitstring/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 bitstring @@ -14,7 +13,6 @@ ## Jitpack ```xml - io.github.neodix42.ton4j bitstring diff --git a/cell/README.md b/cell/README.md index e1cc7eff..7a8be6ba 100644 --- a/cell/README.md +++ b/cell/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 cell diff --git a/emulator/README.md b/emulator/README.md index c81951a5..17779fa7 100644 --- a/emulator/README.md +++ b/emulator/README.md @@ -5,7 +5,6 @@ Java Emulator wrapper uses JNA to access methods in native emulator shared libra ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 emulator @@ -23,7 +22,7 @@ Java Emulator wrapper uses JNA to access methods in native emulator shared libra ``` -## Simply usage +## Usage ```java Tonlib tonlib=Tonlib.builder().build(); // we need tonlib to get network config diff --git a/fift/.gitignore b/fift/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/fift/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/fift/README.md b/fift/README.md new file mode 100644 index 00000000..75b4500d --- /dev/null +++ b/fift/README.md @@ -0,0 +1,47 @@ +# Liteclient module + +Java Lite-client wrapper uses JNA to access methods in native lite-client binary. + +## Maven [![Maven Central][maven-central-svg]][maven-central] + +```xml + + io.github.neodix42 + fift + 0.5.5 + +``` + +## Jitpack + +```xml + + io.github.neodix42.ton4j + fift + 0.5.5 + +``` + +## Usage + +```java +URL resource = TestFiftRunner.class.getResource("/test.fift"); +File fiftFile = Paths.get(resource.toURI()).toFile(); +String absolutePath = fiftFile.getAbsolutePath(); + +FiftRunner fiftRunner = FiftRunner.builder().build(); + +String result = fiftRunner.run(fiftFile.getParent(), "-s", absolutePath); +log.info("output: {}", result); +``` + +More examples in [TestFiftRunner](../fift/src/test/java/org/ton/java/fift/TestFiftRunner.java) class. + + +[maven-central-svg]: https://img.shields.io/maven-central/v/io.github.neodix42/tonlib + +[maven-central]: https://mvnrepository.com/artifact/io.github.neodix42/tonlib + +[ton-svg]: https://img.shields.io/badge/Based%20on-TON-blue + +[ton]: https://ton.org \ No newline at end of file diff --git a/fift/pom.xml b/fift/pom.xml new file mode 100644 index 00000000..4a106b0e --- /dev/null +++ b/fift/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + io.github.neodix42 + top + 0.5.5 + + + fift + TON Java Fift wrapper + + Java wrapper for fift executable. + + https://github.com/neodiX42/ton4j + + + + GNU General Public License v3.0 + https://www.gnu.org/licenses/gpl-3.0.html + + + + + + neodiX + neodiX@ton.org + + + + + scm:git:git://github.com/neodiX42/ton4j.git + scm:git:ssh://github.com/neodiX42/ton4j.git + https://github.com/neodiX42/ton4j/tree/main + + + + 8 + 8 + UTF-8 + + + + + io.github.neodix42 + utils + ${project.parent.version} + compile + + + commons-codec + commons-codec + + + org.apache.commons + commons-lang3 + + + commons-io + commons-io + ${commons-io.version} + + + junit + junit + test + + + org.projectlombok + lombok + compile + + + ch.qos.logback + logback-classic + test + + + org.assertj + assertj-core + test + + + + \ No newline at end of file diff --git a/smartcontract/src/main/java/org/ton/java/smartcontract/Executor.java b/fift/src/main/java/org/ton/java/fift/Executor.java similarity index 97% rename from smartcontract/src/main/java/org/ton/java/smartcontract/Executor.java rename to fift/src/main/java/org/ton/java/fift/Executor.java index 96353a45..9ff0f9ea 100644 --- a/smartcontract/src/main/java/org/ton/java/smartcontract/Executor.java +++ b/fift/src/main/java/org/ton/java/fift/Executor.java @@ -1,4 +1,4 @@ -package org.ton.java.smartcontract; +package org.ton.java.fift; import lombok.extern.java.Log; import org.apache.commons.io.IOUtils; diff --git a/smartcontract/src/main/java/org/ton/java/smartcontract/FiftRunner.java b/fift/src/main/java/org/ton/java/fift/FiftRunner.java similarity index 99% rename from smartcontract/src/main/java/org/ton/java/smartcontract/FiftRunner.java rename to fift/src/main/java/org/ton/java/fift/FiftRunner.java index 15807333..8340ec48 100644 --- a/smartcontract/src/main/java/org/ton/java/smartcontract/FiftRunner.java +++ b/fift/src/main/java/org/ton/java/fift/FiftRunner.java @@ -1,4 +1,4 @@ -package org.ton.java.smartcontract; +package org.ton.java.fift; import jdk.nashorn.internal.ir.annotations.Ignore; import lombok.Builder; diff --git a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFiftRunner.java b/fift/src/test/java/org/ton/java/fift/TestFiftRunner.java similarity index 83% rename from smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFiftRunner.java rename to fift/src/test/java/org/ton/java/fift/TestFiftRunner.java index b9dba721..93fa6ea0 100644 --- a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFiftRunner.java +++ b/fift/src/test/java/org/ton/java/fift/TestFiftRunner.java @@ -1,10 +1,9 @@ -package org.ton.java.smartcontract.unittests; +package org.ton.java.fift; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.ton.java.smartcontract.FiftRunner; import java.io.File; import java.net.URISyntaxException; @@ -21,7 +20,7 @@ public class TestFiftRunner { @Test public void testFiftRunner() throws URISyntaxException { - URL resource = TestFiftRunner.class.getResource("/fift/test.fift"); + URL resource = TestFiftRunner.class.getResource("/test.fift"); File fiftFile = Paths.get(resource.toURI()).toFile(); String absolutePath = fiftFile.getAbsolutePath(); diff --git a/smartcontract/src/test/resources/fift/test.fift b/fift/src/test/resources/test.fift similarity index 100% rename from smartcontract/src/test/resources/fift/test.fift rename to fift/src/test/resources/test.fift diff --git a/func/.gitignore b/func/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/func/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/func/README.md b/func/README.md new file mode 100644 index 00000000..565a5367 --- /dev/null +++ b/func/README.md @@ -0,0 +1,47 @@ +# Liteclient module + +Java Lite-client wrapper uses JNA to access methods in native lite-client binary. + +## Maven [![Maven Central][maven-central-svg]][maven-central] + +```xml + + io.github.neodix42 + func + 0.5.5 + +``` + +## Jitpack + +```xml + + io.github.neodix42.ton4j + func + 0.5.5 + +``` + +## Usage + +```java +URL resource = TestFuncRunner.class.getResource("/test.fc"); +File funcFile = Paths.get(resource.toURI()).toFile(); +String absolutePath = funcFile.getAbsolutePath(); + +FuncRunner funcRunner = FuncRunner.builder().build(); + +String result = funcRunner.run(funcFile.getParent(), "-PA", absolutePath); +log.info("output: {}", result); +``` + +More examples in [TestFuncRunner](../func/src/test/java/org/ton/java/func/TestFuncRunner.java) class. + + +[maven-central-svg]: https://img.shields.io/maven-central/v/io.github.neodix42/tonlib + +[maven-central]: https://mvnrepository.com/artifact/io.github.neodix42/tonlib + +[ton-svg]: https://img.shields.io/badge/Based%20on-TON-blue + +[ton]: https://ton.org \ No newline at end of file diff --git a/func/pom.xml b/func/pom.xml new file mode 100644 index 00000000..c0ca5f24 --- /dev/null +++ b/func/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + io.github.neodix42 + top + 0.5.5 + + + func + TON Java Func wrapper + + Java wrapper for func executable. + + https://github.com/neodiX42/ton4j + + + + GNU General Public License v3.0 + https://www.gnu.org/licenses/gpl-3.0.html + + + + + + neodiX + neodiX@ton.org + + + + + scm:git:git://github.com/neodiX42/ton4j.git + scm:git:ssh://github.com/neodiX42/ton4j.git + https://github.com/neodiX42/ton4j/tree/main + + + + 8 + 8 + UTF-8 + + + + + io.github.neodix42 + utils + ${project.parent.version} + compile + + + commons-codec + commons-codec + + + org.apache.commons + commons-lang3 + + + commons-io + commons-io + ${commons-io.version} + + + junit + junit + test + + + org.projectlombok + lombok + compile + + + ch.qos.logback + logback-classic + test + + + org.assertj + assertj-core + test + + + \ No newline at end of file diff --git a/func/src/main/java/org/ton/java/func/Executor.java b/func/src/main/java/org/ton/java/func/Executor.java new file mode 100644 index 00000000..42f1d699 --- /dev/null +++ b/func/src/main/java/org/ton/java/func/Executor.java @@ -0,0 +1,53 @@ +package org.ton.java.func; + +import lombok.extern.java.Log; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.tuple.Pair; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.concurrent.TimeUnit; + +@Log +public class Executor { + + public static Pair execute(String pathToBinary, String workDir, String... command) { + + String[] withBinaryCommand = new String[]{pathToBinary}; + + withBinaryCommand = ArrayUtils.addAll(withBinaryCommand, command); + + try { + log.info("execute: " + String.join(" ", withBinaryCommand)); + + final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true); + + pb.directory(new File(workDir)); + Process p = pb.start(); + + p.waitFor(1, TimeUnit.SECONDS); + + String resultInput = IOUtils.toString(p.getInputStream(), Charset.defaultCharset()); + + p.getInputStream().close(); + p.getErrorStream().close(); + p.getOutputStream().close(); + if (p.exitValue() == 2 || p.exitValue() == 0) { + return Pair.of(p, resultInput); + } else { + log.info("exit value " + p.exitValue()); + log.info(resultInput); + throw new Exception("Error running " + withBinaryCommand); + } + + } catch (final IOException e) { + log.info(e.getMessage()); + return null; + } catch (Exception e) { + log.info(e.getMessage()); + throw new RuntimeException(e); + } + } +} diff --git a/smartcontract/src/main/java/org/ton/java/smartcontract/FuncRunner.java b/func/src/main/java/org/ton/java/func/FuncRunner.java similarity index 98% rename from smartcontract/src/main/java/org/ton/java/smartcontract/FuncRunner.java rename to func/src/main/java/org/ton/java/func/FuncRunner.java index da9629b2..f041beaa 100644 --- a/smartcontract/src/main/java/org/ton/java/smartcontract/FuncRunner.java +++ b/func/src/main/java/org/ton/java/func/FuncRunner.java @@ -1,4 +1,4 @@ -package org.ton.java.smartcontract; +package org.ton.java.func; import jdk.nashorn.internal.ir.annotations.Ignore; import lombok.Builder; diff --git a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFuncRunner.java b/func/src/test/java/org/ton/java/func/TestFuncRunner.java similarity index 83% rename from smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFuncRunner.java rename to func/src/test/java/org/ton/java/func/TestFuncRunner.java index 4b402ba0..fce4f073 100644 --- a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestFuncRunner.java +++ b/func/src/test/java/org/ton/java/func/TestFuncRunner.java @@ -1,10 +1,9 @@ -package org.ton.java.smartcontract.unittests; +package org.ton.java.func; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.ton.java.smartcontract.FuncRunner; import java.io.File; import java.net.URISyntaxException; @@ -20,7 +19,7 @@ public class TestFuncRunner { @Test public void testFuncRunner() throws URISyntaxException { - URL resource = TestFuncRunner.class.getResource("/func/test.fc"); + URL resource = TestFuncRunner.class.getResource("/test.fc"); File funcFile = Paths.get(resource.toURI()).toFile(); String absolutePath = funcFile.getAbsolutePath(); diff --git a/smartcontract/src/test/resources/func/stdlib.fc b/func/src/test/resources/stdlib.fc similarity index 100% rename from smartcontract/src/test/resources/func/stdlib.fc rename to func/src/test/resources/stdlib.fc diff --git a/smartcontract/src/test/resources/func/test.fc b/func/src/test/resources/test.fc similarity index 100% rename from smartcontract/src/test/resources/func/test.fc rename to func/src/test/resources/test.fc diff --git a/liteclient/README.md b/liteclient/README.md index 717ecff2..008e1e08 100644 --- a/liteclient/README.md +++ b/liteclient/README.md @@ -5,7 +5,6 @@ Java Lite-client wrapper uses JNA to access methods in native lite-client binary ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 lite-client @@ -16,7 +15,6 @@ Java Lite-client wrapper uses JNA to access methods in native lite-client binary ## Jitpack ```xml - io.github.neodix42.ton4j lite-client @@ -24,7 +22,7 @@ Java Lite-client wrapper uses JNA to access methods in native lite-client binary ``` -## Simply usage +## Usage ```java LiteClient liteClient=LiteClient.builder() diff --git a/mnemonic/README.md b/mnemonic/README.md index f74c948a..8dec9a64 100644 --- a/mnemonic/README.md +++ b/mnemonic/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 mnemonic @@ -14,7 +13,6 @@ ## Jitpack ```xml - io.github.neodix42.ton4j mnemonic diff --git a/pom.xml b/pom.xml index ecec5946..4953e673 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,8 @@ liteclient tweetnacl-java-8 tonconnect + fift + func diff --git a/smartcontract/README.md b/smartcontract/README.md index 671c4782..5dd8688e 100644 --- a/smartcontract/README.md +++ b/smartcontract/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 smartcontract @@ -14,7 +13,6 @@ ## Jitpack ```xml - io.github.neodix42.ton4j smartcontract diff --git a/smartcontract/pom.xml b/smartcontract/pom.xml index 988239b2..8f958a7a 100644 --- a/smartcontract/pom.xml +++ b/smartcontract/pom.xml @@ -56,6 +56,18 @@ ${project.parent.version} compile + + io.github.neodix42 + fift + ${project.parent.version} + compile + + + io.github.neodix42 + func + ${project.parent.version} + compile + io.github.neodix42 address diff --git a/smartcontract/src/main/java/org/ton/java/smartcontract/SmartContractCompiler.java b/smartcontract/src/main/java/org/ton/java/smartcontract/SmartContractCompiler.java index 6e1e2382..7de3164e 100644 --- a/smartcontract/src/main/java/org/ton/java/smartcontract/SmartContractCompiler.java +++ b/smartcontract/src/main/java/org/ton/java/smartcontract/SmartContractCompiler.java @@ -6,6 +6,8 @@ import lombok.extern.java.Log; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; +import org.ton.java.fift.FiftRunner; +import org.ton.java.func.FuncRunner; import org.ton.java.utils.Utils; import java.io.File; diff --git a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestSmartContractCompiler.java b/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestSmartContractCompiler.java index 97c93d5c..05321eac 100644 --- a/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestSmartContractCompiler.java +++ b/smartcontract/src/test/java/org/ton/java/smartcontract/unittests/TestSmartContractCompiler.java @@ -5,17 +5,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.ton.java.address.Address; -import org.ton.java.cell.Cell; import org.ton.java.cell.CellBuilder; import org.ton.java.smartcontract.GenericSmartContract; import org.ton.java.smartcontract.SmartContractCompiler; -import org.ton.java.smartcontract.TestFaucet; import org.ton.java.tonlib.Tonlib; import org.ton.java.utils.Utils; import java.io.IOException; -import java.math.BigInteger; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; @@ -77,17 +73,17 @@ public void testSmartContractCompiler() throws URISyntaxException, InterruptedEx log.info(" raw address: {}", rawAddress); log.info("pub-key {}", Utils.bytesToHex(smc.getKeyPair().getPublicKey())); log.info("prv-key {}", Utils.bytesToHex(smc.getKeyPair().getSecretKey())); - - BigInteger balance = TestFaucet.topUpContract(tonlib, Address.of(nonBounceableAddress), Utils.toNano(0.1)); - log.info("new wallet {} balance: {}", smc.getName(), Utils.formatNanoValue(balance)); - - Cell deployMessageBody = CellBuilder.beginCell() - .storeUint(42, 32) // wallet-id - .storeInt(-1, 32) // valid-until - .storeUint(0, 32) //seqno - .endCell(); - - smc.deploy(deployMessageBody); +// +// BigInteger balance = TestFaucet.topUpContract(tonlib, Address.of(nonBounceableAddress), Utils.toNano(0.1)); +// log.info("new wallet {} balance: {}", smc.getName(), Utils.formatNanoValue(balance)); +// +// Cell deployMessageBody = CellBuilder.beginCell() +// .storeUint(42, 32) // wallet-id +// .storeInt(-1, 32) // valid-until +// .storeUint(0, 32) //seqno +// .endCell(); +// +// smc.deploy(deployMessageBody); } @Test diff --git a/tonconnect/README.md b/tonconnect/README.md index 37b4882b..672cbe38 100644 --- a/tonconnect/README.md +++ b/tonconnect/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 tonconnect @@ -14,7 +13,6 @@ ## Jitpack ```xml - io.github.neodix42.ton4j tonconnect diff --git a/tonlib/README.md b/tonlib/README.md index 6b0d95a5..90a0e633 100644 --- a/tonlib/README.md +++ b/tonlib/README.md @@ -12,7 +12,6 @@ You can get the latest tonlib library by: ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 tonlib @@ -23,7 +22,6 @@ You can get the latest tonlib library by: ## Jitpack ```xml - io.github.neodix42.ton4j tonlib diff --git a/utils/README.md b/utils/README.md index 4d62aa7e..f61b8241 100644 --- a/utils/README.md +++ b/utils/README.md @@ -3,7 +3,6 @@ ## Maven [![Maven Central][maven-central-svg]][maven-central] ```xml - io.github.neodix42 utils @@ -14,7 +13,6 @@ ## Jitpack ```xml - io.github.neodix42.ton4j utils