2019-05-22 17:00:34 +02:00
|
|
|
(ns status-im.ethereum.eip165
|
2018-07-24 11:45:29 +02:00
|
|
|
"Utility function related to [EIP165](https://eips.ethereum.org/EIPS/eip-165)"
|
2019-05-22 17:00:34 +02:00
|
|
|
(:require [status-im.ethereum.abi-spec :as abi-spec]
|
|
|
|
[status-im.ethereum.json-rpc :as json-rpc]))
|
2018-07-24 11:45:29 +02:00
|
|
|
|
|
|
|
(def supports-interface-hash "0x01ffc9a7")
|
|
|
|
(def marker-hash "0xffffffff")
|
|
|
|
|
2019-05-20 02:21:38 +02:00
|
|
|
(defn supports-interface?
|
|
|
|
[contract hash cb]
|
|
|
|
(json-rpc/eth-call
|
|
|
|
{:contract contract
|
|
|
|
:method "supportsInterface(bytes4)"
|
|
|
|
:params [hash]
|
|
|
|
:on-success cb}))
|
2018-07-24 11:45:29 +02:00
|
|
|
|
|
|
|
(defn supports?
|
|
|
|
"Calls cb with true if `supportsInterface` is supported by this contract.
|
|
|
|
See EIP for details."
|
|
|
|
[web3 contract cb]
|
2019-03-28 11:03:42 +01:00
|
|
|
(supports-interface?
|
|
|
|
contract
|
|
|
|
supports-interface-hash
|
2019-05-20 02:21:38 +02:00
|
|
|
#(if (true? (abi-spec/hex-to-boolean %))
|
2019-03-28 11:03:42 +01:00
|
|
|
(supports-interface? contract
|
|
|
|
marker-hash
|
|
|
|
(fn [response]
|
2019-05-20 02:21:38 +02:00
|
|
|
(cb (false? (abi-spec/hex-to-boolean response)))))
|
2019-03-28 11:03:42 +01:00
|
|
|
(cb false))))
|