mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
initial commit
This commit is contained in:
commit
c2da007f40
1610 changed files with 398047 additions and 0 deletions
1
example/android/test/ton/.gitignore
vendored
Normal file
1
example/android/test/ton/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
44
example/android/test/ton/build.gradle
Normal file
44
example/android/test/ton/build.gradle
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
jni.srcDirs = []
|
||||
jniLibs.srcDirs 'src/cpp/prebuilt'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
|
||||
}
|
||||
21
example/android/test/ton/proguard-rules.pro
vendored
Normal file
21
example/android/test/ton/proguard-rules.pro
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package drinkless.org.ton
|
||||
|
||||
import android.content.Context
|
||||
import android.support.test.InstrumentationRegistry
|
||||
import android.support.test.InstrumentationRegistry.getContext
|
||||
import android.support.test.filters.LargeTest
|
||||
import android.support.test.filters.SmallTest
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import drinkless.org.ton.Client
|
||||
import drinkless.org.ton.TonApi
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.resumeWithException
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import kotlinx.coroutines.*;
|
||||
|
||||
class ClientKotlin {
|
||||
val client = Client.create(null, null, null);
|
||||
suspend fun send(query: TonApi.Function) : TonApi.Object {
|
||||
return suspendCoroutine<TonApi.Object> { cont ->
|
||||
client.send(query, {
|
||||
cont.resume(it)
|
||||
},null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@SmallTest
|
||||
class TonTest {
|
||||
val config = """{
|
||||
"@type": "config.global",
|
||||
"liteclients": [
|
||||
{
|
||||
"@type": "liteclient.config.global",
|
||||
"ip": 1137658550,
|
||||
"port": 4924,
|
||||
"id": {
|
||||
"@type": "pub.ed25519",
|
||||
"key": "peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M="
|
||||
}
|
||||
}
|
||||
]
|
||||
}"""
|
||||
@Test
|
||||
fun createTestWallet() {
|
||||
val client = ClientKotlin()
|
||||
val dir = getContext().getExternalFilesDir(null).toString() + "/";
|
||||
runBlocking {
|
||||
client.send(TonApi.Init(TonApi.Options(config, dir)))
|
||||
val key = client.send(TonApi.CreateNewKey("local password".toByteArray(), "mnemonic password".toByteArray())) as TonApi.Key
|
||||
val walletAddress = client.send(TonApi.TestWalletGetAccountAddress(TonApi.TestWalletInitialAccountState(key.publicKey))) as TonApi.AccountAddress;
|
||||
val testGiverState = client.send(TonApi.TestGiverGetAccountState()) as TonApi.TestGiverAccountState
|
||||
|
||||
client.send(TonApi.TestGiverSendGrams(walletAddress, testGiverState.seqno, 6660000000)) as TonApi.Ok
|
||||
|
||||
while ((client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateUninited).accountState.balance <= 0L) {
|
||||
delay(1000L)
|
||||
}
|
||||
|
||||
val inputKey = TonApi.InputKey(key, "local password".toByteArray());
|
||||
client.send(TonApi.TestWalletInit(inputKey)) as TonApi.Ok
|
||||
|
||||
while (client.send(TonApi.GenericGetAccountState(walletAddress)) !is TonApi.GenericAccountStateTestWallet) {
|
||||
delay(1000L)
|
||||
}
|
||||
|
||||
val state = client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateTestWallet
|
||||
val balance = state.accountState.balance
|
||||
client.send(TonApi.GenericSendGrams(inputKey, walletAddress, walletAddress, 10)) as TonApi.Ok
|
||||
while ((client.send(TonApi.GenericGetAccountState(walletAddress)) as TonApi.GenericAccountStateTestWallet).accountState.balance == balance) {
|
||||
delay(1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
package drinkless.org.ton;
|
||||
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.util.Log;
|
||||
import drinkless.org.ton.Client;
|
||||
import drinkless.org.ton.TonApi;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getContext;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TonTestJava {
|
||||
class JavaClient {
|
||||
Client client = Client.create(null, null, null);
|
||||
|
||||
public Object send(TonApi.Function query) {
|
||||
Object[] result = new Object[1];
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
|
||||
class Callback implements Client.ResultHandler {
|
||||
Object[] result;
|
||||
CountDownLatch countDownLatch;
|
||||
|
||||
Callback(Object[] result, CountDownLatch countDownLatch) {
|
||||
this.result = result;
|
||||
this.countDownLatch = countDownLatch;
|
||||
}
|
||||
|
||||
public void onResult(TonApi.Object object) {
|
||||
if (object instanceof TonApi.Error) {
|
||||
appendLog(((TonApi.Error) object).message);
|
||||
} else {
|
||||
result[0] = object;
|
||||
}
|
||||
if (countDownLatch != null) {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.send(query, new Callback(result, countDownLatch) , null);
|
||||
if (countDownLatch != null) {
|
||||
try {
|
||||
countDownLatch.await();
|
||||
} catch (Throwable e) {
|
||||
appendLog(e.toString());
|
||||
}
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
}
|
||||
|
||||
String config =
|
||||
"{" +
|
||||
"\"@type\": \"config.global\"," +
|
||||
"\"liteclients\": [" +
|
||||
"{" +
|
||||
"\"@type\": \"liteclient.config.global\"," +
|
||||
"\"ip\": 1137658550," +
|
||||
"\"port\": 4924," +
|
||||
"\"id\": {" +
|
||||
"\"@type\": \"pub.ed25519\"," +
|
||||
"\"key\": \"peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M=\"" +
|
||||
"}" +
|
||||
"}" +
|
||||
"]" +
|
||||
"}";
|
||||
|
||||
private void appendLog(String log) {
|
||||
Log.w("XX", log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTestWallet() {
|
||||
appendLog("start...");
|
||||
|
||||
JavaClient client = new JavaClient();
|
||||
Object result = client.send(new TonApi.Init(new TonApi.Options(config, getContext().getExternalFilesDir(null) + "/")));
|
||||
if (!(result instanceof TonApi.Ok)) {
|
||||
appendLog("failed to set config");
|
||||
return;
|
||||
}
|
||||
appendLog("config set ok");
|
||||
TonApi.Key key = (TonApi.Key) client.send(new TonApi.CreateNewKey("local password".getBytes(), "mnemonic password".getBytes()));
|
||||
appendLog("got private key");
|
||||
TonApi.AccountAddress walletAddress = (TonApi.AccountAddress) client.send(new TonApi.TestWalletGetAccountAddress(new TonApi.TestWalletInitialAccountState(key.publicKey)));
|
||||
appendLog("got account address");
|
||||
appendLog("sending grams...");
|
||||
TonApi.TestGiverAccountState testGiverState = (TonApi.TestGiverAccountState) client.send(new TonApi.TestGiverGetAccountState());
|
||||
result = client.send(new TonApi.TestGiverSendGrams(walletAddress, testGiverState.seqno, 6660000000L));
|
||||
if (!(result instanceof TonApi.Ok)) {
|
||||
appendLog("failed to send grams");
|
||||
return;
|
||||
}
|
||||
appendLog("grams sent, getting balance");
|
||||
|
||||
while (true) {
|
||||
TonApi.GenericAccountStateUninited accountStateUninited = (TonApi.GenericAccountStateUninited) client.send(new TonApi.GenericGetAccountState(walletAddress));
|
||||
if (accountStateUninited == null || accountStateUninited.accountState.balance <= 0L) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Throwable e) {
|
||||
appendLog(e.toString());
|
||||
}
|
||||
} else {
|
||||
appendLog(String.format("balance = %d", accountStateUninited.accountState.balance));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TonApi.InputKey inputKey = new TonApi.InputKey(key, "local password".getBytes());
|
||||
result = client.send(new TonApi.TestWalletInit(inputKey));
|
||||
if (!(result instanceof TonApi.Ok)) {
|
||||
return;
|
||||
}
|
||||
appendLog("init test wallet ok, getting state...");
|
||||
|
||||
while (true) {
|
||||
TonApi.GenericAccountState accountState = (TonApi.GenericAccountState) client.send(new TonApi.GenericGetAccountState(walletAddress));
|
||||
if (!(accountState instanceof TonApi.GenericAccountStateTestWallet)) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Throwable e) {
|
||||
appendLog(e.toString());
|
||||
}
|
||||
} else {
|
||||
appendLog("got account state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
appendLog("sending grams...");
|
||||
TonApi.GenericAccountStateTestWallet state = (TonApi.GenericAccountStateTestWallet) client.send(new TonApi.GenericGetAccountState(walletAddress));
|
||||
long balance = state.accountState.balance;
|
||||
result = client.send(new TonApi.GenericSendGrams(inputKey, walletAddress, walletAddress, 10));
|
||||
if (!(result instanceof TonApi.Ok)) {
|
||||
return;
|
||||
}
|
||||
appendLog(String.format("grams sent, current balance %d, receving...", balance));
|
||||
|
||||
while (true) {
|
||||
TonApi.GenericAccountStateTestWallet wallet = (TonApi.GenericAccountStateTestWallet) client.send(new TonApi.GenericGetAccountState(walletAddress));
|
||||
if (wallet == null || wallet.accountState.balance == balance) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Throwable e) {
|
||||
appendLog(e.toString());
|
||||
}
|
||||
} else {
|
||||
appendLog(String.format("grams received, balance = %d", balance));
|
||||
break;
|
||||
}
|
||||
}
|
||||
appendLog("OK");
|
||||
|
||||
}
|
||||
}
|
||||
4
example/android/test/ton/src/main/AndroidManifest.xml
Normal file
4
example/android/test/ton/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="drinkless.org.ton">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,290 @@
|
|||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
package drinkless.org.ton;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* Main class for interaction with the TDLib.
|
||||
*/
|
||||
public final class Client implements Runnable {
|
||||
static {
|
||||
System.loadLibrary("native-lib");
|
||||
}
|
||||
/**
|
||||
* Interface for handler for results of queries to TDLib and incoming updates from TDLib.
|
||||
*/
|
||||
public interface ResultHandler {
|
||||
/**
|
||||
* Callback called on result of query to TDLib or incoming update from TDLib.
|
||||
*
|
||||
* @param object Result of query or update of type TonApi.Update about new events.
|
||||
*/
|
||||
void onResult(TonApi.Object object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for handler of exceptions thrown while invoking ResultHandler.
|
||||
* By default, all such exceptions are ignored.
|
||||
* All exceptions thrown from ExceptionHandler are ignored.
|
||||
*/
|
||||
public interface ExceptionHandler {
|
||||
/**
|
||||
* Callback called on exceptions thrown while invoking ResultHandler.
|
||||
*
|
||||
* @param e Exception thrown by ResultHandler.
|
||||
*/
|
||||
void onException(Throwable e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the TDLib.
|
||||
*
|
||||
* @param query Object representing a query to the TDLib.
|
||||
* @param resultHandler Result handler with onResult method which will be called with result
|
||||
* of the query or with TonApi.Error as parameter. If it is null, nothing
|
||||
* will be called.
|
||||
* @param exceptionHandler Exception handler with onException method which will be called on
|
||||
* exception thrown from resultHandler. If it is null, then
|
||||
* defaultExceptionHandler will be called.
|
||||
* @throws NullPointerException if query is null.
|
||||
*/
|
||||
public void send(TonApi.Function query, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
|
||||
if (query == null) {
|
||||
throw new NullPointerException("query is null");
|
||||
}
|
||||
|
||||
readLock.lock();
|
||||
try {
|
||||
if (isClientDestroyed) {
|
||||
if (resultHandler != null) {
|
||||
handleResult(new TonApi.Error(500, "Client is closed"), resultHandler, exceptionHandler);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
long queryId = currentQueryId.incrementAndGet();
|
||||
handlers.put(queryId, new Handler(resultHandler, exceptionHandler));
|
||||
nativeClientSend(nativeClientId, queryId, query);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the TDLib with an empty ExceptionHandler.
|
||||
*
|
||||
* @param query Object representing a query to the TDLib.
|
||||
* @param resultHandler Result handler with onResult method which will be called with result
|
||||
* of the query or with TonApi.Error as parameter. If it is null, then
|
||||
* defaultExceptionHandler will be called.
|
||||
* @throws NullPointerException if query is null.
|
||||
*/
|
||||
public void send(TonApi.Function query, ResultHandler resultHandler) {
|
||||
send(query, resultHandler, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously.
|
||||
*
|
||||
* @param query Object representing a query to the TDLib.
|
||||
* @return request result.
|
||||
* @throws NullPointerException if query is null.
|
||||
*/
|
||||
public static TonApi.Object execute(TonApi.Function query) {
|
||||
if (query == null) {
|
||||
throw new NullPointerException("query is null");
|
||||
}
|
||||
return nativeClientExecute(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces handler for incoming updates from the TDLib.
|
||||
*
|
||||
* @param updatesHandler Handler with onResult method which will be called for every incoming
|
||||
* update from the TDLib.
|
||||
* @param exceptionHandler Exception handler with onException method which will be called on
|
||||
* exception thrown from updatesHandler, if it is null, defaultExceptionHandler will be invoked.
|
||||
*/
|
||||
public void setUpdatesHandler(ResultHandler updatesHandler, ExceptionHandler exceptionHandler) {
|
||||
handlers.put(0L, new Handler(updatesHandler, exceptionHandler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces handler for incoming updates from the TDLib. Sets empty ExceptionHandler.
|
||||
*
|
||||
* @param updatesHandler Handler with onResult method which will be called for every incoming
|
||||
* update from the TDLib.
|
||||
*/
|
||||
public void setUpdatesHandler(ResultHandler updatesHandler) {
|
||||
setUpdatesHandler(updatesHandler, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces default exception handler to be invoked on exceptions thrown from updatesHandler and all other ResultHandler.
|
||||
*
|
||||
* @param defaultExceptionHandler Default exception handler. If null Exceptions are ignored.
|
||||
*/
|
||||
public void setDefaultExceptionHandler(Client.ExceptionHandler defaultExceptionHandler) {
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden method from Runnable, do not call it directly.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (!stopFlag) {
|
||||
receiveQueries(300.0 /*seconds*/);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Client.
|
||||
*
|
||||
* @param updatesHandler Handler for incoming updates.
|
||||
* @param updatesExceptionHandler Handler for exceptions thrown from updatesHandler. If it is null, exceptions will be iggnored.
|
||||
* @param defaultExceptionHandler Default handler for exceptions thrown from all ResultHandler. If it is null, exceptions will be iggnored.
|
||||
* @return created Client
|
||||
*/
|
||||
public static Client create(ResultHandler updatesHandler, ExceptionHandler updatesExceptionHandler, ExceptionHandler defaultExceptionHandler) {
|
||||
Client client = new Client(updatesHandler, updatesExceptionHandler, defaultExceptionHandler);
|
||||
new Thread(client, "TDLib thread").start();
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes Client.
|
||||
*/
|
||||
public void close() {
|
||||
writeLock.lock();
|
||||
try {
|
||||
if (isClientDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (!stopFlag) {
|
||||
//send(new TonApi.Close(), null);
|
||||
}
|
||||
isClientDestroyed = true;
|
||||
while (!stopFlag) {
|
||||
Thread.yield();
|
||||
}
|
||||
while (handlers.size() != 1) {
|
||||
receiveQueries(300.0);
|
||||
}
|
||||
destroyNativeClient(nativeClientId);
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
private final Lock readLock = readWriteLock.readLock();
|
||||
private final Lock writeLock = readWriteLock.writeLock();
|
||||
|
||||
private volatile boolean stopFlag = false;
|
||||
private volatile boolean isClientDestroyed = false;
|
||||
private final long nativeClientId;
|
||||
|
||||
private final ConcurrentHashMap<Long, Handler> handlers = new ConcurrentHashMap<Long, Handler>();
|
||||
private final AtomicLong currentQueryId = new AtomicLong();
|
||||
|
||||
private volatile ExceptionHandler defaultExceptionHandler = null;
|
||||
|
||||
private static final int MAX_EVENTS = 1000;
|
||||
private final long[] eventIds = new long[MAX_EVENTS];
|
||||
private final TonApi.Object[] events = new TonApi.Object[MAX_EVENTS];
|
||||
|
||||
private static class Handler {
|
||||
final ResultHandler resultHandler;
|
||||
final ExceptionHandler exceptionHandler;
|
||||
|
||||
Handler(ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
|
||||
this.resultHandler = resultHandler;
|
||||
this.exceptionHandler = exceptionHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private Client(ResultHandler updatesHandler, ExceptionHandler updateExceptionHandler, ExceptionHandler defaultExceptionHandler) {
|
||||
nativeClientId = createNativeClient();
|
||||
handlers.put(0L, new Handler(updatesHandler, updateExceptionHandler));
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
close();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
private void processResult(long id, TonApi.Object object) {
|
||||
/*
|
||||
if (object instanceof TonApi.UpdateAuthorizationState) {
|
||||
if (((TonApi.UpdateAuthorizationState) object).authorizationState instanceof TonApi.AuthorizationStateClosed) {
|
||||
stopFlag = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
Handler handler;
|
||||
if (id == 0) {
|
||||
// update handler stays forever
|
||||
handler = handlers.get(id);
|
||||
} else {
|
||||
handler = handlers.remove(id);
|
||||
}
|
||||
if (handler == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleResult(object, handler.resultHandler, handler.exceptionHandler);
|
||||
}
|
||||
|
||||
private void handleResult(TonApi.Object object, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
|
||||
if (resultHandler == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
resultHandler.onResult(object);
|
||||
} catch (Throwable cause) {
|
||||
if (exceptionHandler == null) {
|
||||
exceptionHandler = defaultExceptionHandler;
|
||||
}
|
||||
if (exceptionHandler != null) {
|
||||
try {
|
||||
exceptionHandler.onException(cause);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveQueries(double timeout) {
|
||||
int resultN = nativeClientReceive(nativeClientId, eventIds, events, timeout);
|
||||
for (int i = 0; i < resultN; i++) {
|
||||
processResult(eventIds[i], events[i]);
|
||||
events[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static native long createNativeClient();
|
||||
|
||||
private static native void nativeClientSend(long nativeClientId, long eventId, TonApi.Function function);
|
||||
|
||||
private static native int nativeClientReceive(long nativeClientId, long[] eventIds, TonApi.Object[] events, double timeout);
|
||||
|
||||
private static native TonApi.Object nativeClientExecute(TonApi.Function function);
|
||||
|
||||
private static native void destroyNativeClient(long nativeClientId);
|
||||
}
|
||||
3
example/android/test/ton/src/main/res/values/strings.xml
Normal file
3
example/android/test/ton/src/main/res/values/strings.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">tonlib</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package drinkless.org.tonlib;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue