GithubHelp home page GithubHelp logo

everscale-client-java's Introduction

Java library for Everscale Client

SDK version

The Library is a binding for Everscale Client written in Java that act as a bridge between Everscale Client and a Java application. The library includes original EVER-SDK Library with incorporated support of Java Native Interface (JNI) which allows direct access to Everscale Client from Java Virtual Machine.

Code Generation

The most of the library source code is generated from api.json by script ./binding/gen-java.js. To use the script you must have Node.js installed.

Prerequisites

  • Use the following command to install Java JDK:
    $ sudo apt-get install default-jdk
  • Use the following command to install maven:
    $ sudo apt-get install maven
    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Build

  • To build, enter the following command:
    $ build.sh
  • To generate Java API Documentation, use:
    $ mvn javadoc:javadoc
  • You can find the generated documentation under ${Project_basedir}/binding/target/site/apidocs
  • To run tests, enter the following command:
    $ mvn test
  • If succeed, you can find "everscale-client-binding-1.44.2-jar-with-dependencies.jar" file located under ${Project_basedir}/binding/target

Clean

  • To clean the generated files, enter the following command:
    $ mvn clean

How to use the library

Once the build succeed you will have the library installed to your local maven repository. To use it in your projects, add the dependency to pom.xml

    ...
    <dependency>
      <groupId>com.radiance.tonclient</groupId>
      <artifactId>everscale-client-binding</artifactId>
      <version>1.44.2</version>
    </dependency>
    ...

Example of usage:

    // At the beginning TON Context must be created
    // Configuration parameters are passed as a json string
    TONContext context = TONContext.create("{\"network\":{\"server_address\":\"https://net.ton.dev/graphql\"}}");

    /* Alternatively TON context can be configured via ClientConfig object
    TONContext context = TONContext.create(new ClientConfig(
        new NetworkConfig("https://net.ton.dev/graphql")
    ));
    */

    try {
        // TON methods can be invoked via context directly ...
        String randomBytes = context
            .requestJSON("crypto.generate_random_bytes", "{\"length\":12}")
            .get()
            .findValue("bytes").asText();
        System.out.println("Random bytes: '" + randomBytes + "'");

        // ... or using convenience classes
        Crypto crypto = new Crypto(context);
        randomBytes = crypto.generateRandomBytes(12).get();
        System.out.println("Random bytes: '" + randomBytes + "'");
    } finally {
        // context should be destroyed after using
        context.destroy();
    }

See also

everscale-client-java's People

Contributors

igor-vasilev avatar samorodkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

everscale-client-java's Issues

centos7 error

v1.19.0 reports an error in the centos7 environment.
v1.14.0 is normal in centos7.
May I ask what's going on?

unusable on linux

compile on ubuntu:18.04

TONContext initialization run fail

image
image
image

md5sum result
eec20d00ef84d348eb0ac38a8edb236c wallet-main-release/WEB-INF/classes/libton_client_jni.so

but i can run on macos succfully

failed to select a version for the requirement `hmac = "^0.4"`

E:\Coins\TON\ton-client-java\jni>cargo build --release
Updating crates.io index
Updating git repository https://github.com/tonlabs/bip39-rs.git
Updating git repository https://github.com/tonlabs/lockfree.git
Updating git repository https://github.com/tonlabs/sodalite.git
Updating git submodule https://github.com/jmesmon/rust-ci-helper
error: failed to select a version for the requirement hmac = "^0.4"
candidate versions found which didn't match: 0.11.0, 0.10.1, 0.10.0, ...
location searched: crates.io index
required by package hmac-drbg v0.1.0
... which is depended on by libsecp256k1 v0.2.2
... which is depended on by ton_client v1.6.2 (E:\Coins\TON\ton-client-java\target\TON-SDK\ton_client)
... which is depended on by ton-client-jni v1.23.0 (E:\Coins\TON\ton-client-java\jni)

how to solve this problem?

Oderby to json is error

version : 1.44.2

