replace last remains of web3.js by json-rpc
This commit is contained in:
parent
d61fffb021
commit
1c475e5b1e
|
@ -103,7 +103,7 @@
|
||||||
chat-props)]
|
chat-props)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (update-in db [:chats chat-id] merge chat)}
|
{:db (update-in db [:chats chat-id] merge chat)}
|
||||||
(chats-store/save-chat-rpc chat))))
|
(chats-store/save-chat chat))))
|
||||||
|
|
||||||
(fx/defn add-public-chat
|
(fx/defn add-public-chat
|
||||||
"Adds new public group chat to db & realm"
|
"Adds new public group chat to db & realm"
|
||||||
|
@ -149,7 +149,7 @@
|
||||||
:unviewed-messages-count 0
|
:unviewed-messages-count 0
|
||||||
:deleted-at-clock-value last-message-clock-value})}
|
:deleted-at-clock-value last-message-clock-value})}
|
||||||
(messages-store/delete-messages-by-chat-id chat-id)
|
(messages-store/delete-messages-by-chat-id chat-id)
|
||||||
#(chats-store/save-chat-rpc % (get-in % [:db :chats chat-id])))))
|
#(chats-store/save-chat % (get-in % [:db :chats chat-id])))))
|
||||||
|
|
||||||
(fx/defn deactivate-chat
|
(fx/defn deactivate-chat
|
||||||
[{:keys [db now] :as cofx} chat-id]
|
[{:keys [db now] :as cofx} chat-id]
|
||||||
|
@ -157,7 +157,7 @@
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-in [:chats chat-id :is-active] false)
|
(assoc-in [:chats chat-id :is-active] false)
|
||||||
(assoc-in [:current-chat-id] nil))}
|
(assoc-in [:current-chat-id] nil))}
|
||||||
#(chats-store/save-chat-rpc % (get-in % [:db :chats chat-id]))))
|
#(chats-store/save-chat % (get-in % [:db :chats chat-id]))))
|
||||||
|
|
||||||
(fx/defn remove-chat
|
(fx/defn remove-chat
|
||||||
"Removes chat completely from app, producing all necessary effects for that"
|
"Removes chat completely from app, producing all necessary effects for that"
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
(fx/defn add-received-message
|
(fx/defn add-received-message
|
||||||
[{:keys [db] :as cofx}
|
[{:keys [db] :as cofx}
|
||||||
{:keys [from message-id chat-id js-obj content metadata] :as raw-message}]
|
{:keys [from message-id chat-id js-obj content metadata] :as raw-message}]
|
||||||
(let [{:keys [web3 current-chat-id view-id]} db
|
(let [{:keys [current-chat-id view-id]} db
|
||||||
current-public-key (multiaccounts.model/current-public-key cofx)
|
current-public-key (multiaccounts.model/current-public-key cofx)
|
||||||
current-chat? (and (or (= :chat view-id)
|
current-chat? (and (or (= :chat view-id)
|
||||||
(= :chat-modal view-id))
|
(= :chat-modal view-id))
|
||||||
|
|
|
@ -50,11 +50,9 @@
|
||||||
(fx/defn notify-user
|
(fx/defn notify-user
|
||||||
"Send an empty message to the user, which will carry device information"
|
"Send an empty message to the user, which will carry device information"
|
||||||
[cofx public-key]
|
[cofx public-key]
|
||||||
(let [{:keys [web3]} (:db cofx)
|
(let [current-public-key (multiaccounts.model/current-public-key cofx)]
|
||||||
current-public-key (multiaccounts.model/current-public-key cofx)]
|
|
||||||
{:shh/send-direct-message
|
{:shh/send-direct-message
|
||||||
[{:web3 web3
|
[{:src current-public-key
|
||||||
:src current-public-key
|
|
||||||
:dst public-key
|
:dst public-key
|
||||||
:payload ""}]}))
|
:payload ""}]}))
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
(assoc :group-chat-local-version 1) ;; TODO(cammellos): this can be removed
|
(assoc :group-chat-local-version 1) ;; TODO(cammellos): this can be removed
|
||||||
(dissoc :chatType :members)))
|
(dissoc :chatType :members)))
|
||||||
|
|
||||||
(fx/defn save-chat-rpc [cofx {:keys [chat-id] :as chat}]
|
(fx/defn save-chat [cofx {:keys [chat-id] :as chat}]
|
||||||
{::json-rpc/call [{:method "shhext_saveChat"
|
{::json-rpc/call [{:method "shhext_saveChat"
|
||||||
:params [(->rpc chat)]
|
:params [(->rpc chat)]
|
||||||
:on-success #(log/debug "saved chat" chat-id "successfuly")
|
:on-success #(log/debug "saved chat" chat-id "successfuly")
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
(defn supports?
|
(defn supports?
|
||||||
"Calls cb with true if `supportsInterface` is supported by this contract.
|
"Calls cb with true if `supportsInterface` is supported by this contract.
|
||||||
See EIP for details."
|
See EIP for details."
|
||||||
[web3 contract cb]
|
[contract cb]
|
||||||
(supports-interface?
|
(supports-interface?
|
||||||
contract
|
contract
|
||||||
supports-interface-hash
|
supports-interface-hash
|
||||||
|
|
|
@ -26,6 +26,13 @@
|
||||||
"eth_syncing" {}
|
"eth_syncing" {}
|
||||||
"net_version" {}
|
"net_version" {}
|
||||||
"web3_clientVersion" {}
|
"web3_clientVersion" {}
|
||||||
|
"shhext_post" {}
|
||||||
|
"shh_generateSymKeyFromPassword" {}
|
||||||
|
"shh_getSymKey" {}
|
||||||
|
"shh_markTrustedPeer" {}
|
||||||
|
"shhext_requestMessages" {}
|
||||||
|
"shhext_sendDirectMessage" {}
|
||||||
|
"shhext_sendPublicMessage" {}
|
||||||
"shhext_enableInstallation" {}
|
"shhext_enableInstallation" {}
|
||||||
"shhext_disableInstallation" {}
|
"shhext_disableInstallation" {}
|
||||||
"shhext_getOurInstallations" {}
|
"shhext_getOurInstallations" {}
|
||||||
|
|
|
@ -65,7 +65,6 @@
|
||||||
[status-im.wallet.core :as wallet]
|
[status-im.wallet.core :as wallet]
|
||||||
[status-im.wallet.custom-tokens.core :as custom-tokens]
|
[status-im.wallet.custom-tokens.core :as custom-tokens]
|
||||||
[status-im.wallet.db :as wallet.db]
|
[status-im.wallet.db :as wallet.db]
|
||||||
[status-im.web3.core :as web3]
|
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.chat.commands.sending :as commands.sending]
|
[status-im.chat.commands.sending :as commands.sending]
|
||||||
[status-im.utils.money :as money]
|
[status-im.utils.money :as money]
|
||||||
|
|
|
@ -120,7 +120,6 @@
|
||||||
creator (extract-creator chat)
|
creator (extract-creator chat)
|
||||||
members (clojure.set/union (get-in cofx [:db :chats chat-id :contacts])
|
members (clojure.set/union (get-in cofx [:db :chats chat-id :contacts])
|
||||||
removed-members)
|
removed-members)
|
||||||
{:keys [web3]} (:db cofx)
|
|
||||||
current-public-key (multiaccounts.model/current-public-key cofx)
|
current-public-key (multiaccounts.model/current-public-key cofx)
|
||||||
members-allowed (filter
|
members-allowed (filter
|
||||||
(fn [pk]
|
(fn [pk]
|
||||||
|
@ -134,8 +133,7 @@
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
{:shh/send-group-message
|
{:shh/send-group-message
|
||||||
{:web3 web3
|
{:src current-public-key
|
||||||
:src current-public-key
|
|
||||||
:dsts destinations
|
:dsts destinations
|
||||||
:success-event [:transport/message-sent
|
:success-event [:transport/message-sent
|
||||||
chat-id
|
chat-id
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[status-im.transport.db :as transport.db]
|
[status-im.transport.db :as transport.db]
|
||||||
[status-im.transport.message.protocol :as protocol]
|
[status-im.transport.message.protocol :as protocol]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
[status-im.mailserver.topics :as mailserver.topics]
|
[status-im.mailserver.topics :as mailserver.topics]
|
||||||
[status-im.mailserver.constants :as constants]
|
[status-im.mailserver.constants :as constants]
|
||||||
[status-im.data-store.mailservers :as data-store.mailservers]
|
[status-im.data-store.mailservers :as data-store.mailservers]
|
||||||
|
@ -158,18 +159,15 @@
|
||||||
(reset! limit (decrease-limit))
|
(reset! limit (decrease-limit))
|
||||||
(reset! success-counter 0)))
|
(reset! success-counter 0)))
|
||||||
|
|
||||||
(defn mark-trusted-peer! [web3 enode]
|
(defn mark-trusted-peer! [enode]
|
||||||
(.markTrustedPeer (transport.utils/shh web3)
|
(json-rpc/call {:method "shh_markTrustedPeer"
|
||||||
enode
|
:params [enode]
|
||||||
(fn [error response]
|
:on-success #(re-frame/dispatch [:mailserver.callback/mark-trusted-peer-success %])
|
||||||
(if error
|
:on-error #(re-frame/dispatch [:mailserver.callback/mark-trusted-peer-error %])}))
|
||||||
(re-frame/dispatch [:mailserver.callback/mark-trusted-peer-error error])
|
|
||||||
(re-frame/dispatch [:mailserver.callback/mark-trusted-peer-success response])))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:mailserver/mark-trusted-peer
|
:mailserver/mark-trusted-peer
|
||||||
(fn [{:keys [address web3]}]
|
mark-trusted-peer!)
|
||||||
(mark-trusted-peer! web3 address)))
|
|
||||||
|
|
||||||
(fx/defn generate-mailserver-symkey
|
(fx/defn generate-mailserver-symkey
|
||||||
[{:keys [db] :as cofx} {:keys [password id] :as mailserver}]
|
[{:keys [db] :as cofx} {:keys [password id] :as mailserver}]
|
||||||
|
@ -177,7 +175,6 @@
|
||||||
{:db (assoc-in db [:mailserver/mailservers current-fleet id :generating-sym-key?] true)
|
{:db (assoc-in db [:mailserver/mailservers current-fleet id :generating-sym-key?] true)
|
||||||
:shh/generate-sym-key-from-password
|
:shh/generate-sym-key-from-password
|
||||||
[{:password password
|
[{:password password
|
||||||
:web3 (:web3 db)
|
|
||||||
:on-success (fn [_ sym-key-id]
|
:on-success (fn [_ sym-key-id]
|
||||||
(re-frame/dispatch [:mailserver.callback/generate-mailserver-symkey-success mailserver sym-key-id]))
|
(re-frame/dispatch [:mailserver.callback/generate-mailserver-symkey-success mailserver sym-key-id]))
|
||||||
:on-error #(log/error "mailserver: get-sym-key error" %)}]}))
|
:on-error #(log/error "mailserver: get-sym-key error" %)}]}))
|
||||||
|
@ -196,8 +193,7 @@
|
||||||
(let [{:keys [address sym-key-id generating-sym-key?] :as mailserver} (fetch-current cofx)]
|
(let [{:keys [address sym-key-id generating-sym-key?] :as mailserver} (fetch-current cofx)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (update-mailserver-state db :added)
|
{:db (update-mailserver-state db :added)
|
||||||
:mailserver/mark-trusted-peer {:web3 (:web3 db)
|
:mailserver/mark-trusted-peer address}
|
||||||
:address address}}
|
|
||||||
(when-not (or sym-key-id generating-sym-key?)
|
(when-not (or sym-key-id generating-sym-key?)
|
||||||
(generate-mailserver-symkey mailserver)))))
|
(generate-mailserver-symkey mailserver)))))
|
||||||
|
|
||||||
|
@ -297,7 +293,8 @@
|
||||||
(assoc-in [:mailserver/current-request :request-id] request-id))}
|
(assoc-in [:mailserver/current-request :request-id] request-id))}
|
||||||
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))))
|
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))))
|
||||||
|
|
||||||
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from force-to?] :as request}]
|
(defn request-messages!
|
||||||
|
[{:keys [sym-key-id address]} {:keys [topics cursor to from force-to?] :as request}]
|
||||||
;; Add some room to from, unless we break day boundaries so that messages that have
|
;; Add some room to from, unless we break day boundaries so that messages that have
|
||||||
;; been received after the last request are also fetched
|
;; been received after the last request are also fetched
|
||||||
(let [actual-from (adjust-request-for-transit-time from)
|
(let [actual-from (adjust-request-for-transit-time from)
|
||||||
|
@ -311,8 +308,8 @@
|
||||||
" range " (- to from)
|
" range " (- to from)
|
||||||
" cursor " cursor
|
" cursor " cursor
|
||||||
" limit " actual-limit)
|
" limit " actual-limit)
|
||||||
(.requestMessages (transport.utils/shh web3)
|
(json-rpc/call {:method "shhext_requestMessages"
|
||||||
(clj->js (cond-> {:topics topics
|
:params [(cond-> {:topics topics
|
||||||
:mailServerPeer address
|
:mailServerPeer address
|
||||||
:symKeyID sym-key-id
|
:symKeyID sym-key-id
|
||||||
:timeout constants/request-timeout
|
:timeout constants/request-timeout
|
||||||
|
@ -320,21 +317,19 @@
|
||||||
:cursor cursor
|
:cursor cursor
|
||||||
:from actual-from}
|
:from actual-from}
|
||||||
force-to?
|
force-to?
|
||||||
(assoc :to to)))
|
(assoc :to to))]
|
||||||
(fn [error request-id]
|
:on-success (fn [request-id]
|
||||||
(if-not error
|
|
||||||
(do
|
|
||||||
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
|
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
|
||||||
(re-frame/dispatch [:mailserver.callback/request-success {:request-id request-id :topics topics}]))
|
(re-frame/dispatch [:mailserver.callback/request-success {:request-id request-id :topics topics}]))
|
||||||
(do
|
:on-error (fn [error]
|
||||||
(log/error "mailserver: messages request error for topic " topics ": " error)
|
(log/error "mailserver: messages request error for topic " topics ": " error)
|
||||||
(utils/set-timeout #(re-frame/dispatch [:mailserver.callback/resend-request {:request-id nil}])
|
(utils/set-timeout #(re-frame/dispatch [:mailserver.callback/resend-request {:request-id nil}])
|
||||||
constants/backoff-interval-ms)))))))
|
constants/backoff-interval-ms))})))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:mailserver/request-messages
|
:mailserver/request-messages
|
||||||
(fn [{:keys [web3 mailserver request]}]
|
(fn [{:keys [mailserver request]}]
|
||||||
(request-messages! web3 mailserver request)))
|
(request-messages! mailserver request)))
|
||||||
|
|
||||||
(defn get-mailserver-when-ready
|
(defn get-mailserver-when-ready
|
||||||
"return the mailserver if the mailserver is ready"
|
"return the mailserver if the mailserver is ready"
|
||||||
|
@ -399,16 +394,14 @@
|
||||||
(when-let [mailserver (get-mailserver-when-ready cofx)]
|
(when-let [mailserver (get-mailserver-when-ready cofx)]
|
||||||
(let [request-to (or (:mailserver/request-to db)
|
(let [request-to (or (:mailserver/request-to db)
|
||||||
(quot now 1000))
|
(quot now 1000))
|
||||||
requests (prepare-messages-requests cofx request-to)
|
requests (prepare-messages-requests cofx request-to)]
|
||||||
web3 (:web3 db)]
|
|
||||||
(log/debug "Mailserver: planned requests " requests)
|
(log/debug "Mailserver: planned requests " requests)
|
||||||
(if-let [request (first requests)]
|
(if-let [request (first requests)]
|
||||||
{:db (assoc db
|
{:db (assoc db
|
||||||
:mailserver/pending-requests (count requests)
|
:mailserver/pending-requests (count requests)
|
||||||
:mailserver/current-request request
|
:mailserver/current-request request
|
||||||
:mailserver/request-to request-to)
|
:mailserver/request-to request-to)
|
||||||
:mailserver/request-messages {:web3 web3
|
:mailserver/request-messages {:mailserver mailserver
|
||||||
:mailserver mailserver
|
|
||||||
:request request}}
|
:request request}}
|
||||||
{:db (dissoc db
|
{:db (dissoc db
|
||||||
:mailserver/pending-requests
|
:mailserver/pending-requests
|
||||||
|
@ -735,8 +728,7 @@
|
||||||
(when-let [mailserver (get-mailserver-when-ready cofx)]
|
(when-let [mailserver (get-mailserver-when-ready cofx)]
|
||||||
(let [request-with-cursor (assoc request :cursor cursor)]
|
(let [request-with-cursor (assoc request :cursor cursor)]
|
||||||
{:db (assoc db :mailserver/current-request request-with-cursor)
|
{:db (assoc db :mailserver/current-request request-with-cursor)
|
||||||
:mailserver/request-messages {:web3 (:web3 db)
|
:mailserver/request-messages {:mailserver mailserver
|
||||||
:mailserver mailserver
|
|
||||||
:request request-with-cursor}}))
|
:request request-with-cursor}}))
|
||||||
(let [{:keys [gap chat-id]} request]
|
(let [{:keys [gap chat-id]} request]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
|
@ -870,8 +862,7 @@
|
||||||
(not current-request)
|
(not current-request)
|
||||||
(-> (assoc-in [:db :mailserver/current-request] first-request)
|
(-> (assoc-in [:db :mailserver/current-request] first-request)
|
||||||
(assoc :mailserver/request-messages
|
(assoc :mailserver/request-messages
|
||||||
{:web3 (:web3 db)
|
{:mailserver mailserver
|
||||||
:mailserver mailserver
|
|
||||||
:request first-request})))))
|
:request first-request})))))
|
||||||
|
|
||||||
(fx/defn resend-request
|
(fx/defn resend-request
|
||||||
|
@ -905,13 +896,11 @@
|
||||||
(dissoc :mailserver/planned-gap-requests))}
|
(dissoc :mailserver/planned-gap-requests))}
|
||||||
|
|
||||||
mailserver
|
mailserver
|
||||||
(let [{:keys [topics from to cursor limit] :as request} current-request
|
(let [{:keys [topics from to cursor limit] :as request} current-request]
|
||||||
web3 (:web3 db)]
|
|
||||||
(log/info "mailserver: message request " request-id "expired for mailserver topic" topics "from" from "to" to "cursor" cursor "limit" (decrease-limit))
|
(log/info "mailserver: message request " request-id "expired for mailserver topic" topics "from" from "to" to "cursor" cursor "limit" (decrease-limit))
|
||||||
{:db (update-in db [:mailserver/current-request :attempts] inc)
|
{:db (update-in db [:mailserver/current-request :attempts] inc)
|
||||||
:mailserver/decrease-limit []
|
:mailserver/decrease-limit []
|
||||||
:mailserver/request-messages {:web3 web3
|
:mailserver/request-messages {:mailserver mailserver
|
||||||
:mailserver mailserver
|
|
||||||
:request (assoc request :limit (decrease-limit))}})
|
:request (assoc request :limit (decrease-limit))}})
|
||||||
|
|
||||||
:else
|
:else
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
[status-im.chat.models :as chat-model]
|
[status-im.chat.models :as chat-model]
|
||||||
[status-im.chat.models.loading :as chat.loading]
|
[status-im.chat.models.loading :as chat.loading]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
|
[status-im.data-store.core :as data-store]
|
||||||
[status-im.contact.core :as contact]
|
[status-im.contact.core :as contact]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
[status-im.utils.types :as types]
|
[status-im.utils.types :as types]
|
||||||
[status-im.utils.universal-links.core :as universal-links]
|
[status-im.utils.universal-links.core :as universal-links]
|
||||||
[status-im.wallet.core :as wallet]
|
[status-im.wallet.core :as wallet]
|
||||||
[status-im.web3.core :as web3]
|
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
(def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a")
|
(def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a")
|
||||||
|
@ -155,6 +155,7 @@
|
||||||
(let [stored-pns (:push-notifications/stored db)]
|
(let [stored-pns (:push-notifications/stored db)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc db :chats/loading? true)
|
{:db (assoc db :chats/loading? true)
|
||||||
|
::data-store/change-multiaccount [address password]
|
||||||
::json-rpc/call
|
::json-rpc/call
|
||||||
[{:method "browsers_getBrowsers"
|
[{:method "browsers_getBrowsers"
|
||||||
:on-success #(re-frame/dispatch [::initialize-browsers %])}
|
:on-success #(re-frame/dispatch [::initialize-browsers %])}
|
||||||
|
@ -177,7 +178,7 @@
|
||||||
(boolean (get-in cofx [:db :multiaccounts/recover])))
|
(boolean (get-in cofx [:db :multiaccounts/recover])))
|
||||||
|
|
||||||
(fx/defn create-only-events
|
(fx/defn create-only-events
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx} address password]
|
||||||
(let [{:keys [multiaccount]} db]
|
(let [{:keys [multiaccount]} db]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (assoc db
|
{:db (assoc db
|
||||||
|
@ -191,6 +192,7 @@
|
||||||
:filters/initialized 1
|
:filters/initialized 1
|
||||||
:network constants/default-network
|
:network constants/default-network
|
||||||
:networks/networks constants/default-networks)
|
:networks/networks constants/default-networks)
|
||||||
|
::data-store/create-multiaccount [address password]
|
||||||
:filters/load-filters []
|
:filters/load-filters []
|
||||||
::json-rpc/call
|
::json-rpc/call
|
||||||
[{:method "settings_saveConfig"
|
[{:method "settings_saveConfig"
|
||||||
|
@ -222,9 +224,6 @@
|
||||||
:card-read-in-progress?
|
:card-read-in-progress?
|
||||||
:pin
|
:pin
|
||||||
:multiaccount))
|
:multiaccount))
|
||||||
;;TODO remove once web3 has been replaced by json-rpc in protocol
|
|
||||||
;; after this call realm and the protocol are initialized as a callback
|
|
||||||
::web3/initialize [address password login-only?]
|
|
||||||
::json-rpc/call
|
::json-rpc/call
|
||||||
[{:method "web3_clientVersion"
|
[{:method "web3_clientVersion"
|
||||||
:on-success #(re-frame/dispatch [::initialize-web3-client-version %])}]
|
:on-success #(re-frame/dispatch [::initialize-web3-client-version %])}]
|
||||||
|
@ -235,7 +234,7 @@
|
||||||
(initialize-multiaccount-db address)
|
(initialize-multiaccount-db address)
|
||||||
(if login-only?
|
(if login-only?
|
||||||
(login-only-events address password save-password?)
|
(login-only-events address password save-password?)
|
||||||
(create-only-events))
|
(create-only-events address password))
|
||||||
(when recovering?
|
(when recovering?
|
||||||
(navigation/navigate-to-cofx :home nil)))))
|
(navigation/navigate-to-cofx :home nil)))))
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
;; Publish updates every 48 hours
|
;; Publish updates every 48 hours
|
||||||
(def publish-updates-interval (* 48 60 60 1000))
|
(def publish-updates-interval (* 48 60 60 1000))
|
||||||
|
|
||||||
(defn publish-update! [{:keys [db now web3]}]
|
(defn publish-update! [{:keys [db now]}]
|
||||||
(let [my-public-key (get-in db [:multiaccount :public-key])
|
(let [my-public-key (get-in db [:multiaccount :public-key])
|
||||||
peers-count (:peers-count db)
|
peers-count (:peers-count db)
|
||||||
last-updated (get-in
|
last-updated (get-in
|
||||||
|
@ -21,18 +21,14 @@
|
||||||
payload (multiaccounts/multiaccount-update-message {:db db})
|
payload (multiaccounts/multiaccount-update-message {:db db})
|
||||||
sync-message (pairing/sync-installation-multiaccount-message {:db db})]
|
sync-message (pairing/sync-installation-multiaccount-message {:db db})]
|
||||||
(doseq [pk public-keys]
|
(doseq [pk public-keys]
|
||||||
(shh/send-direct-message!
|
(shh/send-direct-message! {:pubKey pk
|
||||||
web3
|
|
||||||
{:pubKey pk
|
|
||||||
:sig my-public-key
|
:sig my-public-key
|
||||||
:chat constants/contact-discovery
|
:chat constants/contact-discovery
|
||||||
:payload payload}
|
:payload payload}
|
||||||
[:multiaccounts.update.callback/published]
|
[:multiaccounts.update.callback/published]
|
||||||
[:multiaccounts.update.callback/failed-to-publish]
|
[:multiaccounts.update.callback/failed-to-publish]
|
||||||
1))
|
1))
|
||||||
(shh/send-direct-message!
|
(shh/send-direct-message! {:pubKey my-public-key
|
||||||
web3
|
|
||||||
{:pubKey my-public-key
|
|
||||||
:sig my-public-key
|
:sig my-public-key
|
||||||
:chat constants/contact-discovery
|
:chat constants/contact-discovery
|
||||||
:payload sync-message}
|
:payload sync-message}
|
||||||
|
|
|
@ -193,13 +193,13 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:node/les-show-debug-info
|
:node/les-show-debug-info
|
||||||
(fn [[web3 multiaccount chain-sync-state]]
|
(fn [[multiaccount chain-sync-state]]
|
||||||
(.getBalance
|
#_(.getBalance
|
||||||
(.-eth web3)
|
(.-eth eb3)
|
||||||
(:address multiaccount)
|
(:address multiaccount)
|
||||||
(fn [error-balance balance]
|
(fn [error-balance balance]
|
||||||
(.getBlockNumber
|
(.getBlockNumber
|
||||||
(.-eth web3)
|
(.-eth eb3)
|
||||||
(fn
|
(fn
|
||||||
[error-block block]
|
[error-block block]
|
||||||
(utils/show-popup
|
(utils/show-popup
|
||||||
|
@ -211,5 +211,5 @@
|
||||||
"* eth_getSyncing=" (or chain-sync-state "false")))))))))
|
"* eth_getSyncing=" (or chain-sync-state "false")))))))))
|
||||||
|
|
||||||
(defn display-les-debug-info
|
(defn display-les-debug-info
|
||||||
[{{:keys [web3 multiaccount] :node/keys [chain-sync-state]} :db}]
|
[{{:keys [multiaccount] :node/keys [chain-sync-state]} :db}]
|
||||||
{:node/les-show-debug-info [web3 multiaccount]})
|
{:node/les-show-debug-info [multiaccount]})
|
||||||
|
|
|
@ -73,14 +73,13 @@
|
||||||
(protocol/send (transport.pairing/PairInstallation. installation-id device-type installation-name fcm-token) nil cofx)))
|
(protocol/send (transport.pairing/PairInstallation. installation-id device-type installation-name fcm-token) nil cofx)))
|
||||||
|
|
||||||
(fx/defn confirm-message-processed
|
(fx/defn confirm-message-processed
|
||||||
[{:keys [db]} confirmation]
|
[cofx confirmation]
|
||||||
{:transport/confirm-messages-processed [confirmation]})
|
{:transport/confirm-messages-processed [confirmation]})
|
||||||
|
|
||||||
(defn send-pair-installation [cofx payload]
|
(defn send-pair-installation
|
||||||
(let [{:keys [web3]} (:db cofx)
|
[cofx payload]
|
||||||
current-public-key (multiaccounts.model/current-public-key cofx)]
|
(let [current-public-key (multiaccounts.model/current-public-key cofx)]
|
||||||
{:shh/send-pairing-message {:web3 web3
|
{:shh/send-pairing-message {:src current-public-key
|
||||||
:src current-public-key
|
|
||||||
:payload payload}}))
|
:payload payload}}))
|
||||||
|
|
||||||
(defn merge-contact [local remote]
|
(defn merge-contact [local remote]
|
||||||
|
@ -263,12 +262,11 @@
|
||||||
:pairing/get-our-installations
|
:pairing/get-our-installations
|
||||||
get-our-installations)
|
get-our-installations)
|
||||||
|
|
||||||
(fx/defn send-sync-installation [cofx payload]
|
(fx/defn send-sync-installation
|
||||||
(let [{:keys [web3]} (:db cofx)
|
[cofx payload]
|
||||||
current-public-key (multiaccounts.model/current-public-key cofx)]
|
(let [current-public-key (multiaccounts.model/current-public-key cofx)]
|
||||||
{:shh/send-direct-message
|
{:shh/send-direct-message
|
||||||
[{:web3 web3
|
[{:src current-public-key
|
||||||
:src current-public-key
|
|
||||||
:dst current-public-key
|
:dst current-public-key
|
||||||
:payload payload}]}))
|
:payload payload}]}))
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
(fx/defn init-whisper
|
(fx/defn init-whisper
|
||||||
"Initialises whisper protocol by:
|
"Initialises whisper protocol by:
|
||||||
- (optionally) initializing mailserver"
|
- (optionally) initializing mailserver"
|
||||||
[{:keys [db web3] :as cofx}]
|
[cofx]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(fetch-node-info-fx)
|
(fetch-node-info-fx)
|
||||||
(pairing/init)
|
(pairing/init)
|
||||||
|
|
|
@ -13,13 +13,8 @@
|
||||||
[status-im.transport.utils :as transport.utils]
|
[status-im.transport.utils :as transport.utils]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.ethereum.json-rpc :as json-rpc]))
|
||||||
(defn confirm-messages [confirmations]
|
|
||||||
(json-rpc/call {:method "shhext_confirmMessagesProcessedByID"
|
|
||||||
:params [confirmations]
|
|
||||||
:on-success #(log/debug "successfully confirmed messages")
|
|
||||||
:on-failure #(log/error "failed to confirm messages" %)}))
|
|
||||||
|
|
||||||
(defn add-raw-payload
|
(defn add-raw-payload
|
||||||
"Add raw payload for id calculation"
|
"Add raw payload for id calculation"
|
||||||
|
@ -218,4 +213,7 @@
|
||||||
:transport/confirm-messages-processed
|
:transport/confirm-messages-processed
|
||||||
(fn [confirmations]
|
(fn [confirmations]
|
||||||
(when (seq confirmations)
|
(when (seq confirmations)
|
||||||
(confirm-messages confirmations))))
|
(json-rpc/call {:method "shhext_confirmMessagesProcessedByID"
|
||||||
|
:params [confirmations]
|
||||||
|
:on-success #(log/debug "successfully confirmed messages")
|
||||||
|
:on-failure #(log/error "failed to confirm messages" %)}))))
|
||||||
|
|
|
@ -49,32 +49,27 @@
|
||||||
|
|
||||||
(defn send-public-message
|
(defn send-public-message
|
||||||
"Sends the payload to topic"
|
"Sends the payload to topic"
|
||||||
[{:keys [db] :as cofx} chat-id success-event payload]
|
[cofx chat-id success-event payload]
|
||||||
(let [{:keys [web3]} db]
|
{:shh/send-public-message [{:success-event success-event
|
||||||
{:shh/send-public-message [{:web3 web3
|
|
||||||
:success-event success-event
|
|
||||||
:src (multiaccounts.model/current-public-key cofx)
|
:src (multiaccounts.model/current-public-key cofx)
|
||||||
:chat chat-id
|
:chat chat-id
|
||||||
:payload payload}]}))
|
:payload payload}]})
|
||||||
|
|
||||||
(fx/defn send-direct-message
|
(fx/defn send-direct-message
|
||||||
"Sends the payload using to dst"
|
"Sends the payload using to dst"
|
||||||
[{:keys [db] :as cofx} dst success-event payload]
|
[cofx dst success-event payload]
|
||||||
(let [{:keys [web3]} db]
|
{:shh/send-direct-message [{:success-event success-event
|
||||||
{:shh/send-direct-message [{:web3 web3
|
|
||||||
:success-event success-event
|
|
||||||
:src (multiaccounts.model/current-public-key cofx)
|
:src (multiaccounts.model/current-public-key cofx)
|
||||||
:dst dst
|
:dst dst
|
||||||
:payload payload}]}))
|
:payload payload}]})
|
||||||
|
|
||||||
(fx/defn send-with-pubkey
|
(fx/defn send-with-pubkey
|
||||||
"Sends the payload using asymetric key (multiaccount `:public-key` in db) and fixed discovery topic"
|
"Sends the payload using asymetric key (multiaccount `:public-key` in db) and fixed discovery topic"
|
||||||
[{:keys [db] :as cofx} {:keys [payload chat-id success-event]}]
|
[cofx {:keys [payload chat-id success-event]}]
|
||||||
(let [{:keys [web3]} db]
|
|
||||||
(send-direct-message cofx
|
(send-direct-message cofx
|
||||||
chat-id
|
chat-id
|
||||||
success-event
|
success-event
|
||||||
payload)))
|
payload))
|
||||||
|
|
||||||
(defrecord Message [content content-type message-type clock-value timestamp]
|
(defrecord Message [content content-type message-type clock-value timestamp]
|
||||||
StatusMessage
|
StatusMessage
|
||||||
|
|
|
@ -4,115 +4,106 @@
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.transport.message.transit :as transit]
|
[status-im.transport.message.transit :as transit]
|
||||||
[status-im.transport.utils :as transport.utils]
|
[status-im.transport.utils :as transport.utils]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.ethereum.json-rpc :as json-rpc]))
|
||||||
|
|
||||||
(defn generate-sym-key-from-password
|
(defn generate-sym-key-from-password
|
||||||
[{:keys [web3 password on-success on-error]}]
|
[{:keys [password on-success on-error]}]
|
||||||
(.. web3
|
(json-rpc/call {:method "shh_generateSymKeyFromPassword"
|
||||||
-shh
|
:params [password]
|
||||||
(generateSymKeyFromPassword password (fn [err resp]
|
:on-success on-success
|
||||||
(if-not err
|
:on-error on-error}))
|
||||||
(on-success resp)
|
|
||||||
(on-error err))))))
|
|
||||||
|
|
||||||
(defn post-message
|
(defn post-message
|
||||||
[{:keys [web3 whisper-message on-success on-error]}]
|
[{:keys [whisper-message on-success on-error]}]
|
||||||
(.. web3
|
(json-rpc/call {:method "shh_generateSymKeyFromPassword"
|
||||||
-shh
|
:params [whisper-message]
|
||||||
(extPost (clj->js whisper-message) (fn [err resp]
|
:on-success on-success
|
||||||
(if-not err
|
:on-error on-error}))
|
||||||
(on-success resp)
|
|
||||||
(on-error err))))))
|
|
||||||
|
|
||||||
(defn handle-response [success-event error-event messages-count]
|
(defn send-direct-message!
|
||||||
(fn [err resp]
|
[direct-message success-event error-event messages-count]
|
||||||
(if-not err
|
(json-rpc/call {:method "shhext_sendDirectMessage"
|
||||||
(if success-event
|
:params [(update direct-message :payload (comp ethereum/utf8-to-hex
|
||||||
(re-frame/dispatch (conj success-event resp messages-count))
|
transit/serialize))]
|
||||||
|
:on-success #(if success-event
|
||||||
|
(re-frame/dispatch (conj success-event % messages-count))
|
||||||
(log/debug :shh/post-success))
|
(log/debug :shh/post-success))
|
||||||
(re-frame/dispatch [error-event err resp]))))
|
:on-error #(re-frame/dispatch [error-event %])}))
|
||||||
|
|
||||||
(defn send-direct-message! [web3 direct-message success-event error-event count]
|
|
||||||
(.. web3
|
|
||||||
-shh
|
|
||||||
(sendDirectMessage
|
|
||||||
(clj->js (update direct-message :payload (comp ethereum/utf8-to-hex
|
|
||||||
transit/serialize)))
|
|
||||||
(handle-response success-event error-event count))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/send-direct-message
|
:shh/send-direct-message
|
||||||
(fn [post-calls]
|
(fn [post-calls]
|
||||||
(doseq [{:keys [web3 payload src dst success-event error-event]
|
(doseq [{:keys [payload src dst success-event error-event]
|
||||||
:or {error-event :transport/send-status-message-error}} post-calls]
|
:or {error-event :transport/send-status-message-error}} post-calls]
|
||||||
(let [direct-message {:pubKey dst
|
(let [direct-message {:pubKey dst
|
||||||
:sig src
|
:sig src
|
||||||
:payload payload}]
|
:payload payload}]
|
||||||
(send-direct-message! web3 direct-message success-event error-event 1)))))
|
(send-direct-message! direct-message success-event error-event 1)))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/send-pairing-message
|
:shh/send-pairing-message
|
||||||
(fn [params]
|
(fn [params]
|
||||||
(let [{:keys [web3 payload src success-event error-event]
|
(let [{:keys [payload src success-event error-event]
|
||||||
:or {error-event :transport/send-status-message-error}} params
|
:or {error-event :transport/send-status-message-error}} params]
|
||||||
message (clj->js {:sig src
|
(json-rpc/call {:method "shhext_sendDirectMessage"
|
||||||
|
:params [{:sig src
|
||||||
:pubKey src
|
:pubKey src
|
||||||
;; Send to any device
|
;; Send to any device
|
||||||
:DH true
|
:DH true
|
||||||
:payload (-> payload
|
:payload (-> payload
|
||||||
transit/serialize
|
transit/serialize
|
||||||
ethereum/utf8-to-hex)})]
|
ethereum/utf8-to-hex)}]
|
||||||
(.. web3
|
:on-success #(if success-event
|
||||||
-shh
|
(re-frame/dispatch (conj success-event % 1))
|
||||||
(sendDirectMessage
|
(log/debug :shh/post-success))
|
||||||
message
|
:on-error #(re-frame/dispatch [error-event %])}))))
|
||||||
(handle-response success-event error-event 1))))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/send-group-message
|
:shh/send-group-message
|
||||||
(fn [params]
|
(fn [params]
|
||||||
(let [{:keys [web3 payload src dsts success-event error-event]
|
(let [{:keys [payload src dsts success-event error-event]
|
||||||
:or {error-event :transport/send-status-message-error}} params]
|
:or {error-event :transport/send-status-message-error}} params
|
||||||
(doseq [{:keys [public-key chat]} dsts]
|
payload (-> payload
|
||||||
(let [message
|
|
||||||
(clj->js {:pubKey public-key
|
|
||||||
:sig src
|
|
||||||
:payload (-> payload
|
|
||||||
transit/serialize
|
transit/serialize
|
||||||
ethereum/utf8-to-hex)})]
|
ethereum/utf8-to-hex)]
|
||||||
|
(doseq [{:keys [public-key chat]} dsts]
|
||||||
|
(let [message {:pubKey public-key
|
||||||
|
:sig src
|
||||||
|
:payload payload}]
|
||||||
|
(json-rpc/call {:method "shhext_sendDirectMessage"
|
||||||
|
:params [message]
|
||||||
|
:on-success #(if success-event
|
||||||
|
(re-frame/dispatch (conj success-event % (count dsts)))
|
||||||
|
(log/debug :shh/post-success))
|
||||||
|
:on-error #(re-frame/dispatch [error-event %])}))))))
|
||||||
|
|
||||||
(.. web3
|
(defn send-public-message! [message success-event error-event]
|
||||||
-shh
|
(json-rpc/call {:method "shhext_sendPublicMessage"
|
||||||
(sendDirectMessage
|
:params [message]
|
||||||
message
|
:on-success #(if success-event
|
||||||
(handle-response success-event error-event (count dsts)))))))))
|
(re-frame/dispatch (conj success-event % 1))
|
||||||
|
(log/debug :shh/post-success))
|
||||||
(defn send-public-message! [web3 message success-event error-event]
|
:on-error #(re-frame/dispatch [error-event %])}))
|
||||||
(.. web3
|
|
||||||
-shh
|
|
||||||
(sendPublicMessage
|
|
||||||
(clj->js message)
|
|
||||||
(handle-response success-event error-event 1))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/send-public-message
|
:shh/send-public-message
|
||||||
(fn [post-calls]
|
(fn [post-calls]
|
||||||
(doseq [{:keys [web3 payload src chat success-event error-event]
|
(doseq [{:keys [payload src chat success-event error-event]
|
||||||
:or {error-event :transport/send-status-message-error}} post-calls]
|
:or {error-event :transport/send-status-message-error}} post-calls]
|
||||||
(let [message {:chat chat
|
(let [message {:chat chat
|
||||||
:sig src
|
:sig src
|
||||||
:payload (-> payload
|
:payload (-> payload
|
||||||
transit/serialize
|
transit/serialize
|
||||||
ethereum/utf8-to-hex)}]
|
ethereum/utf8-to-hex)}]
|
||||||
(send-public-message! web3 message success-event error-event)))))
|
(send-public-message! message success-event error-event)))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/post
|
:shh/post
|
||||||
(fn [post-calls]
|
(fn [post-calls]
|
||||||
(doseq [{:keys [web3 message success-event error-event]
|
(doseq [{:keys [message success-event error-event]
|
||||||
:or {error-event :transport/send-status-message-error}} post-calls]
|
:or {error-event :transport/send-status-message-error}} post-calls]
|
||||||
(post-message {:web3 web3
|
(post-message {:whisper-message (update message :payload (comp ethereum/utf8-to-hex
|
||||||
:whisper-message (update message :payload (comp ethereum/utf8-to-hex
|
|
||||||
transit/serialize))
|
transit/serialize))
|
||||||
:on-success (if success-event
|
:on-success (if success-event
|
||||||
#(re-frame/dispatch (conj success-event % 1))
|
#(re-frame/dispatch (conj success-event % 1))
|
||||||
|
@ -120,13 +111,11 @@
|
||||||
:on-error #(re-frame/dispatch [error-event %])}))))
|
:on-error #(re-frame/dispatch [error-event %])}))))
|
||||||
|
|
||||||
(defn get-sym-key
|
(defn get-sym-key
|
||||||
[{:keys [web3 sym-key-id on-success on-error]}]
|
[{:keys [sym-key-id on-success on-error]}]
|
||||||
(.. web3
|
(json-rpc/call {:method "shh_getSymKey"
|
||||||
-shh
|
:params [sym-key-id]
|
||||||
(getSymKey sym-key-id (fn [err resp]
|
:on-success on-success
|
||||||
(if-not err
|
:on-error on-error}))
|
||||||
(on-success resp)
|
|
||||||
(on-error err))))))
|
|
||||||
|
|
||||||
(defn log-error [error]
|
(defn log-error [error]
|
||||||
(log/error :shh/get-new-sym-key-error error))
|
(log/error :shh/get-new-sym-key-error error))
|
||||||
|
@ -134,12 +123,10 @@
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/generate-sym-key-from-password
|
:shh/generate-sym-key-from-password
|
||||||
(fn [args]
|
(fn [args]
|
||||||
(doseq [{:keys [web3 password on-success]} args]
|
(doseq [{:keys [password on-success]} args]
|
||||||
(generate-sym-key-from-password {:web3 web3
|
(generate-sym-key-from-password {:password password
|
||||||
:password password
|
|
||||||
:on-success (fn [sym-key-id]
|
:on-success (fn [sym-key-id]
|
||||||
(get-sym-key {:web3 web3
|
(get-sym-key {:sym-key-id sym-key-id
|
||||||
:sym-key-id sym-key-id
|
|
||||||
:on-success (fn [sym-key]
|
:on-success (fn [sym-key]
|
||||||
(on-success sym-key sym-key-id))
|
(on-success sym-key sym-key-id))
|
||||||
:on-error log-error}))
|
:on-error log-error}))
|
||||||
|
|
|
@ -20,9 +20,6 @@
|
||||||
[chat-id]
|
[chat-id]
|
||||||
(subs (ethereum/sha3 chat-id) 0 10))
|
(subs (ethereum/sha3 chat-id) 0 10))
|
||||||
|
|
||||||
(defn shh [web3]
|
|
||||||
(.-shh web3))
|
|
||||||
|
|
||||||
(defn extract-enode-id [enode]
|
(defn extract-enode-id [enode]
|
||||||
(-> enode
|
(-> enode
|
||||||
(string/split #"/")
|
(string/split #"/")
|
||||||
|
|
|
@ -10,14 +10,13 @@
|
||||||
(def sync-interval-ms 120000)
|
(def sync-interval-ms 120000)
|
||||||
(def sync-timeout-ms 20000)
|
(def sync-timeout-ms 20000)
|
||||||
|
|
||||||
(defn- start-publisher! [web3]
|
(defn- start-publisher! []
|
||||||
(when @polling-executor
|
(when @polling-executor
|
||||||
(async-util/async-periodic-stop! @polling-executor))
|
(async-util/async-periodic-stop! @polling-executor))
|
||||||
(reset! polling-executor
|
(reset! polling-executor
|
||||||
(async-util/async-periodic-exec
|
(async-util/async-periodic-exec
|
||||||
(fn [done-fn]
|
(fn [done-fn]
|
||||||
(let [cofx {:web3 web3
|
(let [cofx {:now (datetime/timestamp)
|
||||||
:now (datetime/timestamp)
|
|
||||||
:db @re-frame.db/app-db}]
|
:db @re-frame.db/app-db}]
|
||||||
(multiaccounts/publish-update! cofx)
|
(multiaccounts/publish-update! cofx)
|
||||||
(done-fn)))
|
(done-fn)))
|
||||||
|
@ -26,15 +25,17 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::start-publisher
|
::start-publisher
|
||||||
#(start-publisher! %))
|
start-publisher!)
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::stop-publisher
|
::stop-publisher
|
||||||
#(when @polling-executor
|
#(when @polling-executor
|
||||||
(async-util/async-periodic-stop! @polling-executor)))
|
(async-util/async-periodic-stop! @polling-executor)))
|
||||||
|
|
||||||
(fx/defn start-fx [{:keys [web3]}]
|
(fx/defn start-fx
|
||||||
{::start-publisher web3})
|
[cofx]
|
||||||
|
{::start-publisher nil})
|
||||||
|
|
||||||
(fx/defn stop-fx [cofx]
|
(fx/defn stop-fx
|
||||||
|
[cofx]
|
||||||
{::stop-publisher []})
|
{::stop-publisher []})
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
(ns status-im.web3.core
|
|
||||||
(:require [status-im.ethereum.core :as ethereum]
|
|
||||||
[status-im.js-dependencies :as dependencies]
|
|
||||||
[status-im.native-module.core :as status]
|
|
||||||
[taoensso.timbre :as log]
|
|
||||||
[status-im.data-store.core :as data-store]
|
|
||||||
[re-frame.core :as re-frame]
|
|
||||||
[status-im.utils.handlers :as handlers]
|
|
||||||
[status-im.utils.fx :as fx]))
|
|
||||||
|
|
||||||
(defn make-internal-web3
|
|
||||||
"This Web3 object will allow access to private RPC calls
|
|
||||||
It should be only used for internal application needs and never provided to any
|
|
||||||
3rd parties (DApps, etc)"
|
|
||||||
[]
|
|
||||||
(let [Web3 (dependencies/Web3)]
|
|
||||||
(Web3.
|
|
||||||
#js {:sendAsync (fn [payload callback]
|
|
||||||
(status/call-private-rpc
|
|
||||||
(.stringify js/JSON payload)
|
|
||||||
(fn [response]
|
|
||||||
(if (= "" response)
|
|
||||||
(log/warn :web3-response-error)
|
|
||||||
(callback nil (.parse js/JSON response))))))})))
|
|
||||||
|
|
||||||
(fx/defn initialization-success
|
|
||||||
{:events [::initialization-success]}
|
|
||||||
[{:keys [db]} web3 address password login?]
|
|
||||||
{:db (assoc db :web3 web3)
|
|
||||||
(if login?
|
|
||||||
::data-store/change-multiaccount
|
|
||||||
::data-store/create-multiaccount) [address password]})
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::initialize
|
|
||||||
(fn [[address password login?]]
|
|
||||||
(let [web3 (make-internal-web3)]
|
|
||||||
(set! (.-defaultAccount (.-eth web3))
|
|
||||||
(ethereum/normalized-address address))
|
|
||||||
(re-frame/dispatch [::initialization-success web3 address password login?]))))
|
|
|
@ -30,7 +30,7 @@
|
||||||
(testing "send contact request & message"
|
(testing "send contact request & message"
|
||||||
(run-test-async
|
(run-test-async
|
||||||
(let [web3 (make-web3)
|
(let [web3 (make-web3)
|
||||||
shh (transport.utils/shh web3)
|
shh (.-shh web3)
|
||||||
from (create-keys shh)]
|
from (create-keys shh)]
|
||||||
(reset! re-frame.db/app-db {:web3 web3
|
(reset! re-frame.db/app-db {:web3 web3
|
||||||
:multiaccount {:public-key from}})
|
:multiaccount {:public-key from}})
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
(testing "Whisper version supported"
|
(testing "Whisper version supported"
|
||||||
(async done
|
(async done
|
||||||
(let [web3 (make-web3)
|
(let [web3 (make-web3)
|
||||||
shh (transport.utils/shh web3)]
|
shh (.-shh web3)]
|
||||||
(.version shh
|
(.version shh
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(is (= "6.0" (second args)))
|
(is (= "6.0" (second args)))
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
[status-im.events :as events]
|
[status-im.events :as events]
|
||||||
[status-im.data-store.core :as data-store]
|
[status-im.data-store.core :as data-store]
|
||||||
[status-im.multiaccounts.login.core :as login.core]
|
[status-im.multiaccounts.login.core :as login.core]
|
||||||
[status-im.web3.core :as web3]
|
|
||||||
[status-im.signals.core :as signals]
|
[status-im.signals.core :as signals]
|
||||||
[status-im.test.sign-in.data :as data]))
|
[status-im.test.sign-in.data :as data]))
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@
|
||||||
(testing ":accounts/login cleared."
|
(testing ":accounts/login cleared."
|
||||||
(is (not (contains? new-db :multiaccounts/login))))
|
(is (not (contains? new-db :multiaccounts/login))))
|
||||||
(testing "Check the rest of effects."
|
(testing "Check the rest of effects."
|
||||||
(is (contains? efx ::web3/initialize))
|
(is (contains? efx ::data-store/change-multiaccount))
|
||||||
(is (json-rpc "web3_clientVersion"))))))
|
(is (json-rpc "web3_clientVersion"))))))
|
||||||
|
|
||||||
;;TODO re-enable when keycard is fixed
|
;;TODO re-enable when keycard is fixed
|
||||||
|
|
Loading…
Reference in New Issue