integrate status-go initKeystore native call

- avoids having to start a node before login
This commit is contained in:
yenda 2019-07-31 18:10:38 +02:00
parent 5e3d2d4625
commit d2f1bbeb16
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
11 changed files with 83 additions and 29 deletions

View File

@ -191,6 +191,7 @@ var TopLevel = {
"index" : function () {},
"indexOf" : function () {},
"init" : function () {},
"initKeystore" : function () {},
"injectJavaScript" : function () {},
"installApplet" : function () {},
"installAppletAndInitCard" : function () {},

View File

@ -352,6 +352,28 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
callback.invoke();
}
@ReactMethod
private void initKeystore() {
Activity currentActivity = getCurrentActivity();
final String keydir = currentActivity.getApplicationInfo().dataDir;
Log.d(TAG, "initKeystore");
if (!checkAvailability()) {
Log.e(TAG, "[initKeystore] Activity doesn't exist, cannot init keystore");
System.exit(0);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
Statusgo.initKeystore(keydir);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void startNode(final String config) {
Log.d(TAG, "startNode");

View File

@ -128,6 +128,12 @@ void RCTStatus::stopNode() {
logStatusGoResult("::stopNode StopNode", result);
}
void RCTStatus::initKeystore() {
aCInfo(RCTSTATUS) << "::initKeystore call";
QString rootDirPath = getDataStoragePath();
const char* result = initKeystore(rootDirPath);
logStatusGoResult("::initKeystore InitKeystore", result);
}
void RCTStatus::createAccount(QString password, double callbackId) {
Q_D(RCTStatus);

View File

@ -35,6 +35,7 @@ public:
QList<ModuleMethod*> methodsToExport() override;
QVariantMap constantsToExport() override;
Q_INVOKABLE void initKeystore();
Q_INVOKABLE void startNode(QString configString);
Q_INVOKABLE void stopNode();
Q_INVOKABLE void createAccount(QString password, double callbackId);

View File

@ -200,6 +200,28 @@ RCT_EXPORT_METHOD(stopNode) {
});
}
////////////////////////////////////////////////////////////////////
#pragma mark - InitKeystore method
//////////////////////////////////////////////////////////////////// StopNode
RCT_EXPORT_METHOD(initKeystore) {
#if DEBUG
NSLog(@"initKeystore() method called");
#endif
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
lastObject];
NSURL *keystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^(void)
{
NSString *res = StatusgoInitKeystore(keystoreDir.path);
NSLog(@"StopNode result %@", res);
});
}
////////////////////////////////////////////////////////////////////
#pragma mark - Accounts method
//////////////////////////////////////////////////////////////////// createAccount

View File

@ -67,6 +67,7 @@
(fx/merge cofx
{:init/get-device-UUID nil
:init/get-supported-biometric-auth nil
:init/init-keystore nil
:init/restore-native-settings nil
:ui/listen-to-window-dimensions-change nil
:notifications/init nil
@ -257,6 +258,11 @@
:init/restore-native-settings
restore-native-settings!)
(re-frame/reg-fx
:init/init-keystore
(fn []
(status/init-keystore)))
(re-frame/reg-fx
:init/get-device-UUID
(fn []

View File

@ -166,15 +166,10 @@
(fx/merge {:db (dissoc db :intro-wizard)}
(navigation/navigate-to-cofx :home nil)))
(fx/defn init-key-generation [{:keys [db] :as cofx}]
(let [node-started? (= :started (:node/status db))]
(fx/merge
{:db (-> db
(assoc-in [:intro-wizard :generating-keys?] true)
(assoc :node/on-ready :start-onboarding))}
(if node-started?
{:intro-wizard/start-onboarding nil}
(node/initialize nil)))))
(fx/defn init-key-generation
[{:keys [db] :as cofx}]
{:db (assoc-in db [:intro-wizard :generating-keys?] true)
:intro-wizard/start-onboarding nil})
(fx/defn on-confirm-failure [{:keys [db] :as cofx}]
(do

View File

@ -3,6 +3,9 @@
(def adjust-resize 16)
(defn init-keystore []
(native-module/init-keystore))
(defn start-node [config]
(native-module/start-node config))

View File

@ -10,6 +10,9 @@
(when (exists? (.-NativeModules rn-dependencies/react-native))
(.-Status (.-NativeModules rn-dependencies/react-native))))
(defn init-keystore []
(.initKeystore (status)))
(defonce listener-initialized (atom false))
(when-not @listener-initialized
@ -63,13 +66,12 @@
(.recoverAccount (status) passphrase password on-result)))
(defn multiaccount-generate-and-derive-addresses [n mnemonic-length paths on-result]
(when (and @node-started (status))
(.multiAccountGenerateAndDeriveAddresses (status)
(types/clj->json {:n n
:mnemonicPhraseLength mnemonic-length
:bip39Passphrase ""
:paths paths})
on-result)))
(.multiAccountGenerateAndDeriveAddresses (status)
(types/clj->json {:n n
:mnemonicPhraseLength mnemonic-length
:bip39Passphrase ""
:paths paths})
on-result))
(defn multiaccount-derive-addresses [account-id paths on-result]
(when (and @node-started (status))
@ -98,13 +100,12 @@
on-result)))
(defn multiaccount-store-derived [account-id paths password on-result]
(when (and @node-started (status))
(.multiAccountStoreDerived (status)
(types/clj->json {:accountID account-id
:paths paths
:password password})
(.multiAccountStoreDerived (status)
(types/clj->json {:accountID account-id
:paths paths
:password password})
on-result)))
on-result))
(defn multiaccount-import-mnemonic [mnemonic password on-result]
(when (and @node-started (status))

View File

@ -42,10 +42,7 @@
:import-mnemonic
(multiaccounts.recover/import-mnemonic)
:create-keycard-multiaccount
(hardwallet/create-keycard-multiaccount)
:start-onboarding
(fn []
{:intro-wizard/start-onboarding nil})))))
(hardwallet/create-keycard-multiaccount)))))
(fx/defn status-node-stopped
[{db :db}]

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "06dc227071708d10988203de8b3787362d5f40d1",
"commit-sha1": "06dc227071708d10988203de8b3787362d5f40d1",
"src-sha256": "1imf5rb35938vwmi96yas9lykcrd2r487kv0di6dj4cz590vx8ws"
"version": "develop",
"commit-sha1": "be9c55bc16ca035ca9bfc0586b6c9298a91bdcd4",
"src-sha256": "1a499mi1xg1ryl8bjg0kiww6s1vdykhrl11sk0h649ajfcaak1jb"
}