support new geth methods to create and update identity
This commit is contained in:
parent
4e9c22c9fc
commit
1155575f11
|
@ -21,7 +21,8 @@
|
|||
make-msg
|
||||
post-msg
|
||||
make-web3
|
||||
new-identity
|
||||
create-identity
|
||||
add-identity
|
||||
stop-listener]]
|
||||
[syng-im.protocol.handler :refer [handle-incoming-whisper-msg]]
|
||||
[syng-im.protocol.user-handler :refer [invoke-user-handler]]
|
||||
|
@ -38,9 +39,6 @@
|
|||
(defn create-connection [ethereum-rpc-url]
|
||||
(make-web3 ethereum-rpc-url))
|
||||
|
||||
(defn create-identity [connection]
|
||||
(new-identity connection))
|
||||
|
||||
(defn my-identity []
|
||||
(state/my-identity))
|
||||
|
||||
|
@ -73,10 +71,14 @@
|
|||
(set-handler handler)
|
||||
(go
|
||||
(let [connection (create-connection ethereum-rpc-url)
|
||||
identity (or identity
|
||||
(<! (create-identity connection)))]
|
||||
{:keys [public private] :as identity} (if identity
|
||||
(do
|
||||
(<! (->> (:private identity)
|
||||
(add-identity connection)))
|
||||
identity)
|
||||
(<! (create-identity connection)))]
|
||||
(set-connection connection)
|
||||
(set-identity identity)
|
||||
(set-identity public)
|
||||
(listen connection handle-incoming-whisper-msg)
|
||||
(start-delivery-loop)
|
||||
(doseq [group-id active-group-ids]
|
||||
|
|
|
@ -45,6 +45,38 @@
|
|||
(.newIdentity (.-shh web3) callback)
|
||||
result-channel))
|
||||
|
||||
(defn create-identity [web3]
|
||||
(let [result-channel (chan)]
|
||||
(.sendAsync (.-currentProvider web3)
|
||||
(clj->js [{:jsonrpc "2.0" :method "shh_createIdentity" :params [] :id 99999999999}])
|
||||
(fn [error result]
|
||||
(if error
|
||||
(do
|
||||
(log/error (str "Call to shh_createIdentity failed" ":") error)
|
||||
(invoke-user-handler :error {:error-msg "Call to shh_createIdentity failed"
|
||||
:details error}))
|
||||
(let [[public private] (-> (js->clj result :keywordize-keys true)
|
||||
(first)
|
||||
:result)]
|
||||
(put! result-channel {:public public
|
||||
:private private})))
|
||||
(close! result-channel)))
|
||||
result-channel))
|
||||
|
||||
(defn add-identity [web3 private-key]
|
||||
(let [result-channel (chan)]
|
||||
(.sendAsync (.-currentProvider web3)
|
||||
(clj->js [{:jsonrpc "2.0" :method "shh_addIdentity" :params [private-key] :id 99999999999}])
|
||||
(fn [error result]
|
||||
(if error
|
||||
(do
|
||||
(log/error (str "Call to shh_addIdentity failed" ":") error)
|
||||
(invoke-user-handler :error {:error-msg "Call to shh_addIdentity failed"
|
||||
:details error}))
|
||||
(put! result-channel (js->clj result)))
|
||||
(close! result-channel)))
|
||||
result-channel))
|
||||
|
||||
(defn post-msg [web3 msg]
|
||||
(let [js-msg (clj->js msg)]
|
||||
(log/info "Sending whisper message:" js-msg)
|
||||
|
|
|
@ -5,17 +5,22 @@
|
|||
(defn timestamp []
|
||||
(tf/unparse (:hour-minute-second-fraction tf/formatters) (t/now)))
|
||||
|
||||
(defn to-js [args]
|
||||
(->> (cons (timestamp) args)
|
||||
(mapv clj->js)
|
||||
(into-array)))
|
||||
|
||||
(defn debug [& args]
|
||||
(.apply (.-log js/console) js/console (to-js args)))
|
||||
|
||||
(defn info [& args]
|
||||
(let [args (cons (timestamp) args)]
|
||||
(.apply (.-log js/console) js/console (into-array args))))
|
||||
(.apply (.-log js/console) js/console (to-js args)))
|
||||
|
||||
(defn warn [& args]
|
||||
(let [args (cons (timestamp) args)]
|
||||
(.apply (.-warn js/console) js/console (into-array args))))
|
||||
(.apply (.-warn js/console) js/console (to-js args)))
|
||||
|
||||
(defn error [& args]
|
||||
(let [args (cons (timestamp) args)]
|
||||
(.apply (.-error js/console) js/console (into-array args))))
|
||||
(.apply (.-error js/console) js/console (to-js args)))
|
||||
|
||||
|
||||
(comment
|
||||
|
|
|
@ -217,11 +217,16 @@
|
|||
;(p/make-whisper-msg web3-2 user2-ident user1-ident "Hello World!")
|
||||
|
||||
|
||||
(require '[syng-im.protocol.whisper :as w])
|
||||
(require '[syng-im.protocol.web3 :as w])
|
||||
(def web3 (w/make-web3 "http://localhost:4546"))
|
||||
(.newIdentity (w/whisper web3) (fn [error result]
|
||||
(println error result)))
|
||||
|
||||
(.sendAsync (.-currentProvider web3)
|
||||
(clj->js [{:jsonrpc "2.0" :method "shh_addIdentity" :params ["0x585493cda18f2b4314afb51224e9c1e913780642783ca11e683a66cfaa9eec94"] :id 99999999999}])
|
||||
(fn [error result]
|
||||
(println error result)))
|
||||
|
||||
)
|
||||
|
||||
(comment
|
||||
|
|
Loading…
Reference in New Issue