diff --git a/android/app/build.gradle b/android/app/build.gradle index 16252077d3..9cf1a19a82 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -138,8 +138,6 @@ dependencies { compile project(':react-native-fs') compile project(':react-native-image-crop-picker') compile project(':react-native-webview-bridge') - //compile(name:'statusgo-android-16', ext:'aar') - compile(group: 'status-im', name: 'status-go', version: '0.1.0-574f68-service', ext: 'aar') compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8131fa84ff..2dc81d9380 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index cc26f91d5f..190c4055a9 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -14,7 +14,7 @@ import java.util.Properties; public class MainActivity extends ReactActivity { private static final String TAG = "MainActivity"; - protected void startStatus() { + protected void configureStatus() { // Required because of crazy APN settings redirecting localhost (found in GB) Properties properties = System.getProperties(); properties.setProperty("http.nonProxyHosts", "localhost|127.0.0.1"); @@ -26,7 +26,7 @@ public class MainActivity extends ReactActivity { super.onCreate(savedInstanceState); if (!RootUtil.isDeviceRooted()) { - startStatus(); + configureStatus(); } else { AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) .setMessage(getResources().getString(R.string.root_warning)) @@ -34,7 +34,7 @@ public class MainActivity extends ReactActivity { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); - startStatus(); + configureStatus(); } }) .setNegativeButton(getResources().getString(R.string.root_cancel), new OnClickListener() { diff --git a/android/app/src/main/java/com/statusim/MainApplication.java b/android/app/src/main/java/com/statusim/MainApplication.java index 9c9a881d40..3d7bec0251 100644 --- a/android/app/src/main/java/com/statusim/MainApplication.java +++ b/android/app/src/main/java/com/statusim/MainApplication.java @@ -7,7 +7,7 @@ import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; -import com.statusim.Jail.JailPackage; +import com.statusim.module.StatusPackage; import io.realm.react.RealmReactPackage; import com.oblador.vectoricons.VectorIconsPackage; import com.rt2zz.reactnativecontacts.ReactNativeContacts; @@ -18,7 +18,6 @@ import com.lwansbrough.RCTCamera.*; import com.centaurwarchief.smslistener.SmsListenerPackage; import com.github.yamill.orientation.OrientationPackage; import com.rnfs.RNFSPackage; -import com.statusim.geth.module.GethPackage; import com.aakashns.reactnativedialogs.ReactNativeDialogsPackage; import fr.bamlab.rnimageresizer.ImageResizerPackage; import com.reactnative.picker.PickerPackage; @@ -39,7 +38,7 @@ public class MainApplication extends Application implements ReactApplication { protected List getPackages() { return Arrays.asList( new MainReactPackage(), - new JailPackage(), + new StatusPackage(), new RealmReactPackage(), new VectorIconsPackage(), new ReactNativeContacts(), @@ -50,7 +49,6 @@ public class MainApplication extends Application implements ReactApplication { new SmsListenerPackage(), new OrientationPackage(), new RNFSPackage(), - new GethPackage(), new ReactNativeDialogsPackage(), new ImageResizerPackage(), new PickerPackage(), diff --git a/android/app/src/main/java/com/statusim/geth/module/GethModule.java b/android/app/src/main/java/com/statusim/geth/module/GethModule.java deleted file mode 100644 index 0d89f154e7..0000000000 --- a/android/app/src/main/java/com/statusim/geth/module/GethModule.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.statusim.geth.module; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Message; -import android.os.RemoteException; -import com.facebook.react.bridge.*; -import com.facebook.react.modules.core.DeviceEventManagerModule; -import com.statusim.geth.service.ConnectorHandler; -import com.statusim.geth.service.GethConnector; -import com.statusim.geth.service.GethMessages; -import com.statusim.geth.service.GethService; -import android.util.Log; - -import java.util.HashMap; -import java.util.UUID; - -class GethModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler { - - private static final String TAG = "GethModule"; - - private GethConnector geth = null; - - private HashMap callbacks = new HashMap<>(); - - GethModule(ReactApplicationContext reactContext) { - super(reactContext); - reactContext.addLifecycleEventListener(this); - } - - @Override - public String getName() { - return "Geth"; - } - - @Override - public void onHostResume() { // Actvity `onResume` - - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - return; - } - if (geth == null) { - geth = new GethConnector(currentActivity, GethService.class); - geth.registerHandler(this); - } - geth.bindService(); - } - - @Override - public void onHostPause() { // Actvity `onPause` - - if (geth != null) { - geth.unbindService(); - } - } - - @Override - public void onHostDestroy() { // Actvity `onDestroy` - - if (geth != null) { - geth.stopNode(null); - } - } - - @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 data = message.getData(); - String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER); - Log.d(TAG, "callback identifier: " + callbackIdentifier); - Callback callback = callbacks.remove(callbackIdentifier); - if (callback == null) { - Log.d(TAG, "Could not find callback: " + callbackIdentifier); - } - switch (message.what) { - case GethMessages.MSG_NODE_STARTED: - if (callback != null) { - callback.invoke(true); - } - break; - case GethMessages.MSG_NODE_STOPPED: - break; - case GethMessages.MSG_ACCOUNT_CREATED: - if (callback != null) { - callback.invoke(data.getString("data")); - } - break; - case GethMessages.MSG_ACCOUNT_RECOVERED: - if (callback != null) { - callback.invoke(data.getString("data")); - } - break; - case GethMessages.MSG_LOGGED_IN: - if (callback != null) { - callback.invoke(data.getString("result")); - } - break; - case GethMessages.MSG_TRANSACTION_COMPLETED: - String result = data.getString("result"); - Log.d(TAG, "Send result: " + result + (callback == null)); - if (callback != null) { - callback.invoke(result); - } - break; - case GethMessages.MSG_GETH_EVENT: - String event = data.getString("event"); - WritableMap params = Arguments.createMap(); - params.putString("jsonEvent", event); - getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params); - default: - isClaimed = false; - } - - return isClaimed; - } - - @ReactMethod - public void startNode(Callback callback, Callback onAlreadyRunning) { - - if (GethService.isRunning()) { - onAlreadyRunning.invoke(); - return; - } - - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - callback.invoke("Activity doesn't exist"); - return; - } - - if (geth == null) { - callback.invoke("Geth connector is null"); - return; - } - - String callbackIdentifier = createIdentifier(); - callbacks.put(callbackIdentifier, callback); - - geth.startNode(callbackIdentifier); - } - - @ReactMethod - public void login(String address, String password, Callback callback) { - - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - callback.invoke("Activity doesn't exist"); - return; - } - - if (geth == null) { - callback.invoke("Geth connector is null"); - return; - } - - String callbackIdentifier = createIdentifier(); - callbacks.put(callbackIdentifier, callback); - - geth.login(callbackIdentifier, address, password); - } - - @ReactMethod - public void createAccount(String password, Callback callback) { - - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - callback.invoke("Activity doesn't exist"); - return; - } - - if (geth == null) { - callback.invoke("Geth connector is null"); - return; - } - - String callbackIdentifier = createIdentifier(); - callbacks.put(callbackIdentifier, callback); - - geth.createAccount(callbackIdentifier, password); - } - - @ReactMethod - public void recoverAccount(String passphrase, String password, Callback callback) { - - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - callback.invoke("Activity doesn't exist"); - return; - } - - if (geth == null) { - callback.invoke("Geth connector is null"); - return; - } - - String callbackIdentifier = createIdentifier(); - callbacks.put(callbackIdentifier, callback); - - geth.recoverAccount(callbackIdentifier, passphrase, password); - } - - private String createIdentifier() { - return UUID.randomUUID().toString(); - } - - @ReactMethod - public void completeTransaction(String hash, String password, Callback callback) { - Activity currentActivity = getCurrentActivity(); - - if (currentActivity == null) { - callback.invoke("Activity doesn't exist"); - return; - } - - if (geth == null) { - callback.invoke("Geth connector is null"); - return; - } - - Log.d(TAG, "Complete transaction: " + hash); - String callbackIdentifier = createIdentifier(); - callbacks.put(callbackIdentifier, callback); - - geth.completeTransaction(callbackIdentifier, hash, password); - } -} diff --git a/android/app/src/main/java/com/statusim/geth/service/GethConnector.java b/android/app/src/main/java/com/statusim/geth/service/GethConnector.java deleted file mode 100644 index 1a90b53e55..0000000000 --- a/android/app/src/main/java/com/statusim/geth/service/GethConnector.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.statusim.geth.service; - - -import android.content.Context; -import android.os.Bundle; -import android.os.Message; -import android.os.RemoteException; -import android.util.Log; - -public class GethConnector extends ServiceConnector { - - private static final String TAG = "GethConnector"; - - public static final String CALLBACK_IDENTIFIER = "callbackIdentifier"; - - public GethConnector(Context context, Class serviceClass) { - - super(context, serviceClass); - } - - public void startNode(String callbackIdentifier) { - - if (checkBound()) { - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_START_NODE, null); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(startNode) to service: ", e); - } - } - } - - public void stopNode(String callbackIdentifier) { - - if (checkBound()) { - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_STOP_NODE, null); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(stopNode) to service: ", e); - } - } - } - - public void login(String callbackIdentifier, String address, String password) { - - if (checkBound()) { - Bundle data = new Bundle(); - data.putString("address", address); - data.putString("password", password); - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_LOGIN, data); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(unlockAccount) to service: ", e); - } - } - } - - public void createAccount(String callbackIdentifier, String password) { - - if (checkBound()) { - Bundle data = new Bundle(); - data.putString("password", password); - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_CREATE_ACCOUNT, data); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(createAccount) to service: ", e); - } - } - } - - public void recoverAccount(String callbackIdentifier, String passphrase, String password) { - - if (checkBound()) { - Bundle data = new Bundle(); - data.putString("passphrase", passphrase); - data.putString("password", password); - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_RECOVER_ACCOUNT, data); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(recoverAccount) to service: ", e); - } - } - } - - public void completeTransaction(String callbackIdentifier, String hash, String password){ - if (checkBound()) { - Bundle data = new Bundle(); - data.putString("hash", hash); - data.putString("password", password); - Message msg = createMessage(callbackIdentifier, GethMessages.MSG_COMPLETE_TRANSACTION, data); - try { - serviceMessenger.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Exception sending message(completeTransaction) to service: ", e); - } - } - } - - - private boolean checkBound() { - - if (!isBound) { - Log.d(TAG, "GethConnector 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; - } -} diff --git a/android/app/src/main/java/com/statusim/geth/service/GethMessages.java b/android/app/src/main/java/com/statusim/geth/service/GethMessages.java deleted file mode 100644 index 2194cbdd08..0000000000 --- a/android/app/src/main/java/com/statusim/geth/service/GethMessages.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.statusim.geth.service; - - -public class GethMessages { - - /** - * Start the node - */ - static final int MSG_START_NODE = 1; - - /** - * Node started event - */ - public static final int MSG_NODE_STARTED = 2; - - /** - * Stop the node - */ - static final int MSG_STOP_NODE = 3; - - /** - * Node stopped event - */ - public static final int MSG_NODE_STOPPED = 4; - - /** - * Unlock an account - */ - static final int MSG_LOGIN = 5; - - /** - * Account unlocked event - */ - public static final int MSG_LOGGED_IN = 6; - - /** - * Create an account - */ - static final int MSG_CREATE_ACCOUNT = 7; - - /** - * Account created event - */ - public static final int MSG_ACCOUNT_CREATED = 8; - - /** - * Create an account - */ - static final int MSG_RECOVER_ACCOUNT = 9; - - /** - * Account created event - */ - public static final int MSG_ACCOUNT_RECOVERED = 10; - - /** - * Account complete transaction event - */ - static final int MSG_COMPLETE_TRANSACTION = 11; - - /** - * Account complete transaction event - */ - public static final int MSG_TRANSACTION_COMPLETED = 11; - - /** - * Geth event - */ - public static final int MSG_GETH_EVENT = 12; -} diff --git a/android/settings.gradle b/android/settings.gradle index d68bcdd911..48440b5102 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -20,7 +20,7 @@ project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules include ':react-native-linear-gradient' project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android') include ':react-native-status' -project(':react-native-status').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-status/android') +project(':react-native-status').projectDir = new File(rootProject.projectDir, '../modules/react-native-status/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') include ':react-native-orientation', ':app' diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index d1ce2be680..8f5965aede 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ 2028DFFA1D4275B600227DCD /* SF-UI-Display-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2028DFF61D4275B600227DCD /* SF-UI-Display-Regular.otf */; }; 2028DFFB1D4275B600227DCD /* SF-UI-Display-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2028DFF71D4275B600227DCD /* SF-UI-Display-Semibold.otf */; }; 2028DFFC1D4275B600227DCD /* SF-UI-Display-Thin.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2028DFF81D4275B600227DCD /* SF-UI-Display-Thin.otf */; }; - 20AB9EC61D47CC0300E7FD9C /* libRCTJail.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 201067C41D4789F700FA83B6 /* libRCTJail.a */; }; + 20AB9EC61D47CC0300E7FD9C /* libRCTStatus.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 201067C41D4789F700FA83B6 /* libRCTStatus.a */; }; 20B2DBFC1D47C70C00427CD8 /* Statusgo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20B2DBFB1D47C70C00427CD8 /* Statusgo.framework */; }; 213311F38CA74CE280FD09AD /* libRNI18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 52F6ED6465184513A082652B /* libRNI18n.a */; }; 22118DE1207A419FBFE7B62D /* libRealmReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CD48A32459B64E96843BB238 /* libRealmReact.a */; }; @@ -131,10 +131,10 @@ }; 201067C31D4789F700FA83B6 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 439B6B4B407A4E2AACAFE5BE /* RCTJail.xcodeproj */; + containerPortal = 439B6B4B407A4E2AACAFE5BE /* RCTStatus.xcodeproj */; proxyType = 2; remoteGlobalIDString = 206C9F3A1D474E910063E3E6; - remoteInfo = RCTJail; + remoteInfo = RCTStatus; }; 20B7D0FD1D3F74CC00B70F14 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -249,16 +249,16 @@ 2028DFF61D4275B600227DCD /* SF-UI-Display-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-UI-Display-Regular.otf"; sourceTree = ""; }; 2028DFF71D4275B600227DCD /* SF-UI-Display-Semibold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-UI-Display-Semibold.otf"; sourceTree = ""; }; 2028DFF81D4275B600227DCD /* SF-UI-Display-Thin.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-UI-Display-Thin.otf"; sourceTree = ""; }; - 20B2DBDD1D47BD5E00427CD8 /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Statusgo.framework; path = "../node_modules/react-native-status/ios/RCTJail/Statusgo.framework"; sourceTree = ""; }; + 20B2DBDD1D47BD5E00427CD8 /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Statusgo.framework; path = "../modules/react-native-status/ios/RCTStatus/Statusgo.framework"; sourceTree = ""; }; 20B2DBF71D47C25500427CD8 /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Statusgo.framework; sourceTree = ""; }; - 20B2DBFB1D47C70C00427CD8 /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Statusgo.framework; path = "../node_modules/react-native-status/ios/Statusgo.framework"; sourceTree = ""; }; + 20B2DBFB1D47C70C00427CD8 /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Statusgo.framework; path = "../modules/react-native-status/ios/Statusgo.framework"; sourceTree = ""; }; 2756305FAFF144C4A6B0A039 /* Zocial.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Zocial.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Zocial.ttf"; sourceTree = ""; }; 2F0276A9E90843E996A0E762 /* UdpSockets.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = UdpSockets.xcodeproj; path = "../node_modules/react-native-udp/ios/UdpSockets.xcodeproj"; sourceTree = ""; }; 305F194186D848FDB07AF34C /* RNFS.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFS.xcodeproj; path = "../node_modules/react-native-fs/RNFS.xcodeproj"; sourceTree = ""; }; 3384AFA9609A409B81928AD5 /* libRCTContacts.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTContacts.a; sourceTree = ""; }; 359B076A658B4FBAB5128B03 /* Ionicons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Ionicons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Ionicons.ttf"; sourceTree = ""; }; 38E1A2C8D0734EE99E2B16CE /* TcpSockets.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = TcpSockets.xcodeproj; path = "../node_modules/react-native-tcp/ios/TcpSockets.xcodeproj"; sourceTree = ""; }; - 439B6B4B407A4E2AACAFE5BE /* RCTJail.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTJail.xcodeproj; path = "../node_modules/react-native-status/ios/RCTJail/RCTJail.xcodeproj"; sourceTree = ""; }; + 439B6B4B407A4E2AACAFE5BE /* RCTStatus.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTStatus.xcodeproj; path = "../modules/react-native-status/ios/RCTStatus/RCTStatus.xcodeproj"; sourceTree = ""; }; 43A6FA689D844B0BAF3AA8B4 /* RCTOrientation.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTOrientation.xcodeproj; path = "../node_modules/react-native-orientation/iOS/RCTOrientation.xcodeproj"; sourceTree = ""; }; 45FB5F523DE04BDE9877869C /* RNRandomBytes.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNRandomBytes.xcodeproj; path = "../node_modules/react-native-randombytes/RNRandomBytes.xcodeproj"; sourceTree = ""; }; 46E2F6052EB44C698C680894 /* RNI18n.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNI18n.xcodeproj; path = "../node_modules/react-native-i18n/RNI18n.xcodeproj"; sourceTree = ""; }; @@ -301,7 +301,7 @@ buildActionMask = 2147483647; files = ( 20B2DBFC1D47C70C00427CD8 /* Statusgo.framework in Frameworks */, - 20AB9EC61D47CC0300E7FD9C /* libRCTJail.a in Frameworks */, + 20AB9EC61D47CC0300E7FD9C /* libRCTStatus.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, @@ -462,7 +462,7 @@ 201067BA1D4789F700FA83B6 /* Products */ = { isa = PBXGroup; children = ( - 201067C41D4789F700FA83B6 /* libRCTJail.a */, + 201067C41D4789F700FA83B6 /* libRCTStatus.a */, ); name = Products; sourceTree = ""; @@ -583,7 +583,7 @@ F090E261B9854867A728CE4F /* RealmReact.xcodeproj */, 38E1A2C8D0734EE99E2B16CE /* TcpSockets.xcodeproj */, 2F0276A9E90843E996A0E762 /* UdpSockets.xcodeproj */, - 439B6B4B407A4E2AACAFE5BE /* RCTJail.xcodeproj */, + 439B6B4B407A4E2AACAFE5BE /* RCTStatus.xcodeproj */, 5E5A7625B76441D984EA8C0D /* RCTImageResizer.xcodeproj */, ); name = Libraries; @@ -724,7 +724,7 @@ }, { ProductGroup = 201067BA1D4789F700FA83B6 /* Products */; - ProjectRef = 439B6B4B407A4E2AACAFE5BE /* RCTJail.xcodeproj */; + ProjectRef = 439B6B4B407A4E2AACAFE5BE /* RCTStatus.xcodeproj */; }, { ProductGroup = 78C398B11ACF4ADC00677621 /* Products */; @@ -866,10 +866,10 @@ remoteRef = 201067711D477F5E00FA83B6 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 201067C41D4789F700FA83B6 /* libRCTJail.a */ = { + 201067C41D4789F700FA83B6 /* libRCTStatus.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; - path = libRCTJail.a; + path = libRCTStatus.a; remoteRef = 201067C31D4789F700FA83B6 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1144,8 +1144,8 @@ "$(SRCROOT)/../node_modules/realm/src/**", "$(SRCROOT)/../node_modules/react-native-tcp/ios/**", "$(SRCROOT)/../node_modules/react-native-udp/ios/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", "$(SRCROOT)/../node_modules/react-native-image-resizer/ios/RCTImageResizer", ); INFOPLIST_FILE = StatusIm/Info.plist; @@ -1185,8 +1185,8 @@ "$(SRCROOT)/../node_modules/realm/src/**", "$(SRCROOT)/../node_modules/react-native-tcp/ios/**", "$(SRCROOT)/../node_modules/react-native-udp/ios/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", "$(SRCROOT)/../node_modules/react-native-image-resizer/ios/RCTImageResizer", ); INFOPLIST_FILE = StatusIm/Info.plist; @@ -1250,8 +1250,8 @@ "$(SRCROOT)/../node_modules/realm/src/**", "$(SRCROOT)/../node_modules/react-native-tcp/ios/**", "$(SRCROOT)/../node_modules/react-native-udp/ios/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", "$(SRCROOT)/../node_modules/react-native-image-resizer/ios/RCTImageResizer", ); IPHONEOS_DEPLOYMENT_TARGET = 7.0; @@ -1304,8 +1304,8 @@ "$(SRCROOT)/../node_modules/realm/src/**", "$(SRCROOT)/../node_modules/react-native-tcp/ios/**", "$(SRCROOT)/../node_modules/react-native-udp/ios/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", - "$(SRCROOT)/../node_modules/react-native-status/ios/RCTJail/RCTJail/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", + "$(SRCROOT)/../modules/react-native-status/ios/RCTStatus/**", "$(SRCROOT)/../node_modules/react-native-image-resizer/ios/RCTImageResizer", ); IPHONEOS_DEPLOYMENT_TARGET = 7.0; diff --git a/modules/react-native-status/android/build.gradle b/modules/react-native-status/android/build.gradle new file mode 100644 index 0000000000..abdaecb7c1 --- /dev/null +++ b/modules/react-native-status/android/build.gradle @@ -0,0 +1,18 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } +} + +dependencies { + compile 'com.facebook.react:react-native:+' + compile(group: 'status-im', name: 'status-go', version: '0.1.0-module', ext: 'aar') +} \ No newline at end of file diff --git a/modules/react-native-status/android/src/main/AndroidManifest.xml b/modules/react-native-status/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..2b6aeb87f8 --- /dev/null +++ b/modules/react-native-status/android/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/android/app/src/main/java/com/statusim/geth/service/ConnectorHandler.java b/modules/react-native-status/android/src/main/java/com/statusim/module/ConnectorHandler.java similarity index 83% rename from android/app/src/main/java/com/statusim/geth/service/ConnectorHandler.java rename to modules/react-native-status/android/src/main/java/com/statusim/module/ConnectorHandler.java index 1a9077490a..5259e17ce3 100644 --- a/android/app/src/main/java/com/statusim/geth/service/ConnectorHandler.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/ConnectorHandler.java @@ -1,4 +1,4 @@ -package com.statusim.geth.service; +package com.statusim.module; import android.os.Message; diff --git a/android/app/src/main/java/com/statusim/geth/service/ServiceConnector.java b/modules/react-native-status/android/src/main/java/com/statusim/module/ServiceConnector.java similarity index 99% rename from android/app/src/main/java/com/statusim/geth/service/ServiceConnector.java rename to modules/react-native-status/android/src/main/java/com/statusim/module/ServiceConnector.java index b2cd7996dd..78b225d109 100644 --- a/android/app/src/main/java/com/statusim/geth/service/ServiceConnector.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/ServiceConnector.java @@ -1,4 +1,4 @@ -package com.statusim.geth.service; +package com.statusim.module; import android.content.ComponentName; @@ -69,6 +69,7 @@ public class ServiceConnector { // interact with the service. We are communicating with the // service using a Messenger, so here we get a client-side // representation of that from the raw IBinder object. + serviceMessenger = new Messenger(service); isBound = true; for (ConnectorHandler handler: handlers) { diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java new file mode 100644 index 0000000000..23cd3f9171 --- /dev/null +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java @@ -0,0 +1,135 @@ +package com.statusim.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 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 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); + } + } +} diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java new file mode 100644 index 0000000000..6365a45a20 --- /dev/null +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java @@ -0,0 +1,59 @@ +package com.statusim.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; + + + +} diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java new file mode 100644 index 0000000000..959e72061b --- /dev/null +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java @@ -0,0 +1,298 @@ +package com.statusim.module; + +import android.app.Activity; +import android.view.WindowManager; +import android.os.Bundle; +import android.os.Message; +import android.os.RemoteException; +import com.facebook.react.bridge.*; +import com.facebook.react.modules.core.DeviceEventManagerModule; +import android.util.Log; + +import java.util.HashMap; +import java.util.UUID; + +class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler { + + private static final String TAG = "StatusModule"; + + private StatusConnector status = null; + + private HashMap callbacks = new HashMap<>(); + + StatusModule(ReactApplicationContext reactContext) { + super(reactContext); + reactContext.addLifecycleEventListener(this); + } + + @Override + public String getName() { + return "Status"; + } + + @Override + public void onHostResume() { // Actvity `onResume` + + Activity currentActivity = getCurrentActivity(); + if (currentActivity == null) { + return; + } + if (status == null) { + status = new StatusConnector(currentActivity, StatusService.class); + status.registerHandler(this); + } + status.bindService(); + } + + @Override + public void onHostPause() { // Actvity `onPause` + + if (status != null) { + status.unbindService(); + } + } + + @Override + public void onHostDestroy() { // Actvity `onDestroy` + + if (status != null) { + status.stopNode(null); + } + } + + @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() { + + Activity currentActivity = getCurrentActivity(); + if (currentActivity == null) { + Log.d(TAG, "Activity doesn't exist"); + return false; + } + + if (status == null) { + Log.d(TAG, "Status connector is null"); + return false; + } + + return true; + } + + // Geth + + @ReactMethod + public void startNode(Callback callback, Callback onAlreadyRunning) { + + if (StatusService.isRunning()) { + onAlreadyRunning.invoke(); + return; + } + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.startNode(callbackIdentifier); + } + + @ReactMethod + public void login(String address, String password, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.login(callbackIdentifier, address, password); + } + + @ReactMethod + public void createAccount(String password, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.createAccount(callbackIdentifier, password); + } + + @ReactMethod + public void recoverAccount(String passphrase, String password, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.recoverAccount(callbackIdentifier, passphrase, password); + } + + private String createIdentifier() { + return UUID.randomUUID().toString(); + } + + @ReactMethod + public void completeTransaction(String hash, String password, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + Log.d(TAG, "Complete transaction: " + hash); + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.completeTransaction(callbackIdentifier, hash, password); + } + + // Jail + + @ReactMethod + public void initJail(String js, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.initJail(callbackIdentifier, js); + } + + @ReactMethod + public void parseJail(String chatId, String js, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.parseJail(callbackIdentifier, chatId, js); + } + + @ReactMethod + public void callJail(String chatId, String path, String params, Callback callback) { + + if (!checkAvailability()) { + callback.invoke(false); + return; + } + + String callbackIdentifier = createIdentifier(); + callbacks.put(callbackIdentifier, callback); + + status.callJail(callbackIdentifier, chatId, path, params); + } + + @ReactMethod + public void setAdjustResize() { + + final Activity activity = getCurrentActivity(); + if (activity == null) { + return; + } + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + } + }); + } + + @ReactMethod + public void setAdjustPan() { + + final Activity activity = getCurrentActivity(); + if (activity == null) { + return; + } + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); + } + }); + } + + @ReactMethod + public void setSoftInputMode(final int mode) { + + final Activity activity = getCurrentActivity(); + if (activity == null) { + return; + } + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.getWindow().setSoftInputMode(mode); + } + }); + } +} diff --git a/android/app/src/main/java/com/statusim/geth/module/GethPackage.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusPackage.java similarity index 81% rename from android/app/src/main/java/com/statusim/geth/module/GethPackage.java rename to modules/react-native-status/android/src/main/java/com/statusim/module/StatusPackage.java index d7dc02df6f..806bf8c1f4 100644 --- a/android/app/src/main/java/com/statusim/geth/module/GethPackage.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusPackage.java @@ -1,22 +1,23 @@ -package com.statusim.geth.module; +package com.statusim.module; import com.facebook.react.ReactPackage; 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 com.statusim.module.StatusService; import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class GethPackage implements ReactPackage { +public class StatusPackage implements ReactPackage { @Override public List createNativeModules(ReactApplicationContext reactContext) { List modules = new ArrayList<>(); - modules.add(new GethModule(reactContext)); + modules.add(new StatusModule(reactContext)); return modules; } diff --git a/android/app/src/main/java/com/statusim/geth/service/GethService.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java similarity index 67% rename from android/app/src/main/java/com/statusim/geth/service/GethService.java rename to modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java index 2724a824b5..ca90ef3f71 100644 --- a/android/app/src/main/java/com/statusim/geth/service/GethService.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java @@ -1,4 +1,4 @@ -package com.statusim.geth.service; +package com.statusim.module; import android.app.Service; import android.content.Intent; @@ -12,11 +12,11 @@ import com.github.status_im.status_go.Statusgo; import java.io.File; -public class GethService extends Service { +public class StatusService extends Service { - private static final String TAG = "GethService"; + private static final String TAG = "StatusService"; - private static boolean isGethInitialized = false; + private static boolean isStatusInitialized = false; private final Handler handler = new Handler(); private static String dataFolder; @@ -25,9 +25,9 @@ public class GethService extends Service { private static class IncomingHandler extends Handler { - private final WeakReference service; + private final WeakReference service; - IncomingHandler(GethService service) { + IncomingHandler(StatusService service) { this.service = new WeakReference<>(service); } @@ -35,7 +35,7 @@ public class GethService extends Service { @Override public void handleMessage(Message message) { - GethService service = this.service.get(); + StatusService service = this.service.get(); if (service != null) { if (!service.handleMessage(message)) { super.handleMessage(message); @@ -48,15 +48,21 @@ public class GethService extends Service { public static void signalEvent(String jsonEvent) { + Log.d(TAG, "Signal event: " + jsonEvent); Bundle replyData = new Bundle(); replyData.putString("event", jsonEvent); - Message replyMessage = Message.obtain(null, GethMessages.MSG_GETH_EVENT, 0, 0, null); + Message replyMessage = Message.obtain(null, StatusMessages.MSG_GETH_EVENT, 0, 0, null); replyMessage.setData(replyData); sendReply(applicationMessenger, replyMessage); } + static { + System.loadLibrary("statusgoraw"); + System.loadLibrary("statusgo"); + } + @Nullable @Override public IBinder onBind(Intent intent) { @@ -65,53 +71,68 @@ public class GethService extends Service { @Override public void onCreate() { + super.onCreate(); - System.loadLibrary("statusgoraw"); - System.loadLibrary("statusgo"); + } @Override public void onDestroy() { + super.onDestroy(); //TODO: stop geth stopNode(null); - isGethInitialized = false; - Log.d(TAG, "Geth Service stopped !"); + isStatusInitialized = false; + Log.d(TAG, "Status Service stopped !"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { + return Service.START_STICKY; } private boolean handleMessage(Message message) { + switch (message.what) { - case GethMessages.MSG_START_NODE: + case StatusMessages.MSG_START_NODE: Log.d(TAG, "Received start node message." + message.toString()); startNode(message); break; - case GethMessages.MSG_STOP_NODE: + case StatusMessages.MSG_STOP_NODE: stopNode(message); break; - case GethMessages.MSG_CREATE_ACCOUNT: + case StatusMessages.MSG_CREATE_ACCOUNT: createAccount(message); break; - case GethMessages.MSG_RECOVER_ACCOUNT: + case StatusMessages.MSG_RECOVER_ACCOUNT: recoverAccount(message); break; - case GethMessages.MSG_LOGIN: + case StatusMessages.MSG_LOGIN: login(message); break; - case GethMessages.MSG_COMPLETE_TRANSACTION: + case StatusMessages.MSG_COMPLETE_TRANSACTION: completeTransaction(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; + default: return false; } @@ -120,11 +141,12 @@ public class GethService extends Service { } private void startNode(Message message) { - if (!isGethInitialized) { - isGethInitialized = true; + + if (!isStatusInitialized) { + isStatusInitialized = true; Log.d(TAG, "Client messenger1: " + message.replyTo.toString()); Bundle data = message.getData(); - String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER); + String callbackIdentifier = data.getString(StatusConnector.CALLBACK_IDENTIFIER); Log.d(TAG, "Callback identifier: " + callbackIdentifier); new StartTask(message.replyTo, callbackIdentifier).execute(); } @@ -136,11 +158,13 @@ public class GethService extends Service { Messenger messenger; StartTask(Messenger messenger, String callbackIdentifier) { + this.messenger = messenger; this.callbackIdentifier = callbackIdentifier; } protected Void doInBackground(Void... args) { + startGeth(); return null; } @@ -151,20 +175,19 @@ public class GethService extends Service { } private void onGethStarted(Messenger messenger, String callbackIdentifier) { - Log.d(TAG, "Geth Service started"); - Message replyMessage = Message.obtain(null, GethMessages.MSG_NODE_STARTED, 0, 0, null); + + Log.d(TAG, "Geth Node started"); + Message replyMessage = Message.obtain(null, StatusMessages.MSG_START_NODE, 0, 0, null); Bundle replyData = new Bundle(); Log.d(TAG, "Callback identifier: " + callbackIdentifier); - replyData.putString(GethConnector.CALLBACK_IDENTIFIER, callbackIdentifier); + replyData.putString(StatusConnector.CALLBACK_IDENTIFIER, callbackIdentifier); replyMessage.setData(replyData); sendReply(messenger, replyMessage); } private void startGeth() { - - + File extStore = Environment.getExternalStorageDirectory(); - dataFolder = extStore.exists() ? extStore.getAbsolutePath() + "/ethereum" : getApplicationInfo().dataDir + "/ethereum"; @@ -197,10 +220,11 @@ public class GethService extends Service { private void stopNode(Message message) { // TODO: stop node - createAndSendReply(message, GethMessages.MSG_NODE_STOPPED, null); + createAndSendReply(message, StatusMessages.MSG_STOP_NODE, null); } private void createAccount(Message message) { + Bundle data = message.getData(); String password = data.getString("password"); Log.d(TAG, "Creating account: " + password); @@ -209,10 +233,11 @@ public class GethService extends Service { Bundle replyData = new Bundle(); replyData.putString("data", jsonData); - createAndSendReply(message, GethMessages.MSG_ACCOUNT_CREATED, replyData); + 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"); @@ -222,10 +247,11 @@ public class GethService extends Service { Bundle replyData = new Bundle(); replyData.putString("data", jsonData); - createAndSendReply(message, GethMessages.MSG_ACCOUNT_RECOVERED, replyData); + createAndSendReply(message, StatusMessages.MSG_RECOVER_ACCOUNT, replyData); } private void login(Message message) { + applicationMessenger = message.replyTo; Bundle data = message.getData(); String address = data.getString("address"); @@ -234,14 +260,15 @@ public class GethService extends Service { Log.d(TAG, "Loggedin account: " + result); Bundle replyData = new Bundle(); - replyData.putString("result", result); - createAndSendReply(message, GethMessages.MSG_LOGGED_IN, replyData); + replyData.putString("data", result); + createAndSendReply(message, StatusMessages.MSG_LOGIN, replyData); // Test signalEvent //signalEvent("{ \"type\": \"test\", \"event\": \"test event\" }"); } private void completeTransaction(Message message){ + Bundle data = message.getData(); String hash = data.getString("hash"); String password = data.getString("password"); @@ -251,12 +278,50 @@ public class GethService extends Service { Log.d(TAG, "After CompleteTransaction: " + result); Bundle replyData = new Bundle(); - replyData.putString("result", result); - createAndSendReply(message, GethMessages.MSG_TRANSACTION_COMPLETED, replyData); + replyData.putString("data", result); + createAndSendReply(message, StatusMessages.MSG_COMPLETE_TRANSACTION, replyData); + } + + 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 result = Statusgo.call(chatId, path, params); + + Bundle replyData = new Bundle(); + replyData.putString("data", result); + createAndSendReply(message, StatusMessages.MSG_JAIL_CALL, replyData); } public static boolean isRunning() { - return isGethInitialized; + return isStatusInitialized; } private static void createAndSendReply(Message message, int replyIdMessage, Bundle replyData) { @@ -269,15 +334,16 @@ public class GethService extends Service { replyData = new Bundle(); } Bundle data = message.getData(); - String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER); + String callbackIdentifier = data.getString(StatusConnector.CALLBACK_IDENTIFIER); Log.d(TAG, "Callback identifier: " + callbackIdentifier); - replyData.putString(GethConnector.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 { messenger.send(message); } catch (Exception e) { diff --git a/modules/react-native-status/index.js b/modules/react-native-status/index.js new file mode 100644 index 0000000000..af2b94d150 --- /dev/null +++ b/modules/react-native-status/index.js @@ -0,0 +1,4 @@ +'use strict'; + +import { NativeModules } from 'react-native'; +module.exports = NativeModules.Status; \ No newline at end of file diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.h b/modules/react-native-status/ios/RCTStatus/RCTStatus.h new file mode 100644 index 0000000000..c3793a8b96 --- /dev/null +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.h @@ -0,0 +1,6 @@ +#import +#import "RCTBridgeModule.h" +#import "RCTLog.h" + +@interface Status : NSObject +@end \ No newline at end of file diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m new file mode 100644 index 0000000000..7bc0c1acf7 --- /dev/null +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -0,0 +1,55 @@ +#import "RCTStatus.h" + +#import + +@implementation Status +@synthesize bridge = _bridge; + +RCT_EXPORT_MODULE(); + +RCT_EXPORT_METHOD(initJail: (NSString *) js + callback:(RCTResponseSenderBlock)callback) { + initJail((char *) [js UTF8String]); + callback(@[[NSNull null]]); +} + +RCT_EXPORT_METHOD(parseJail:(NSString *)chatId + js:(NSString *)js + callback:(RCTResponseSenderBlock)callback) { +#if DEBUG + NSLog(@"parseJail() method called"); +#endif + char * result = parse((char *) [chatId UTF8String], (char *) [js UTF8String]); + callback(@[[NSNull null], [NSString stringWithUTF8String: result]]); +} + +RCT_EXPORT_METHOD(callJail:(NSString *)chatId + path:(NSString *)path + params:(NSString *)params + callback:(RCTResponseSenderBlock)callback) { +#if DEBUG + NSLog(@"callJail() method called"); +#endif + char * result = call((char *) [chatId UTF8String], (char *) [path UTF8String], (char *) [params UTF8String]); + callback(@[[NSNull null], [NSString stringWithUTF8String: result]]); +} + +RCT_EXPORT_METHOD(setAdjustResize) { +#if DEBUG + NSLog(@"setAdjustResize() works only on Android"); +#endif +} + +RCT_EXPORT_METHOD(setAdjustPan) { +#if DEBUG + NSLog(@"setAdjustPan() works only on Android"); +#endif +} + +RCT_EXPORT_METHOD(setSoftInputMode: (NSInteger) i) { +#if DEBUG + NSLog(@"setSoftInputMode() works only on Android"); +#endif +} + +@end diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.xcodeproj/project.pbxproj b/modules/react-native-status/ios/RCTStatus/RCTStatus.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..8db2d0ee36 --- /dev/null +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.xcodeproj/project.pbxproj @@ -0,0 +1,302 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 206C9F3E1D474E910063E3E6 /* RCTStatus.h in Copy Files */ = {isa = PBXBuildFile; fileRef = 206C9F3D1D474E910063E3E6 /* RCTStatus.h */; }; + 206C9F401D474E910063E3E6 /* RCTStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 206C9F3F1D474E910063E3E6 /* RCTStatus.m */; }; + 20AB9EAE1D47CBF500E7FD9C /* Statusgo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20AB9EAD1D47CBF500E7FD9C /* Statusgo.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 206C9F381D474E910063E3E6 /* Copy Files */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + 206C9F3E1D474E910063E3E6 /* RCTStatus.h in Copy Files */, + ); + name = "Copy Files"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 206C9F3A1D474E910063E3E6 /* libRCTStatus.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTStatus.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 206C9F3D1D474E910063E3E6 /* RCTStatus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTStatus.h; sourceTree = ""; }; + 206C9F3F1D474E910063E3E6 /* RCTStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTStatus.m; sourceTree = ""; }; + 20AB9EAD1D47CBF500E7FD9C /* Statusgo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Statusgo.framework; path = "../../../../../react-native-status/ios/Statusgo.framework"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 206C9F371D474E910063E3E6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 20AB9EAE1D47CBF500E7FD9C /* Statusgo.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 206C9F311D474E910063E3E6 = { + isa = PBXGroup; + children = ( + 20AB9EAD1D47CBF500E7FD9C /* Statusgo.framework */, + 206C9F3C1D474E910063E3E6 /* RCTStatus */, + 206C9F3B1D474E910063E3E6 /* Products */, + ); + sourceTree = ""; + }; + 206C9F3B1D474E910063E3E6 /* Products */ = { + isa = PBXGroup; + children = ( + 206C9F3A1D474E910063E3E6 /* libRCTStatus.a */, + ); + name = Products; + sourceTree = ""; + }; + 206C9F3C1D474E910063E3E6 /* RCTStatus */ = { + isa = PBXGroup; + children = ( + 206C9F3D1D474E910063E3E6 /* RCTStatus.h */, + 206C9F3F1D474E910063E3E6 /* RCTStatus.m */, + ); + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 206C9F391D474E910063E3E6 /* RCTStatus */ = { + isa = PBXNativeTarget; + buildConfigurationList = 206C9F431D474E910063E3E6 /* Build configuration list for PBXNativeTarget "RCTStatus" */; + buildPhases = ( + 206C9F361D474E910063E3E6 /* Sources */, + 206C9F371D474E910063E3E6 /* Frameworks */, + 206C9F381D474E910063E3E6 /* Copy Files */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RCTStatus; + productName = RCTStatus; + productReference = 206C9F3A1D474E910063E3E6 /* libRCTStatus.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 206C9F321D474E910063E3E6 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = Status.im; + TargetAttributes = { + 206C9F391D474E910063E3E6 = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 206C9F351D474E910063E3E6 /* Build configuration list for PBXProject "RCTStatus" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 206C9F311D474E910063E3E6; + productRefGroup = 206C9F3B1D474E910063E3E6 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 206C9F391D474E910063E3E6 /* RCTStatus */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 206C9F361D474E910063E3E6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 206C9F401D474E910063E3E6 /* RCTStatus.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 206C9F411D474E910063E3E6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 206C9F421D474E910063E3E6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 206C9F441D474E910063E3E6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + "$(ARCHS_STANDARD)", + x86_64, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/..", + ); + FRAMEWORK_VERSION = A; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../../react-native/React/**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-ObjC", + "$(inherited)", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = "armv7 armv7s arm64 x86_64"; + }; + name = Debug; + }; + 206C9F451D474E910063E3E6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + "$(ARCHS_STANDARD)", + x86_64, + ); + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/..", + ); + FRAMEWORK_VERSION = A; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../../react-native/React/**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ( + "-ObjC", + "$(inherited)", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = "armv7 armv7s arm64 x86_64"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 206C9F351D474E910063E3E6 /* Build configuration list for PBXProject "RCTStatus" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 206C9F411D474E910063E3E6 /* Debug */, + 206C9F421D474E910063E3E6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 206C9F431D474E910063E3E6 /* Build configuration list for PBXNativeTarget "RCTStatus" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 206C9F441D474E910063E3E6 /* Debug */, + 206C9F451D474E910063E3E6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 206C9F321D474E910063E3E6 /* Project object */; +} diff --git a/modules/react-native-status/ios/Statusgo.framework/Versions/A/Headers/Statusgo.h b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Headers/Statusgo.h new file mode 100755 index 0000000000..a7a43155db --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Headers/Statusgo.h @@ -0,0 +1,71 @@ +/* Created by "go tool cgo" - DO NOT EDIT. */ + +/* package github.com/status-im/status-go/src */ + +/* Start of preamble from import "C" comments. */ + + + + +/* End of preamble from import "C" comments. */ + + +/* Start of boilerplate cgo prologue. */ + +#ifndef GO_CGO_PROLOGUE_H +#define GO_CGO_PROLOGUE_H + +typedef signed char GoInt8; +typedef unsigned char GoUint8; +typedef short GoInt16; +typedef unsigned short GoUint16; +typedef int GoInt32; +typedef unsigned int GoUint32; +typedef long long GoInt64; +typedef unsigned long long GoUint64; +typedef GoInt64 GoInt; +typedef GoUint64 GoUint; +typedef __SIZE_TYPE__ GoUintptr; +typedef float GoFloat32; +typedef double GoFloat64; +typedef float _Complex GoComplex64; +typedef double _Complex GoComplex128; + +/* + static assertion to make sure the file is being used on architecture + at least with matching size of GoInt. +*/ +typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; + +typedef struct { const char *p; GoInt n; } GoString; +typedef void *GoMap; +typedef void *GoChan; +typedef struct { void *t; void *v; } GoInterface; +typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; + +#endif + +/* End of boilerplate cgo prologue. */ + +#ifdef __cplusplus +extern "C" { +#endif + + +extern char* CreateAccount(char* p0); + +extern char* Login(char* p0, char* p1); + +extern char* UnlockAccount(char* p0, char* p1, GoInt p2); + +extern char* StartNode(char* p0); + +extern char* parse(char* p0, char* p1); + +extern char* call(char* p0, char* p1, char* p2); + +extern void initJail(char* p0); + +#ifdef __cplusplus +} +#endif diff --git a/modules/react-native-status/ios/Statusgo.framework/Versions/A/Modules/module.modulemap b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Modules/module.modulemap new file mode 100755 index 0000000000..25973b253d --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Modules/module.modulemap @@ -0,0 +1,4 @@ +framework module "Statusgo" { + header "Statusgo.h" + export * +} diff --git a/modules/react-native-status/ios/Statusgo.framework/Versions/A/Resources/Info.plist b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Resources/Info.plist new file mode 100755 index 0000000000..6631ffa6f2 --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/modules/react-native-status/ios/Statusgo.framework/Versions/A/Statusgo.REMOVED.git-id b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Statusgo.REMOVED.git-id new file mode 100644 index 0000000000..f28049e1c7 --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/Versions/A/Statusgo.REMOVED.git-id @@ -0,0 +1 @@ +bd7ae0b1c5bf90e4a4fa06bd17667234485f130a \ No newline at end of file diff --git a/modules/react-native-status/ios/Statusgo.framework/Versions/Current b/modules/react-native-status/ios/Statusgo.framework/Versions/Current new file mode 120000 index 0000000000..8c7e5a667f --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/modules/react-native-status/ios/Statusgo.framework/fix_symlinks_ios.sh b/modules/react-native-status/ios/Statusgo.framework/fix_symlinks_ios.sh new file mode 100755 index 0000000000..b371423470 --- /dev/null +++ b/modules/react-native-status/ios/Statusgo.framework/fix_symlinks_ios.sh @@ -0,0 +1,32 @@ +#!/bin/bash +########################################################## +# Fix Symlinks +# +# Usage : Copy this file into the Framework directory, +# Execute it passing the Framework Name in argument. +# +########################################################## + +if [ -z $1 ] ; then + echo "Usage : $0 " + exit -1 +else + echo "Removing current Symlinks files" + rm Headers + rm Resources + rm Modules + rm $1 + rm Versions/Current + + echo "Creating new Symlinks" + cd Versions + ln -s A Current + cd .. + + ln -s ./Versions/Current/Headers Headers + ln -s ./Versions/Current/Resources Resources + ln -s ./Versions/Current/Modules Modules + ln -s ./Versions/Current/$1 $1 + + echo "Job done!" +fi diff --git a/modules/react-native-status/package.json b/modules/react-native-status/package.json new file mode 100644 index 0000000000..1df0d0b103 --- /dev/null +++ b/modules/react-native-status/package.json @@ -0,0 +1,21 @@ +{ + "private": true, + "nativePackage": true, + "name": "react-native-status", + "version": "1.0.0", + "description": "Manage Geth, Jail & Background Service", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/status-im/react-native-status.git" + }, + "author": "", + "license": "", + "bugs": { + "url": "https://github.com/status-im/react-native-status/issues" + }, + "homepage": "https://github.com/status-im/react-native-status#readme" +} \ No newline at end of file diff --git a/package.json b/package.json index 161c8f3446..f2fbb3e2eb 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "react-native-orientation": "github:youennPennarun/react-native-orientation", "react-native-qrcode": "^0.2.2", "react-native-randombytes": "^2.1.0", - "react-native-status": "github:status-im/react-native-status#ios-module", "react-native-tcp": "^1.0.1", "react-native-udp": "^1.2.5", "react-native-vector-icons": "^2.0.3", diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index fed7ec8cac..dafc5d97db 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -3,7 +3,7 @@ [re-frame.core :refer [register-handler after dispatch dispatch-sync debug]] [status-im.utils.logging :as log] [status-im.protocol.api :as api] - [status-im.components.geth :as geth] + [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] @@ -52,7 +52,7 @@ (after #(dispatch [:init-wallet-chat])) (u/side-effect! (fn [_ [_ password]] - (geth/create-account + (status/create-account password #(account-created % password))))) diff --git a/src/status_im/accounts/login/handlers.cljs b/src/status_im/accounts/login/handlers.cljs index df790b19b7..66f8f0902a 100644 --- a/src/status_im/accounts/login/handlers.cljs +++ b/src/status_im/accounts/login/handlers.cljs @@ -5,7 +5,7 @@ [status-im.utils.types :refer [json->clj]] [status-im.db :refer [default-view]] [status-im.persistence.realm.core :as realm] - [status-im.components.geth :as geth])) + [status-im.components.status :as status])) (defn set-login-from-qr @@ -48,12 +48,12 @@ :login-account (u/side-effect! (fn [db [_ address password]] - (geth/login address password - (fn [result] - (let [data (json->clj result) - error (:error data) - success (zero? (count error))] - (log/debug "Logged in account: ") - (if success - (logged-in db address) - (dispatch [:set-in [:login :error] error])))))))) \ No newline at end of file + (status/login address password + (fn [result] + (let [data (json->clj result) + error (:error data) + success (zero? (count error))] + (log/debug "Logged in account: ") + (if success + (logged-in db address) + (dispatch [:set-in [:login :error] error])))))))) \ No newline at end of file diff --git a/src/status_im/accounts/recover/handlers.cljs b/src/status_im/accounts/recover/handlers.cljs index 81cb14a734..e97a168d46 100644 --- a/src/status_im/accounts/recover/handlers.cljs +++ b/src/status_im/accounts/recover/handlers.cljs @@ -1,10 +1,8 @@ (ns status-im.accounts.recover.handlers (:require [re-frame.core :refer [register-handler after dispatch dispatch-sync]] - [status-im.components.geth :as geth] - [status-im.utils.handlers :as u] + [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.utils.identicon :refer [identicon]] - [status-im.chat.sign-up :as sign-up-service] [status-im.utils.logging :as log] [clojure.string :as str])) @@ -31,7 +29,7 @@ (defn recover-account [{:keys [recover] :as db} [_ passphrase password]] - (geth/recover-account passphrase password (fn [result] (account-recovered result password))) + (status/recover-account passphrase password (fn [result] (account-recovered result password))) db) (register-handler :recover-account recover-account) \ No newline at end of file diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 7681e112e4..1a3139dceb 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -32,7 +32,7 @@ [status-im.utils.encryption] status-im.persistence.realm.core [status-im.utils.logging :as log] - [status-im.components.jail :as j])) + [status-im.components.status :as status])) (defn init-back-button-handler! [] (let [new-listener (fn [] @@ -113,7 +113,7 @@ (dispatch-sync [:reset-app]) (dispatch [:initialize-crypt]) (dispatch [:initialize-geth]) - (j/set-soft-input-mode j/adjust-resize) + (status/set-soft-input-mode status/adjust-resize) (dispatch [:load-user-phone-number]) (init-back-button-handler!) (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index f9f8d5ec82..fe869c6be3 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -22,7 +22,7 @@ [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.utils.phone-number :refer [format-phone-number valid-mobile-number?]] - [status-im.components.jail :as j] + [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.chat.handlers.commands :refer [command-prefix]] [status-im.chat.utils :refer [console? not-console?]] @@ -413,9 +413,9 @@ (after (fn [{:keys [current-chat-id]} [_ mode chat-id]] (when (or (nil? chat-id) (= current-chat-id chat-id)) - (j/set-soft-input-mode (if (= :pan mode) - j/adjust-pan - j/adjust-resize))))) + (status/set-soft-input-mode (if (= :pan mode) + status/adjust-pan + status/adjust-resize))))) (fn [db [_ chat-id mode]] (assoc-in db [:kb-mode chat-id] mode))) diff --git a/src/status_im/chat/handlers/commands.cljs b/src/status_im/chat/handlers/commands.cljs index 76e7b78bbd..2990467f61 100644 --- a/src/status_im/chat/handlers/commands.cljs +++ b/src/status_im/chat/handlers/commands.cljs @@ -1,7 +1,7 @@ (ns status-im.chat.handlers.commands (:require [re-frame.core :refer [enrich after dispatch]] [status-im.utils.handlers :refer [register-handler] :as u] - [status-im.components.jail :as j] + [status-im.components.status :as status] [status-im.components.react :as r] [status-im.models.commands :as commands] [clojure.string :as str] @@ -30,12 +30,12 @@ 0 :suggestions] params {:value (content-by-command command content)}] - (j/call current-chat-id - path - params - #(dispatch [:suggestions-handler {:command command - :content content - :chat-id current-chat-id} %]))))) + (status/call-jail current-chat-id + path + params + #(dispatch [:suggestions-handler {:command command + :content content + :chat-id current-chat-id} %]))))) (defn cancel-command! [{:keys [canceled-command]}] @@ -69,10 +69,10 @@ name :preview] params {:value content}] - (j/call chat-id - path - params - #(dispatch [:command-preview chat-id id %])))) + (status/call-jail chat-id + path + params + #(dispatch [:command-preview chat-id id %])))) (defn command-input ([{:keys [current-chat-id] :as db}] @@ -106,10 +106,10 @@ :validator] params {:value content :command data}] - (j/call chat-id - path - params - #(dispatch [::validate! data %])))) + (status/call-jail chat-id + path + params + #(dispatch [::validate! data %])))) (register-handler :stage-command (after start-validate!) diff --git a/src/status_im/chat/handlers/send_message.cljs b/src/status_im/chat/handlers/send_message.cljs index 3bb9a5fb71..02e29f9d06 100644 --- a/src/status_im/chat/handlers/send_message.cljs +++ b/src/status_im/chat/handlers/send_message.cljs @@ -2,7 +2,7 @@ (:require [status-im.utils.handlers :refer [register-handler] :as u] [clojure.string :as s] [status-im.models.messages :as messages] - [status-im.components.jail :as j] + [status-im.components.status :as status] [status-im.utils.random :as random] [status-im.utils.datetime :as time] [re-frame.core :refer [enrich after debug dispatch path]] @@ -146,10 +146,10 @@ params {:value content :command {:from address :to to}}] - (j/call chat-id - path - params - #(dispatch [:command-handler! chat-id parameters %])))))) + (status/call-jail chat-id + path + params + #(dispatch [:command-handler! chat-id parameters %])))))) (register-handler ::prepare-message (u/side-effect! diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index 1b485f0f60..11031286ba 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -2,7 +2,7 @@ (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] - [status-im.components.jail :as j] + [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [generate-hiccup reg-handler]] [clojure.string :as s] @@ -10,8 +10,8 @@ (defn init-render-command! [_ [chat-id command message-id data]] - (j/call chat-id [command :render] data - #(dispatch [::render-command chat-id message-id %]))) + (status/call-jail chat-id [command :render] data + #(dispatch [::render-command chat-id message-id %]))) (defn render-command [db [chat-id message-id markup]] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index f3d874e876..e81057d51d 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -5,7 +5,7 @@ [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] [status-im.persistence.realm.core :as realm] - [status-im.components.jail :as j] + [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [reg-handler]])) @@ -54,12 +54,12 @@ (hash file)) (defn parse-commands! [_ [identity file]] - (j/parse identity file - (fn [result] - (let [{:keys [error result]} (json->clj result)] - (if error - (dispatch [::loading-failed! identity ::error-in-jail error]) - (dispatch [::add-commands identity file result])))))) + (status/parse-jail identity file + (fn [result] + (let [{:keys [error result]} (json->clj result)] + (if error + (dispatch [::loading-failed! identity ::error-in-jail error]) + (dispatch [::add-commands identity file result])))))) (defn validate-hash [db [identity file]] diff --git a/src/status_im/components/geth.cljs b/src/status_im/components/geth.cljs deleted file mode 100644 index 5ede7e3b68..0000000000 --- a/src/status_im/components/geth.cljs +++ /dev/null @@ -1,31 +0,0 @@ -(ns status-im.components.geth - (:require [status-im.components.react :as r] - [re-frame.core :refer [dispatch]])) - -(def geth - (when (exists? (.-NativeModules r/react-native)) - (.-Geth (.-NativeModules r/react-native)))) - -(.addListener r/device-event-emitter "gethEvent" - #(dispatch [:signal-event (.-jsonEvent %)])) - -(defn start-node [on-result on-already-running] - (when geth - (.startNode geth on-result on-already-running))) - -(defn create-account [password on-result] - (when geth - (.createAccount geth password on-result))) - -(defn recover-account [passphrase password on-result] - (when geth - (.recoverAccount geth passphrase password on-result))) - -(defn login [address password on-result] - (when geth - (.login geth address password on-result))) - -(defn complete-transaction - [hash password callback] - (when geth - (.completeTransaction geth hash password callback))) diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs deleted file mode 100644 index 4e2f896d62..0000000000 --- a/src/status_im/components/jail.cljs +++ /dev/null @@ -1,36 +0,0 @@ -(ns status-im.components.jail - (:require-macros [status-im.utils.slurp :refer [slurp]]) - (:require [status-im.components.react :as r] - [status-im.utils.types :as t])) - -(def status-js (slurp "resources/status.js")) - -(def jail - (when (exists? (.-NativeModules r/react-native)) - (.-Jail (.-NativeModules r/react-native)))) - -(when jail - (.init jail status-js)) - -(defn parse [chat-id file callback] - (when jail - (.parse jail chat-id file callback))) - -(defn cljs->json [data] - (.stringify js/JSON (clj->js data))) - -(defn call [chat-id path params callback] - (when jail - (println :call chat-id (cljs->json path) (cljs->json params)) - (let [cb (fn [r] - (let [r' (t/json->clj r)] - (println r') - (callback r')))] - (.call jail chat-id (cljs->json path) (cljs->json params) cb)))) - -(defn set-soft-input-mode [mode] - (when jail - (.setSoftInputMode jail mode))) - -(def adjust-resize 16) -(def adjust-pan 32) diff --git a/src/status_im/components/status.cljs b/src/status_im/components/status.cljs new file mode 100644 index 0000000000..ff21d8a5dd --- /dev/null +++ b/src/status_im/components/status.cljs @@ -0,0 +1,62 @@ +(ns status-im.components.status + (:require-macros [status-im.utils.slurp :refer [slurp]]) + (:require [status-im.components.react :as r] + [status-im.utils.types :as t] + [re-frame.core :refer [dispatch]] + [status-im.utils.logging :as log])) + +(def status-js (slurp "resources/status.js")) + +(def status + (when (exists? (.-NativeModules r/react-native)) + (.-Status (.-NativeModules r/react-native)))) + +(when status + (.initJail status status-js #(log/debug "jail initialized"))) + +(.addListener r/device-event-emitter "gethEvent" + #(dispatch [:signal-event (.-jsonEvent %)])) + +(defn start-node [on-result on-already-running] + (when status + (.startNode status on-result on-already-running))) + +(defn create-account [password on-result] + (when status + (.createAccount status password on-result))) + +(defn recover-account [passphrase password on-result] + (when status + (.recoverAccount status passphrase password on-result))) + +(defn login [address password on-result] + (when status + (.login status address password on-result))) + +(defn complete-transaction + [hash password callback] + (when status + (.completeTransaction status hash password callback))) + +(defn parse-jail [chat-id file callback] + (when status + (.parseJail status chat-id file callback))) + +(defn cljs->json [data] + (.stringify js/JSON (clj->js data))) + +(defn call-jail [chat-id path params callback] + (when status + (println :call chat-id (cljs->json path) (cljs->json params)) + (let [cb (fn [r] + (let [r' (t/json->clj r)] + (println r') + (callback r')))] + (.callJail status chat-id (cljs->json path) (cljs->json params) cb)))) + +(defn set-soft-input-mode [mode] + (when status + (.setSoftInputMode status mode))) + +(def adjust-resize 16) +(def adjust-pan 32) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index d1829af700..88f71b8881 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -8,7 +8,7 @@ [status-im.protocol.state.storage :as storage] [status-im.utils.logging :as log] [status-im.utils.crypt :refer [gen-random-bytes]] - [status-im.components.geth :as geth] + [status-im.components.status :as status] [status-im.utils.handlers :refer [register-handler] :as u] status-im.chat.handlers status-im.group-settings.handlers @@ -112,8 +112,8 @@ (u/side-effect! (fn [db _] (log/debug "Starting node") - (geth/start-node (fn [result] (node-started db result)) - #(log/debug "Geth already initialized"))))) + (status/start-node (fn [result] (node-started db result)) + #(log/debug "Geth already initialized"))))) (register-handler :crypt-initialized (u/side-effect! diff --git a/src/status_im/transactions/handlers.cljs b/src/status_im/transactions/handlers.cljs index e2c47498f7..74b6ff5933 100644 --- a/src/status_im/transactions/handlers.cljs +++ b/src/status_im/transactions/handlers.cljs @@ -4,7 +4,7 @@ [status-im.navigation.handlers :as nav] [status-im.utils.handlers :as u] [status-im.utils.types :as t] - [status-im.components.geth :as g] + [status-im.components.status :as status] cljsjs.web3 [clojure.string :as s])) @@ -18,7 +18,7 @@ (do ;(dispatch [:set :wrong-password? false]) (doseq [hash hashes] - (g/complete-transaction + (status/complete-transaction hash password #(dispatch [:transaction-completed hash %])))