closes #446
This commit is contained in:
parent
353d50d6bf
commit
0ce43593aa
|
@ -21,14 +21,15 @@
|
||||||
[status-im.navigation.handlers :as nav]))
|
[status-im.navigation.handlers :as nav]))
|
||||||
|
|
||||||
|
|
||||||
(defn save-account [_ [_ account]]
|
(defn save-account [{:keys [network]} [_ account]]
|
||||||
(accounts-store/save account true))
|
(accounts-store/save (assoc account :network network) true))
|
||||||
|
|
||||||
(register-handler
|
(register-handler
|
||||||
:add-account
|
:add-account
|
||||||
((after save-account)
|
((after save-account)
|
||||||
(fn [db [_ {:keys [address] :as account}]]
|
(fn [{:keys [network] :as db} [_ {:keys [address] :as account}]]
|
||||||
(update db :accounts assoc address account))))
|
(let [account' (assoc account :network network)]
|
||||||
|
(update db :accounts assoc address account')))))
|
||||||
|
|
||||||
(defn account-created [result password]
|
(defn account-created [result password]
|
||||||
(let [data (json->clj result)
|
(let [data (json->clj result)
|
||||||
|
|
|
@ -34,5 +34,5 @@
|
||||||
|
|
||||||
(defn migration [_ new-realm]
|
(defn migration [_ new-realm]
|
||||||
(let [new-objs (.objects new-realm "chat")]
|
(let [new-objs (.objects new-realm "chat")]
|
||||||
(dotimes [i (range (.-length new-objs))]
|
(dotimes [i (.-length new-objs)]
|
||||||
(aset (aget new-objs i) "pending-contact?" false))))
|
(aset (aget new-objs i) "pending-contact?" false))))
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
(ns status-im.data-store.realm.schemas.base.core
|
(ns status-im.data-store.realm.schemas.base.core
|
||||||
(:require [status-im.data-store.realm.schemas.base.v1.core :as v1]))
|
(:require [status-im.data-store.realm.schemas.base.v1.core :as v1]
|
||||||
|
[status-im.data-store.realm.schemas.base.v2.core :as v2]))
|
||||||
|
|
||||||
; put schemas ordered by version
|
; put schemas ordered by version
|
||||||
(def schemas [{:schema v1/schema
|
(def schemas [{:schema v1/schema
|
||||||
:schemaVersion 1
|
:schemaVersion 1
|
||||||
:migration v1/migration}])
|
:migration v1/migration}
|
||||||
|
{:schema v2/schema
|
||||||
|
:schemaVersion 2
|
||||||
|
:migration v2/migration}])
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
(ns status-im.data-store.realm.schemas.base.v2.account
|
||||||
|
(:require [taoensso.timbre :as log]))
|
||||||
|
|
||||||
|
(def schema {:name :account
|
||||||
|
:primaryKey :address
|
||||||
|
:properties {:address :string
|
||||||
|
:public-key :string
|
||||||
|
:updates-public-key {:type :string
|
||||||
|
:optional true}
|
||||||
|
:updates-private-key {:type :string
|
||||||
|
:optional true}
|
||||||
|
:name {:type :string :optional true}
|
||||||
|
:phone {:type :string :optional true}
|
||||||
|
:email {:type :string :optional true}
|
||||||
|
:status {:type :string :optional true}
|
||||||
|
:photo-path :string
|
||||||
|
:last-updated {:type :int :default 0}
|
||||||
|
:signed-up? {:type :bool
|
||||||
|
:default false}
|
||||||
|
:network {:type :string}}})
|
||||||
|
|
||||||
|
(defn migration [old-realm new-realm]
|
||||||
|
(log/debug "migrating account schema v2")
|
||||||
|
(let [new-objs (.objects new-realm "account")]
|
||||||
|
(dotimes [i (.-length new-objs)]
|
||||||
|
(aset (aget new-objs i) "network" "testnet"))))
|
|
@ -0,0 +1,11 @@
|
||||||
|
(ns status-im.data-store.realm.schemas.base.v2.core
|
||||||
|
(:require [status-im.data-store.realm.schemas.base.v2.account :as account]
|
||||||
|
[status-im.data-store.realm.schemas.base.v1.kv-store :as kv-store]
|
||||||
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
|
(def schema [account/schema
|
||||||
|
kv-store/schema])
|
||||||
|
|
||||||
|
(defn migration [old-realm new-realm]
|
||||||
|
(log/debug "migrating v2 base database: " old-realm new-realm)
|
||||||
|
(account/migration old-realm new-realm))
|
|
@ -23,7 +23,8 @@
|
||||||
status-im.transactions.handlers
|
status-im.transactions.handlers
|
||||||
status-im.network.handlers
|
status-im.network.handlers
|
||||||
[status-im.utils.types :as t]
|
[status-im.utils.types :as t]
|
||||||
[status-im.constants :refer [console-chat-id]]))
|
[status-im.constants :refer [console-chat-id]]
|
||||||
|
[status-im.utils.ethereum-network :as enet]))
|
||||||
|
|
||||||
;; -- Common --------------------------------------------------------------
|
;; -- Common --------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -42,12 +43,15 @@
|
||||||
(assoc-in db [:animations k] v)))
|
(assoc-in db [:animations k] v)))
|
||||||
|
|
||||||
(register-handler :initialize-db
|
(register-handler :initialize-db
|
||||||
(fn [{:keys [status-module-initialized?]} _]
|
(fn [{:keys [status-module-initialized? network]} _]
|
||||||
(data-store/init)
|
(data-store/init)
|
||||||
(let [db' (assoc app-db :current-account-id nil)]
|
(cond-> (assoc app-db :current-account-id nil)
|
||||||
(if status-module-initialized?
|
|
||||||
(assoc db' :status-module-initialized? true)
|
status-module-initialized?
|
||||||
db'))))
|
(assoc :status-module-initialized? true)
|
||||||
|
|
||||||
|
true
|
||||||
|
(assoc :network network))))
|
||||||
|
|
||||||
(register-handler :initialize-account-db
|
(register-handler :initialize-account-db
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
|
@ -97,7 +101,8 @@
|
||||||
(dispatch [:crypt-initialized]))))))))
|
(dispatch [:crypt-initialized]))))))))
|
||||||
|
|
||||||
(defn node-started [db result]
|
(defn node-started [db result]
|
||||||
(log/debug "Started Node: "))
|
(log/debug "Started Node")
|
||||||
|
(enet/get-network #(dispatch [:set :network %])))
|
||||||
|
|
||||||
(register-handler :initialize-geth
|
(register-handler :initialize-geth
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
blocks-per-hour]]
|
blocks-per-hour]]
|
||||||
[status-im.i18n :refer [label]]
|
[status-im.i18n :refer [label]]
|
||||||
[status-im.utils.random :as random]
|
[status-im.utils.random :as random]
|
||||||
[taoensso.timbre :as log :refer-macros [debug]]))
|
[taoensso.timbre :as log :refer-macros [debug]]
|
||||||
|
[status-im.constants :as c]))
|
||||||
|
|
||||||
(register-handler :initialize-protocol
|
(register-handler :initialize-protocol
|
||||||
(fn [db [_ current-account-id]]
|
(fn [db [_ current-account-id]]
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
(get-in db [:accounts current-account-id])]
|
(get-in db [:accounts current-account-id])]
|
||||||
(let [groups (chats/get-active-group-chats)
|
(let [groups (chats/get-active-group-chats)
|
||||||
w3 (protocol/init-whisper!
|
w3 (protocol/init-whisper!
|
||||||
{:rpc-url "http://localhost:8545"
|
{:rpc-url c/ethereum-rpc-url
|
||||||
:identity public-key
|
:identity public-key
|
||||||
:groups groups
|
:groups groups
|
||||||
:callback #(dispatch [:incoming-message %1 %2])
|
:callback #(dispatch [:incoming-message %1 %2])
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
(ns status-im.utils.ethereum-network
|
||||||
|
(:require [status-im.constants :as c]))
|
||||||
|
|
||||||
|
(def Web3 (js/require "web3"))
|
||||||
|
|
||||||
|
(defn web3 []
|
||||||
|
(->> (Web3.providers.HttpProvider. c/ethereum-rpc-url)
|
||||||
|
(Web3.)))
|
||||||
|
|
||||||
|
(def networks
|
||||||
|
{"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" :mainnet
|
||||||
|
"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303" :testnet
|
||||||
|
;; Ropsten
|
||||||
|
"0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d" :testnet})
|
||||||
|
|
||||||
|
(defn- on-block [callback]
|
||||||
|
(fn [error block]
|
||||||
|
(when-not error
|
||||||
|
(let [hash (.-hash block)]
|
||||||
|
(callback (networks hash :unknown))))))
|
||||||
|
|
||||||
|
(defn get-network [callback]
|
||||||
|
(.eth.getBlock (web3) 0 false (on-block callback)))
|
Loading…
Reference in New Issue