move statusgo to StatusModule

remove StatusService
few minor performance fixes in RN app
This commit is contained in:
Roman Volosovskyi 2017-01-22 17:05:15 +02:00 committed by Roman Volosovskyi
parent bf582c6091
commit 58fd0c1134
15 changed files with 242 additions and 658 deletions

View File

@ -27,7 +27,6 @@
<service
android:name=".module.StatusService"
android:enabled="true"
android:process=":status_service"
android:exported="true"/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
</application>

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Wed Jul 20 10:42:35 EEST 2016
#Sun Jan 22 10:12:39 EET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

View File

@ -84,6 +84,7 @@ var TopLevel = {
"isMatches" : function () {},
"isMobile" : function () {},
"isSyncing" : function () {},
"getSyncing" : function () {},
"isValid" : function () {},
"Item" : function () {},
"JSON" : function () {},

View File

@ -6,11 +6,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.*;
import android.util.Log;
import java.util.ArrayList;
public class ServiceConnector {
private static final String TAG = "ServiceConnector";
/** Context of the activity from which this connector was launched */
private Context context;
@ -136,4 +138,16 @@ public class ServiceConnector {
handlers.remove(handler);
}
public void sendMessage() {
Message msg = Message.obtain(null, 0, 0, 0);
msg.replyTo = clientMessenger;
try {
Log.d(TAG, "Sending message to service: ");
serviceMessenger.send(msg);
} catch (RemoteException e) {
Log.e(TAG, "Exception sending message(" + msg.toString() + ") to service: ", e);
}
}
}

View File

@ -1,156 +0,0 @@
package im.status.ethereum.module;
import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
public class StatusConnector extends ServiceConnector {
private static final String TAG = "StatusConnector";
public static final String CALLBACK_IDENTIFIER = "callbackIdentifier";
public StatusConnector(Context context, Class serviceClass) {
super(context, serviceClass);
}
public void startNode(String callbackIdentifier) {
if (checkBound()) {
sendMessage(callbackIdentifier, StatusMessages.MSG_START_NODE, null);
}
}
public void stopNode(String callbackIdentifier) {
if (checkBound()) {
sendMessage(callbackIdentifier, StatusMessages.MSG_STOP_NODE, null);
}
}
public void startRPC() {
if (checkBound()) {
sendMessage(null, StatusMessages.MSG_START_RPC, null);
}
}
public void stopRPC() {
if (checkBound()) {
sendMessage(null, StatusMessages.MSG_STOP_RPC, null);
}
}
public void login(String callbackIdentifier, String address, String password) {
if (checkBound()) {
Bundle data = new Bundle();
data.putString("address", address);
data.putString("password", password);
sendMessage(callbackIdentifier, StatusMessages.MSG_LOGIN, data);
}
}
public void createAccount(String callbackIdentifier, String password) {
if (checkBound()) {
Bundle data = new Bundle();
data.putString("password", password);
sendMessage(callbackIdentifier, StatusMessages.MSG_CREATE_ACCOUNT, data);
}
}
public void recoverAccount(String callbackIdentifier, String passphrase, String password) {
if (checkBound()) {
Bundle data = new Bundle();
data.putString("passphrase", passphrase);
data.putString("password", password);
sendMessage(callbackIdentifier, StatusMessages.MSG_RECOVER_ACCOUNT, data);
}
}
public void completeTransaction(String callbackIdentifier, String hash, String password){
if (checkBound()) {
Bundle data = new Bundle();
data.putString("hash", hash);
data.putString("password", password);
sendMessage(callbackIdentifier, StatusMessages.MSG_COMPLETE_TRANSACTION, data);
}
}
public void discardTransaction(String id){
if (checkBound()) {
Bundle data = new Bundle();
data.putString("id", id);
sendMessage(null, StatusMessages.MSG_DISCARD_TRANSACTION, data);
}
}
public void initJail(String callbackIdentifier, String js){
if (checkBound()) {
Bundle data = new Bundle();
data.putString("js", js);
sendMessage(callbackIdentifier, StatusMessages.MSG_JAIL_INIT, data);
}
}
public void parseJail(String callbackIdentifier, String chatId, String js){
if (checkBound()) {
Bundle data = new Bundle();
data.putString("chatId", chatId);
data.putString("js", js);
sendMessage(callbackIdentifier, StatusMessages.MSG_JAIL_PARSE, data);
}
}
public void callJail(String callbackIdentifier, String chatId, String path, String params){
if (checkBound()) {
Bundle data = new Bundle();
data.putString("chatId", chatId);
data.putString("path", path);
data.putString("params", params);
sendMessage(callbackIdentifier, StatusMessages.MSG_JAIL_CALL, data);
}
}
private boolean checkBound() {
if (!isBound) {
Log.d(TAG, "StatusConnector not bound!");
return false;
}
return true;
}
private Message createMessage(String callbackIdentifier, int idMessage, Bundle data) {
Log.d(TAG, "Client messenger: " + clientMessenger.toString());
Message msg = Message.obtain(null, idMessage, 0, 0);
msg.replyTo = clientMessenger;
if (data == null) {
data = new Bundle();
}
data.putString(CALLBACK_IDENTIFIER, callbackIdentifier);
msg.setData(data);
return msg;
}
private void sendMessage(String callbackIdentifier, int idMessage, Bundle data) {
Message msg = createMessage(callbackIdentifier, idMessage, data);
try {
serviceMessenger.send(msg);
} catch (RemoteException e) {
Log.e(TAG, "Exception sending message(" + msg.toString() + ") to service: ", e);
}
}
}

View File

@ -1,72 +0,0 @@
package im.status.ethereum.module;
public class StatusMessages {
/**
* Start the node
*/
static final int MSG_START_NODE = 1;
/**
* Stop the node
*/
static final int MSG_STOP_NODE = 2;
/**
* Unlock an account
*/
static final int MSG_LOGIN = 3;
/**
* Create an account
*/
static final int MSG_CREATE_ACCOUNT = 4;
/**
* Create an account
*/
static final int MSG_RECOVER_ACCOUNT = 5;
/**
* Account complete transaction event
*/
static final int MSG_COMPLETE_TRANSACTION = 6;
/**
* Geth event
*/
public static final int MSG_GETH_EVENT = 7;
/**
* Initialize jail
*/
public static final int MSG_JAIL_INIT = 8;
/**
* Parse js in jail
*/
public static final int MSG_JAIL_PARSE = 9;
/**
* Parse js in jail
*/
public static final int MSG_JAIL_CALL = 10;
/**
* Account discard transaction event
*/
public static final int MSG_DISCARD_TRANSACTION = 11;
/**
* Start RPC server
*/
static final int MSG_START_RPC = 12;
/**
* Stop RPC server
*/
static final int MSG_STOP_RPC = 13;
}

View File

@ -1,11 +1,9 @@
package im.status.ethereum.module;
import android.app.Activity;
import android.os.*;
import android.os.Process;
import android.view.WindowManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@ -13,20 +11,29 @@ import android.webkit.WebStorage;
import com.facebook.react.bridge.*;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.github.status_im.status_go.cmd.Statusgo;
import java.io.File;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler {
private static final String TAG = "StatusModule";
private StatusConnector status = null;
private HashMap<String, Callback> callbacks = new HashMap<>();
private static StatusModule module;
private ServiceConnector status = null;
private ExecutorService executor = null;
StatusModule(ReactApplicationContext reactContext) {
super(reactContext);
if (executor == null) {
executor = Executors.newCachedThreadPool();
}
reactContext.addLifecycleEventListener(this);
}
@ -37,84 +44,34 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@Override
public void onHostResume() { // Actvity `onResume`
module = this;
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
Log.d(TAG, "On host Activity doesn't exist");
return;
}
if (status == null) {
status = new StatusConnector(currentActivity, StatusService.class);
status = new ServiceConnector(currentActivity, StatusService.class);
status.registerHandler(this);
}
status.bindService();
WritableMap params = Arguments.createMap();
Log.d(TAG, "Send module.initialized event");
params.putString("jsonEvent", "{\"type\":\"module.initialized\"}");
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("gethEvent", params);
signalEvent("{\"type\":\"module.initialized\"}");
}
@Override
public void onHostPause() { // Actvity `onPause`
public void onHostPause() {
if (status != null) {
status.unbindService();
}
}
@Override
public void onHostDestroy() { // Actvity `onDestroy`
if (status != null) {
status.stopNode(null);
}
}
public void onHostDestroy() {
@Override
public void onConnectorConnected() {
}
@Override
public void onConnectorDisconnected() {
}
@Override
public boolean handleMessage(Message message) {
Log.d(TAG, "Received message: " + message.toString());
boolean isClaimed = true;
Bundle bundle = message.getData();
String callbackIdentifier = bundle.getString(StatusConnector.CALLBACK_IDENTIFIER);
String data = bundle.getString("data");
Callback callback = callbacks.remove(callbackIdentifier);
switch (message.what) {
case StatusMessages.MSG_START_NODE:
case StatusMessages.MSG_STOP_NODE:
case StatusMessages.MSG_LOGIN:
case StatusMessages.MSG_CREATE_ACCOUNT:
case StatusMessages.MSG_RECOVER_ACCOUNT:
case StatusMessages.MSG_COMPLETE_TRANSACTION:
case StatusMessages.MSG_JAIL_INIT:
case StatusMessages.MSG_JAIL_PARSE:
case StatusMessages.MSG_JAIL_CALL:
if (callback == null) {
Log.d(TAG, "Could not find callback: " + callbackIdentifier);
} else {
callback.invoke(data);
}
break;
case StatusMessages.MSG_GETH_EVENT:
String event = bundle.getString("event");
WritableMap params = Arguments.createMap();
params.putString("jsonEvent", event);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params);
break;
default:
isClaimed = false;
}
return isClaimed;
}
private boolean checkAvailability() {
@ -125,28 +82,58 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
return false;
}
if (status == null) {
Log.d(TAG, "Status connector is null");
return false;
}
return true;
}
// Geth
private void signalEvent(String jsonEvent) {
Log.d(TAG, "Signal event: " + jsonEvent);
WritableMap params = Arguments.createMap();
params.putString("jsonEvent", jsonEvent);
this.getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params);
}
private void doStartNode() {
Activity currentActivity = getCurrentActivity();
File extStore = Environment.getExternalStorageDirectory();
String dataFolder = extStore.exists() ?
extStore.getAbsolutePath() + "/ethereum" :
currentActivity.getApplicationInfo().dataDir + "/ethereum";
Log.d(TAG, "Starting Geth node in folder: " + dataFolder);
try {
final File newFile = new File(dataFolder);
// todo handle error?
newFile.mkdir();
} catch (Exception e) {
Log.e(TAG, "error making folder: " + dataFolder, e);
}
Statusgo.StartNode(dataFolder);
Log.d(TAG, "Geth node started");
}
@ReactMethod
public void startNode(Callback callback) {
Log.d(TAG, "startNode");
status.sendMessage();
if (!checkAvailability()) {
callback.invoke(false);
return;
}
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
Thread thread = new Thread() {
@Override
public void run() {
doStartNode();
}
};
status.startNode(callbackIdentifier);
thread.start();
callback.invoke(false);
}
@ReactMethod
@ -157,7 +144,14 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
return;
}
status.startRPC();
Thread thread = new Thread() {
@Override
public void run() {
Statusgo.StartNodeRPCServer();
}
};
thread.start();
}
@ReactMethod
@ -168,49 +162,72 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
return;
}
status.stopRPC();
Thread thread = new Thread() {
@Override
public void run() {
Statusgo.StopNodeRPCServer();
}
};
thread.start();
}
@ReactMethod
public void login(String address, String password, Callback callback) {
public void login(final String address, final String password, final Callback callback) {
Log.d(TAG, "login");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Thread thread = new Thread() {
@Override
public void run() {
String result = Statusgo.Login(address, password);
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
callback.invoke(result);
}
};
status.login(callbackIdentifier, address, password);
thread.start();
}
@ReactMethod
public void createAccount(String password, Callback callback) {
public void createAccount(final String password, final Callback callback) {
Log.d(TAG, "createAccount");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
Thread thread = new Thread() {
@Override
public void run() {
String res = Statusgo.CreateAccount(password);
status.createAccount(callbackIdentifier, password);
callback.invoke(res);
}
};
thread.start();
}
@ReactMethod
public void recoverAccount(String passphrase, String password, Callback callback) {
public void recoverAccount(final String passphrase, final String password, final Callback callback) {
Log.d(TAG, "recoverAccount");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Thread thread = new Thread() {
@Override
public void run() {
String res = Statusgo.RecoverAccount(password, passphrase);
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
callback.invoke(res);
}
};
status.recoverAccount(callbackIdentifier, passphrase, password);
thread.start();
}
private String createIdentifier() {
@ -218,74 +235,103 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
@ReactMethod
public void completeTransaction(String hash, String password, Callback callback) {
public void completeTransaction(final String hash, final String password, final Callback callback) {
Log.d(TAG, "completeTransaction");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Log.d(TAG, "Complete transaction: " + hash);
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
Thread thread = new Thread() {
@Override
public void run() {
String res = Statusgo.CompleteTransaction(hash, password);
status.completeTransaction(callbackIdentifier, hash, password);
callback.invoke(res);
}
};
thread.start();
}
@ReactMethod
public void discardTransaction(String id) {
public void discardTransaction(final String id) {
Log.d(TAG, "discardTransaction");
if (!checkAvailability()) {
return;
}
Log.d(TAG, "Discard transaction: " + id);
status.discardTransaction(id);
Thread thread = new Thread() {
@Override
public void run() {
Statusgo.DiscardTransaction(id);
}
};
thread.start();
}
// Jail
@ReactMethod
public void initJail(String js, Callback callback) {
public void initJail(final String js, final Callback callback) {
Log.d(TAG, "initJail");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
Thread thread = new Thread() {
@Override
public void run() {
Statusgo.InitJail(js);
status.initJail(callbackIdentifier, js);
callback.invoke(false);
}
};
thread.start();
}
@ReactMethod
public void parseJail(String chatId, String js, Callback callback) {
public void parseJail(final String chatId, final String js, final Callback callback) {
Log.d(TAG, "parseJail");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
Thread thread = new Thread() {
@Override
public void run() {
String res = Statusgo.Parse(chatId, js);
Log.d(TAG, "endParseJail");
callback.invoke(res);
}
};
status.parseJail(callbackIdentifier, chatId, js);
thread.start();
}
@ReactMethod
public void callJail(String chatId, String path, String params, Callback callback) {
public void callJail(final String chatId, final String path, final String params, final Callback callback) {
Log.d(TAG, "callJail");
Log.d(TAG, path);
if (!checkAvailability()) {
callback.invoke(false);
return;
}
String callbackIdentifier = createIdentifier();
callbacks.put(callbackIdentifier, callback);
status.callJail(callbackIdentifier, chatId, path, params);
executor.execute(new Runnable() {
@Override
public void run() {
Log.d(TAG, "startCallJail");
String res = Statusgo.Call(chatId, path, params);
Log.d(TAG, "endCallJail");
callback.invoke(res);
}
});
}
@ReactMethod
@ -372,4 +418,26 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
storage.deleteAllData();
}
}
@Override
public boolean handleMessage(Message message) {
Log.d(TAG, "Received message: " + message.toString());
Bundle bundle = message.getData();
String event = bundle.getString("event");
signalEvent(event);
return true;
}
@Override
public void onConnectorConnected() {
}
@Override
public void onConnectorDisconnected() {
}
}

View File

@ -5,7 +5,6 @@ import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import im.status.ethereum.module.StatusService;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -5,28 +5,16 @@ import android.content.Intent;
import android.os.*;
import android.support.annotation.Nullable;
import android.util.Log;
import java.util.concurrent.Callable;
import java.lang.ref.WeakReference;
import com.github.status_im.status_go.cmd.Statusgo;
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class StatusService extends Service {
private static final String TAG = "StatusService";
private boolean isNodeInitialized = false;
private final Handler handler = new Handler();
private ExecutorService executor = null;
private static String dataFolder;
private static Messenger applicationMessenger = null;
public StatusService() {
super();
}
private static class IncomingHandler extends Handler {
@ -51,6 +39,14 @@ public class StatusService extends Service {
private final Messenger serviceMessenger = new Messenger(new IncomingHandler(this));
private static Messenger applicationMessenger = null;
private boolean handleMessage(Message message) {
Log.d(TAG, "Received service message." + message.toString());
applicationMessenger = message.replyTo;
return true;
}
public static void signalEvent(String jsonEvent) {
@ -58,7 +54,7 @@ public class StatusService extends Service {
Bundle replyData = new Bundle();
replyData.putString("event", jsonEvent);
Message replyMessage = Message.obtain(null, StatusMessages.MSG_GETH_EVENT, 0, 0, null);
Message replyMessage = Message.obtain(null, 0, 0, 0, null);
replyMessage.setData(replyData);
sendReply(applicationMessenger, replyMessage);
}
@ -71,301 +67,28 @@ public class StatusService extends Service {
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "Status Service created!");
}
@Override
public void onDestroy() {
super.onDestroy();
if (executor != null) {
executor.shutdownNow();
}
//TODO: stop geth
stopNode(null);
isNodeInitialized = false;
Log.d(TAG, "Status Service stopped!");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (executor == null) {
executor = Executors.newCachedThreadPool();
}
return Service.START_STICKY;
}
private boolean handleMessage(Message message) {
Log.d(TAG, "Received service message." + message.toString());
applicationMessenger = message.replyTo;
doStartNode();
switch (message.what) {
case StatusMessages.MSG_START_NODE:
startNode(message);
break;
case StatusMessages.MSG_STOP_NODE:
stopNode(message);
break;
case StatusMessages.MSG_CREATE_ACCOUNT:
createAccount(message);
break;
case StatusMessages.MSG_RECOVER_ACCOUNT:
recoverAccount(message);
break;
case StatusMessages.MSG_LOGIN:
login(message);
break;
case StatusMessages.MSG_COMPLETE_TRANSACTION:
completeTransaction(message);
break;
case StatusMessages.MSG_DISCARD_TRANSACTION:
discardTransaction(message);
break;
case StatusMessages.MSG_JAIL_INIT:
initJail(message);
break;
case StatusMessages.MSG_JAIL_PARSE:
parseJail(message);
break;
case StatusMessages.MSG_JAIL_CALL:
callJail(message);
break;
case StatusMessages.MSG_START_RPC:
startRPC();
break;
case StatusMessages.MSG_STOP_RPC:
stopRPC();
break;
default:
return false;
}
return true;
}
public void doStartNode() {
if (!isNodeInitialized) {
File extStore = Environment.getExternalStorageDirectory();
dataFolder = extStore.exists() ?
extStore.getAbsolutePath() + "/ethereum" :
getApplicationInfo().dataDir + "/ethereum";
Log.d(TAG, "Starting Geth node in folder: " + dataFolder);
try {
final File newFile = new File(dataFolder);
// todo handle error?
newFile.mkdir();
} catch (Exception e) {
Log.e(TAG, "error making folder: " + dataFolder, e);
}
Statusgo.StartNode(dataFolder);
Log.d(TAG, "Geth node started");
Log.w(TAG, "adding peer");
Statusgo.AddPeer("enode://e19d89e6faf2772e2f250e9625478ee7f313fcc0bb5e9310d5d407371496d9d7d73ccecd9f226cc2a8be34484525f72ba9db9d26f0222f4efc3c6d9d995ee224@198.199.105.122:30303");
Statusgo.AddPeer("enode://1ad53266faaa9258ae71eef4d162022ba0d39498e1a3488e6c65fd86e0fb528e2aa68ad0e199da69fd39f4a3a38e9e8e95ac53ba5cc7676dfeaacf5fd6c0ad27@139.59.212.114:30303");
isNodeInitialized = true;
}
}
private void startNode(Message message) {
doStartNode();
createAndSendReply(message, StatusMessages.MSG_START_NODE, null);
}
private void stopNode(Message message) {
// TODO: stop node
createAndSendReply(message, StatusMessages.MSG_STOP_NODE, null);
}
private void startRPC() {
Statusgo.StartNodeRPCServer();
}
private void stopRPC() {
Statusgo.StopNodeRPCServer();
}
private void createAccount(Message message) {
Bundle data = message.getData();
String password = data.getString("password");
Log.d(TAG, "Creating account: " + password);
String jsonData = Statusgo.CreateAccount(password);
Log.d(TAG, "Created account: " + jsonData);
Bundle replyData = new Bundle();
replyData.putString("data", jsonData);
createAndSendReply(message, StatusMessages.MSG_CREATE_ACCOUNT, replyData);
}
private void recoverAccount(Message message) {
Bundle data = message.getData();
String passphrase = data.getString("passphrase");
String password = data.getString("password");
Log.d(TAG, "Recovering account: " + passphrase + " - " + password);
String jsonData = Statusgo.RecoverAccount(password, passphrase);
Log.d(TAG, "Recovered account: " + jsonData);
Bundle replyData = new Bundle();
replyData.putString("data", jsonData);
createAndSendReply(message, StatusMessages.MSG_RECOVER_ACCOUNT, replyData);
}
private void login(Message message) {
applicationMessenger = message.replyTo;
Bundle data = message.getData();
String address = data.getString("address");
String password = data.getString("password");
String result = Statusgo.Login(address, password);
Log.d(TAG, "Loggedin account: " + result);
Bundle replyData = new Bundle();
replyData.putString("data", result);
createAndSendReply(message, StatusMessages.MSG_LOGIN, replyData);
}
private void completeTransaction(Message message){
Bundle data = message.getData();
String hash = data.getString("hash");
String password = data.getString("password");
Log.d(TAG, "Before CompleteTransaction: " + hash);
String result = Statusgo.CompleteTransaction(hash, password);
Log.d(TAG, "After CompleteTransaction: " + result);
Bundle replyData = new Bundle();
replyData.putString("data", result);
createAndSendReply(message, StatusMessages.MSG_COMPLETE_TRANSACTION, replyData);
}
private void discardTransaction(Message message){
Bundle data = message.getData();
String id = data.getString("id");
Log.d(TAG, "Before DiscardTransaction: " + id);
String result = Statusgo.DiscardTransaction(id);
Log.d(TAG, "After DiscardTransaction: " + result);
}
private void initJail(Message message){
Bundle data = message.getData();
String js = data.getString("js");
Statusgo.InitJail(js);
Bundle replyData = new Bundle();
createAndSendReply(message, StatusMessages.MSG_JAIL_INIT, replyData);
}
private void parseJail(Message message){
Bundle data = message.getData();
String chatId = data.getString("chatId");
String js = data.getString("js");
String result = Statusgo.Parse(chatId, js);
Bundle replyData = new Bundle();
replyData.putString("data", result);
createAndSendReply(message, StatusMessages.MSG_JAIL_PARSE, replyData);
}
private void callJail(Message message){
Bundle data = message.getData();
String chatId = data.getString("chatId");
String path = data.getString("path");
String params = data.getString("params");
String callbackIdentifier = data.getString(StatusConnector.CALLBACK_IDENTIFIER);
Log.d(TAG, "Before StatusGo.Call");
Callable<String> callable = new JailRequest(message.replyTo, chatId, path, params, callbackIdentifier);
executor.submit(callable);
}
public class JailRequest implements Callable<String> {
String chatId;
String path;
String params;
String callbackIdentifier;
Messenger messenger;
JailRequest(Messenger messenger, String chatId, String path, String params, String callbackIdentifier) {
this.messenger = messenger;
this.chatId = chatId;
this.path = path;
this.params = params;
this.callbackIdentifier = callbackIdentifier;
}
public String call() throws Exception {
Log.d(TAG, "StatusGo.Call");
String result = Statusgo.Call(chatId, path, params);
Bundle replyData = new Bundle();
replyData.putString("data", result);
Message replyMessage = Message.obtain(null, StatusMessages.MSG_JAIL_CALL, 0, 0, null);
Log.d(TAG, "Callback identifier: " + callbackIdentifier);
replyData.putString(StatusConnector.CALLBACK_IDENTIFIER, callbackIdentifier);
replyMessage.setData(replyData);
sendReply(messenger, replyMessage);
return result;
}
}
public boolean isNodeInitialized() {
return isNodeInitialized;
}
private static void createAndSendReply(Message message, int replyIdMessage, Bundle replyData) {
if (message == null) {
return;
}
Message replyMessage = Message.obtain(null, replyIdMessage, 0, 0, message.obj);
if (replyData == null) {
replyData = new Bundle();
}
Bundle data = message.getData();
String callbackIdentifier = data.getString(StatusConnector.CALLBACK_IDENTIFIER);
Log.d(TAG, "Callback identifier: " + callbackIdentifier);
replyData.putString(StatusConnector.CALLBACK_IDENTIFIER, callbackIdentifier);
replyMessage.setData(replyData);
sendReply(message.replyTo, replyMessage);
}
private static void sendReply(Messenger messenger, Message message) {
try {
boolean ex = false;
if (messenger != null) {
ex = true;
}
Log.d(TAG, "before sendReply " + ex);
messenger.send(message);
} catch (Exception e) {
Log.e(TAG, "Exception sending message id: " + message.what, e);

View File

@ -363,8 +363,8 @@
(dispatch [:cancel-command]))
(dispatch [:load-requests! chat-id])
;; todo rewrite this. temporary fix for https://github.com/status-im/status-react/issues/607
(dispatch [:load-commands! chat-id])
#_(if-not commands-loaded?
#_(dispatch [:load-commands! chat-id])
(if-not commands-loaded?
(dispatch [:load-commands! chat-id])
(dispatch [:invoke-chat-loaded-callbacks chat-id]))
(if (and (seq messages)

View File

@ -100,7 +100,7 @@
(defn commands-loaded? [db chat-id]
(get-in db [:chats chat-id :commands-loaded]))
(def timeout 50)
(def timeout 400)
(register-handler :received-message-when-commands-loaded
(u/side-effect!

View File

@ -45,7 +45,7 @@
:loading-allowed true
:sync-state :done
:sync-listener nil
:sync-listening-started nil
:status-module-initialized? (or p/ios? js/goog.DEBUG)
:edit-mode {}
:network :testnet})

View File

@ -87,7 +87,6 @@
(dispatch [:load-accounts])
(dispatch [:init-console-chat])
(dispatch [:load-default-contacts!])
(dispatch [:load-commands! console-chat-id])
(dispatch [:load-commands!]))))
(def ecc (js/require "eccjs"))

View File

@ -17,7 +17,8 @@
[taoensso.timbre :as log :refer-macros [debug]]
[status-im.constants :as c]
[status-im.components.status :as status]
[clojure.string :refer [join]]))
[clojure.string :refer [join]]
[status-im.utils.scheduler :as s]))
(register-handler :initialize-protocol
(fn [db [_ current-account-id]]
@ -71,16 +72,24 @@
(when (and (not= sync-data state) (= :in-progress new-state))
(dispatch [:set :sync-data state]))
(when (not= sync-state new-state)
(dispatch [:set :sync-state new-state]))))))
(dispatch [:set :sync-state new-state]))
(let [timeout (if (#{:done :synced} new-state) 60 10)]
(s/execute-later #(dispatch [:check-sync]) (s/s->ms timeout)))))))
(register-handler :initialize-sync-listener
(fn [{:keys [web3 sync-listener] :as db} _]
(if-not sync-listener
(let [sync-listener (.isSyncing
(register-handler :check-sync
(u/side-effect!
(fn [{:keys [web3] :as db}]
(.getSyncing
(.-eth web3)
(fn [error sync]
(dispatch [:update-sync-state error sync])))]
(assoc db :sync-listener sync-listener))
(dispatch [:update-sync-state error sync]))))))
(register-handler :initialize-sync-listener
(fn [{:keys [sync-listening-started] :as db} _]
(if-not sync-listening-started
(do
(dispatch [:check-sync])
(assoc db :sync-listening-started true))
db)))
(register-handler :incoming-message