Add ethereum/poll-logs event, fixes #6855

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Zach Zundel 2018-11-29 23:06:54 -07:00 committed by Julien Eluard
parent b65f678429
commit 1a46355c61
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
3 changed files with 67 additions and 0 deletions

View File

@ -201,6 +201,11 @@
(def ^:const web3-personal-sign "personal_sign") (def ^:const web3-personal-sign "personal_sign")
(def ^:const web3-get-logs "eth_getLogs") (def ^:const web3-get-logs "eth_getLogs")
(def ^:const web3-transaction-receipt "eth_getTransactionReceipt") (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 (def ^:const event-transfer-hash
(ethereum/sha3 "Transfer(address,address,uint256)")) (ethereum/sha3 "Transfer(address,address,uint256)"))

View File

@ -538,6 +538,24 @@
:value :extensions/ethereum-resolve-ens :value :extensions/ethereum-resolve-ens
:arguments {:name :string :arguments {:name :string
:on-result :event}} :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 'ethereum/call
{:permissions [:read] {:permissions [:read]
:value :extensions/ethereum-call :value :extensions/ethereum-call

View File

@ -222,3 +222,47 @@
:on-error [:extensions/wallet-ui-on-error on-result] :on-error [:extensions/wallet-ui-on-error on-result]
:method constants/web3-personal-sign})} :method constants/web3-personal-sign})}
(navigation/navigate-to-cofx :wallet-sign-message-modal nil))))) (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)))))))