Add ethereum/poll-logs event, fixes #6855
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
b65f678429
commit
1a46355c61
|
@ -201,6 +201,11 @@
|
|||
(def ^:const web3-personal-sign "personal_sign")
|
||||
(def ^:const web3-get-logs "eth_getLogs")
|
||||
(def ^:const web3-transaction-receipt "eth_getTransactionReceipt")
|
||||
(def ^:const web3-new-filter "eth_newFilter")
|
||||
(def ^:const web3-new-pending-transaction-filter "eth_newPendingTransactionFilter")
|
||||
(def ^:const web3-new-block-filter "eth_newBlockFilter")
|
||||
(def ^:const web3-uninstall-filter "eth_uninstallFilter")
|
||||
(def ^:const web3-get-filter-changes "eth_getFilterChanges")
|
||||
|
||||
(def ^:const event-transfer-hash
|
||||
(ethereum/sha3 "Transfer(address,address,uint256)"))
|
||||
|
|
|
@ -538,6 +538,24 @@
|
|||
:value :extensions/ethereum-resolve-ens
|
||||
:arguments {:name :string
|
||||
:on-result :event}}
|
||||
'ethereum/create-filter
|
||||
{:permissions [:read]
|
||||
:value :extensions/ethereum-create-filter
|
||||
:arguments {:filter-type :string
|
||||
:from? :string
|
||||
:to? :string
|
||||
:address? :vector
|
||||
:topics? :vector
|
||||
:block-hash? :string
|
||||
:on-result :event}}
|
||||
'ethereum/logs-changes
|
||||
{:permissions [:read]
|
||||
:value :extensions/ethereum-logs-changes
|
||||
:arguments {:id :string}}
|
||||
'ethereum/cancel-filter
|
||||
{:permissions [:read]
|
||||
:value :extensions/ethereum-cancel-filter
|
||||
:arguments {:id :string}}
|
||||
'ethereum/call
|
||||
{:permissions [:read]
|
||||
:value :extensions/ethereum-call
|
||||
|
|
|
@ -222,3 +222,47 @@
|
|||
:on-error [:extensions/wallet-ui-on-error on-result]
|
||||
:method constants/web3-personal-sign})}
|
||||
(navigation/navigate-to-cofx :wallet-sign-message-modal nil)))))
|
||||
|
||||
;; poll logs implementation
|
||||
(handlers/register-handler-fx
|
||||
:extensions/ethereum-logs-changes
|
||||
(fn [_ [_ _ {:keys [filterId on-result]}]]
|
||||
(let [args {:jsonrpc "2.0"
|
||||
:method constants/web3-get-filter-changes
|
||||
:params [filterId]}
|
||||
payload (types/clj->json args)]
|
||||
(status/call-private-rpc payload #(let [{:keys [error result]} (types/json->clj %1)
|
||||
response (merge {:result result} (when error {:error error}))]
|
||||
(mapv (fn [one-result]
|
||||
(re-frame/dispatch (on-result one-result))) result))))))
|
||||
(handlers/register-handler-fx
|
||||
:extensions/ethereum-cancel-filter
|
||||
(fn [_ [_ _ {:keys [filterId on-result]}]]
|
||||
(let [args {:jsonrpc "2.0"
|
||||
:method constants/web3-uninstall-filter
|
||||
:params [filterId]}
|
||||
payload (types/clj->json args)]
|
||||
(status/call-private-rpc payload #(let [{:keys [error result]} (types/json->clj %1)
|
||||
response (merge {:result result} (when error {:error error}))]
|
||||
(re-frame/dispatch (on-result response)))))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/ethereum-create-filter
|
||||
(fn [_ [_ _ {:keys [filter-type from to address topics block-hash on-result]}]]
|
||||
(let [parsed-topics (mapv parse-topic topics)
|
||||
args (case filter-type
|
||||
"filter" {:jsonrpc "2.0"
|
||||
:method constants/web3-new-filter
|
||||
:params [{:fromBlock (ensure-hex-bn from)
|
||||
:toBlock (ensure-hex-bn to)
|
||||
:address address
|
||||
:topics parsed-topics
|
||||
:blockhash block-hash}]}
|
||||
"block" {:jsonrpc "2.0"
|
||||
:method constants/web3-new-block-filter}
|
||||
"pendingTransaction" {:jsonrpc "2.0"
|
||||
:method constants/web3-new-pending-transaction-filter})
|
||||
payload (types/clj->json args)]
|
||||
(status/call-private-rpc payload #(let [{:keys [error result]} (types/json->clj %1)
|
||||
response (merge {:result result} (when error {:error error}))]
|
||||
(re-frame/dispatch (on-result response)))))))
|
||||
|
|
Loading…
Reference in New Issue