[feature] use status-go signal subscriptions for current block
- use signal subscriptions to get latest block signals - compute confirmations in transaction details from current block dynamically Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
9b18f1d261
commit
65f05933bc
|
@ -1,3 +1,3 @@
|
|||
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
|
||||
|
||||
0cc4p735l979g2j7v6yvxni22d6a34v22b1ma5dsmdn0x9s88nkx
|
||||
0cj202bj2rwfrw327gibj8hj8i94ciyp3hkq2hck9l6711qlhpnb
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
|
||||
|
||||
v0.24.0-beta.1
|
||||
v0.25.0-beta.0
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.chaos-mode.core :as chaos-mode]
|
||||
[status-im.data-store.core :as data-store]
|
||||
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.models.transactions :as transactions]
|
||||
|
@ -84,6 +85,7 @@
|
|||
(fx/defn initialize-wallet [cofx]
|
||||
(fx/merge cofx
|
||||
(models.wallet/initialize-tokens)
|
||||
(ethereum.subscriptions/initialize)
|
||||
(models.wallet/update-wallet)
|
||||
(transactions/start-sync)))
|
||||
|
||||
|
@ -149,8 +151,8 @@
|
|||
(protocol/initialize-protocol)
|
||||
(universal-links/process-stored-event)
|
||||
(chaos-mode/check-chaos-mode)
|
||||
#(when-not platform/desktop?
|
||||
(initialize-wallet %)))
|
||||
(when-not platform/desktop?
|
||||
(initialize-wallet)))
|
||||
(account-and-db-password-do-not-match cofx error)))))
|
||||
|
||||
(fx/defn show-migration-error-dialog
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
(ns status-im.ethereum.decode
|
||||
(:require [status-im.utils.ethereum.abi-spec :as abi-spec]))
|
||||
|
||||
(defn uint
|
||||
[hex]
|
||||
(first (abi-spec/decode hex ["uint"])))
|
|
@ -0,0 +1,75 @@
|
|||
(ns status-im.ethereum.subscriptions
|
||||
(:require [clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.ethereum.decode :as decode]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.fx :as fx]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defn get-block-by-hash [block-hash callback]
|
||||
(status/call-private-rpc
|
||||
(.stringify js/JSON (clj->js {:jsonrpc "2.0"
|
||||
:id 1
|
||||
:method "eth_getBlockByHash"
|
||||
:params [block-hash false]}))
|
||||
(fn [response]
|
||||
(if (string/blank? response)
|
||||
(log/warn :web3-response-error)
|
||||
(callback (-> (.parse js/JSON response)
|
||||
(js->clj :keywordize-keys true)
|
||||
:result
|
||||
:number
|
||||
decode/uint))))))
|
||||
|
||||
(fx/defn handle-signal
|
||||
[cofx {:keys [subscription_id data] :as event}]
|
||||
(if-let [handler (get-in cofx [:db :ethereum/subscriptions subscription_id])]
|
||||
(handler data)
|
||||
(log/warn ::unknown-subscription :event event)))
|
||||
|
||||
(fx/defn register-subscription
|
||||
[{:keys [db]} id handler]
|
||||
{:db (assoc-in db [:ethereum/subscriptions id] handler)})
|
||||
|
||||
(fx/defn new-block
|
||||
[{:keys [db]} block-number]
|
||||
{:db (assoc-in db [:ethereum/current-block] block-number)})
|
||||
|
||||
(defn subscribe-signal
|
||||
[filter params callback]
|
||||
(status/call-private-rpc
|
||||
(.stringify js/JSON (clj->js {:jsonrpc "2.0"
|
||||
:id 1
|
||||
:method "eth_subscribeSignal"
|
||||
:params [filter, params]}))
|
||||
(fn [response]
|
||||
(if (string/blank? response)
|
||||
(log/error ::subscription-unknown-error :filter filter :params params)
|
||||
(let [{:keys [error result]}
|
||||
(-> (.parse js/JSON response)
|
||||
(js->clj :keywordize-keys true))]
|
||||
(if error
|
||||
(log/error ::subscription-error error :filter filter :params params)
|
||||
(re-frame/dispatch [:ethereum.callback/subscription-success
|
||||
result
|
||||
callback])))))))
|
||||
|
||||
(defn new-block-filter
|
||||
[]
|
||||
(subscribe-signal
|
||||
"eth_newBlockFilter" []
|
||||
(fn [[block-hash]]
|
||||
(get-block-by-hash
|
||||
block-hash
|
||||
(fn [block-number]
|
||||
(when block-number
|
||||
(re-frame/dispatch [:ethereum.signal/new-block
|
||||
block-number])))))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:ethereum.subscriptions/new-block-filter
|
||||
new-block-filter)
|
||||
|
||||
(fx/defn initialize
|
||||
[cofx]
|
||||
{:ethereum.subscriptions/new-block-filter nil})
|
|
@ -20,6 +20,7 @@
|
|||
[status-im.contact-recovery.core :as contact-recovery]
|
||||
[status-im.contact.block :as contact.block]
|
||||
[status-im.contact.core :as contact]
|
||||
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
||||
[status-im.extensions.core :as extensions]
|
||||
[status-im.extensions.registry :as extensions.registry]
|
||||
[status-im.fleet.core :as fleet]
|
||||
|
@ -2045,3 +2046,14 @@
|
|||
:bottom-sheet/hide-sheet
|
||||
(fn [cofx _]
|
||||
(bottom-sheet/hide-bottom-sheet cofx)))
|
||||
|
||||
;; ethereum subscriptions events
|
||||
(handlers/register-handler-fx
|
||||
:ethereum.callback/subscription-success
|
||||
(fn [cofx [_ id handler]]
|
||||
(ethereum.subscriptions/register-subscription cofx id handler)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:ethereum.signal/new-block
|
||||
(fn [cofx [_ block-number]]
|
||||
(ethereum.subscriptions/new-block cofx block-number)))
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
(ns status-im.signals.core
|
||||
(:require [status-im.accounts.db :as accounts.db]
|
||||
[status-im.accounts.login.core :as accounts.login]
|
||||
[status-im.init.core :as init]
|
||||
[status-im.contact-recovery.core :as contact-recovery]
|
||||
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
||||
[status-im.hardwallet.core :as hardwallet]
|
||||
[status-im.mailserver.core :as mailserver]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.pairing.core :as pairing]
|
||||
[status-im.contact-recovery.core :as contact-recovery]
|
||||
[status-im.mailserver.core :as mailserver]
|
||||
[status-im.transport.message.core :as transport.message]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.hardwallet.core :as hardwallet]))
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(fx/defn status-node-started
|
||||
[{db :db :as cofx}]
|
||||
|
@ -73,4 +73,5 @@
|
|||
(mailserver/resend-request cofx {:request-id (:hash event)}))
|
||||
"messages.decrypt.failed" (contact-recovery/handle-contact-recovery-fx cofx (:sender event))
|
||||
"discovery.summary" (summary cofx event)
|
||||
"subscriptions.data" (ethereum.subscriptions/handle-signal cofx event)
|
||||
(log/debug "Event " type " not handled"))))
|
||||
|
|
|
@ -1,49 +1,43 @@
|
|||
(ns status-im.subs
|
||||
(:require [re-frame.core :as re-frame]
|
||||
(:require [cljs.spec.alpha :as spec]
|
||||
[clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.browser.core :as browser]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.chat.commands.input :as commands.input]
|
||||
[status-im.chat.constants :as chat.constants]
|
||||
[status-im.chat.db :as chat.db]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contact.db :as contact.db]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.models.transactions :as transactions]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
[status-im.ui.components.bottom-bar.styles :as tabs.styles]
|
||||
[status-im.ui.components.toolbar.styles :as toolbar.styles]
|
||||
[status-im.ui.screens.add-new.new-public-chat.db :as db]
|
||||
[status-im.ui.screens.chat.stickers.styles :as stickers.styles]
|
||||
[status-im.ui.screens.mobile-network-settings.utils
|
||||
:as
|
||||
mobile-network-utils]
|
||||
[status-im.ui.screens.wallet.utils :as wallet.utils]
|
||||
[status-im.utils.build :as build]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.datetime :as datetime]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.money :as money]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.utils.universal-links.core :as links]
|
||||
status-im.tribute-to-talk.subs
|
||||
status-im.ui.screens.hardwallet.connect.subs
|
||||
status-im.ui.screens.hardwallet.settings.subs
|
||||
status-im.ui.screens.hardwallet.pin.subs
|
||||
status-im.ui.screens.hardwallet.setup.subs
|
||||
[cljs.spec.alpha :as spec]
|
||||
[clojure.string :as string]
|
||||
|
||||
[status-im.chat.db :as chat.db]
|
||||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.contact.db :as contact.db]
|
||||
|
||||
[status-im.browser.core :as browser]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.constants :as constants]
|
||||
|
||||
[status-im.models.transactions :as transactions]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
|
||||
[status-im.chat.commands.input :as commands.input]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.chat.constants :as chat.constants]
|
||||
|
||||
[status-im.ui.components.toolbar.styles :as toolbar.styles]
|
||||
[status-im.ui.components.bottom-bar.styles :as tabs.styles]
|
||||
|
||||
[status-im.ui.screens.chat.stickers.styles :as stickers.styles]
|
||||
[status-im.ui.screens.add-new.new-public-chat.db :as db]
|
||||
[status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils]
|
||||
[status-im.ui.screens.wallet.utils :as wallet.utils]
|
||||
|
||||
[status-im.utils.universal-links.core :as links]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.money :as money]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.build :as build]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
[status-im.utils.datetime :as datetime]
|
||||
|
||||
[status-im.i18n :as i18n]))
|
||||
status-im.ui.screens.hardwallet.setup.subs))
|
||||
|
||||
;; TOP LEVEL ===========================================================================================================
|
||||
|
||||
|
@ -157,6 +151,9 @@
|
|||
(reg-root-key-sub :prices-loading? :prices-loading?)
|
||||
(reg-root-key-sub :wallet.transactions :wallet.transactions)
|
||||
|
||||
;;ethereum
|
||||
(reg-root-key-sub :ethereum/current-block :ethereum/current-block)
|
||||
|
||||
;;GENERAL ==============================================================================================================
|
||||
|
||||
(re-frame/reg-sub
|
||||
|
@ -1138,10 +1135,12 @@
|
|||
|
||||
(re-frame/reg-sub
|
||||
:wallet.transactions.details/confirmations
|
||||
:<- [:ethereum/current-block]
|
||||
:<- [:wallet.transactions/transaction-details]
|
||||
(fn [transaction-details]
|
||||
;;TODO (yenda) this field should be calculated based on the current-block and the block of the transaction
|
||||
(:confirmations transaction-details)))
|
||||
(fn [[current-block {:keys [block]}]]
|
||||
(if (and current-block block)
|
||||
(- current-block block)
|
||||
0)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:wallet.transactions.details/confirmations-progress
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns status-im.utils.ethereum.core
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.ethereum.decode :as decode]
|
||||
[status-im.js-dependencies :as dependencies]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
|
@ -124,7 +125,7 @@
|
|||
|
||||
(defn call [params callback]
|
||||
(status/call-private-rpc
|
||||
(.stringify js/JSON (clj->js {:jsonprc "2.0"
|
||||
(.stringify js/JSON (clj->js {:jsonrpc "2.0"
|
||||
:id 1
|
||||
:method "eth_call"
|
||||
:params [params "latest"]}))
|
||||
|
@ -172,13 +173,9 @@
|
|||
(cb (js->clj result :keywordize-keys true))
|
||||
(handle-error error)))))
|
||||
|
||||
(defn- decode-uint
|
||||
[hex]
|
||||
(first (abi-spec/decode hex ["uint"])))
|
||||
|
||||
(defn get-transaction [transaction-hash callback]
|
||||
(status/call-private-rpc
|
||||
(.stringify js/JSON (clj->js {:jsonprc "2.0"
|
||||
(.stringify js/JSON (clj->js {:jsonrpc "2.0"
|
||||
:id 1
|
||||
:method "eth_getTransactionByHash"
|
||||
:params [transaction-hash]}))
|
||||
|
@ -188,9 +185,9 @@
|
|||
(callback (-> (.parse js/JSON response)
|
||||
(js->clj :keywordize-keys true)
|
||||
:result
|
||||
(update :gasPrice decode-uint)
|
||||
(update :value decode-uint)
|
||||
(update :gas decode-uint)))))))
|
||||
(update :gasPrice decode/uint)
|
||||
(update :value decode/uint)
|
||||
(update :gas decode/uint)))))))
|
||||
|
||||
(defn get-transaction-receipt [web3 number cb]
|
||||
(.getTransactionReceipt (.-eth web3) number (fn [error result]
|
||||
|
|
Loading…
Reference in New Issue