`2024-04-24 19:15:13.124 INFO 48914 --- [ main] com.radiance.tonclient.TONContext : => 1 net.query_collection {"collection":"blocks","result":"id workchain_id shard seq_no","order":[{"path":"seq_no","direction":"DESC"}],"limit":1}

2024-04-24 19:15:14.670 INFO 48914 --- [ Thread-10] com.radiance.tonclient.TONContext : <= 1 {"result":[{"id":"8712979ca122a06d77474b1256d4b9bf104ac9590c2182cd7ca06dfdd1a53f9b","workchain_id":0,"shard":"7000000000000000","seq_no":7039626}]} type=0 finished=true

2024-04-24 19:15:14.677 INFO 48914 --- [ main] com.radiance.tonclient.TONContext : => 2 net.query_collection {"collection":"blocks","result":"id workchain_id shard seq_no","order":[{"path":"seq_no","direction":1}],"limit":1}

2024-04-24 19:15:14.678 INFO 48914 --- [ Thread-11] com.radiance.tonclient.TONContext : <= 2 {"code":23,"message":"Invalid parameters: expected value at line 1 column 102\nparams: {"collection":"blocks","result":"id workchain_id shard seq_no","order":[{"path":"seq_no","direction":1}],"limit":1}","data":{"core_version":"1.44.2"}} type=1 finished=true`

when call this code

Object[] completableFuture1 = net.queryCollection( "blocks", null, "id workchain_id shard seq_no", new Net.OrderBy[]{new Net.OrderBy("seq_no", Net.SortDirection.DESC)}, 1).get();

OrderBy class to json should be
"order":[{"path":"seq_no","direction":"DESC"}]
not
"order":[{"path":"seq_no","direction":1}],

Wrong dependency in README.md

Please fix artifactId in README.md. Now it points to ton-client-binding, which is wrong:

    ...
    <dependency>
      <groupId>com.radiance.tonclient</groupId>
      <artifactId>ton-client-binding</artifactId>
      <version>1.17.0</version>
    </dependency>
    ...

Binding lib is unusable in deployment packaging

Hello!

Did you achieve any working examples of this lib usage?
It works in unpackaged build runs or in tests, but it can't be used in executable JAR or WAR package (made via Spring Boot, for example).

The error looks like this:

28-Jun-2021 04:51:42.170 INFO [https-jsse-nio-8443-exec-6] com.radiance.tonclient.TONContext.requestCallback => 1 net.query_collection {"collection":"accounts","filter":{"id":{"in":["0:f4611223eabcfc4dcdcfbe504da6a6c539405a509cfa552f84e783c56e4b2b9b","0:4989360a2b2a9443864f2e0f1ae49283ef67726161047942227aa6d0f1b1805c","0:035e31e05c6c1582c93d8c0e33c09ccb6b75aa160f10b641e7801b3dee8b0505","0:d80011d1ec9559392113a99319982935a37fa5b7cccae7218751232551ea6896"] },"acc_type":{"eq":1}},"result":"id boc"}
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: JavaException', src/lib.rs:82:73
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Exception in thread "Thread-6" java.lang.NoClassDefFoundError: com/radiance/tonclient/TONContext
Caused by: java.lang.ClassNotFoundException: com.radiance.tonclient.TONContext
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "PoisonError { inner: .. }"', src/lib.rs:36:40
fatal runtime error: failed to initiate panic, error 5

Variants I've tried:

  • Package: WAR, JAR;
  • OS: Linux AMD64 (Ubuntu 20), Windows 64 (Server 2019)
  • JDK 8, JDK 16
  • Maven, Gradle builds (just in case)

Lib successfully creates context (because answer is synchronous) and falls when it comes to async callback handling here:
https://github.com/radianceteam/ton-client-java/blob/main/jni/src/lib.rs#L82

Reasons for this are explained here I think:
https://developer.android.com/training/articles/perf-jni.html#faq_FindClass

(You can get into trouble if you create a thread yourself (perhaps by calling pthread_create and then attaching it with AttachCurrentThread). Now there are no stack frames from your application. If you call FindClass from this thread, the JavaVM will start in the "system" class loader instead of the one associated with your application, so attempts to find app-specific classes will fail.)

Can you fix this, please? I have not enough experience with Rust to make correct changes and do a PR with fix.
In current state, lib is hardly usable to any server or mobile apps development.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.