yenda b13864d052
[refactor] move utils.ethereum to ethereum
move utils.ethereum.tokens to ethereum.tokens
move utils.ethereum.abi-spec to ethereum.abi-spec
move utils.ethereum.core to ethereum.core
move utils.ethereum.eip165 to ethereum.eip165
move utils.ethereum.eip55 to ethereum.eip55
move utils.ethereum.eip681 to ethereum.eip681
move utils.ethereum.ens to ethereum.ens
move utils.ethereum.erc721 to ethereum.erc721
move utils.ethereum.mnemonics to ethereum.mnemonics
move utils.ethereum.resolver to ethereum.resolver
move utils.ethereum.macros to ethereum.macros

Signed-off-by: yenda <eric@status.im>
2019-05-23 15:11:48 +02:00

30 lines
933 B
Clojure

(ns status-im.ethereum.eip165
"Utility function related to [EIP165](https://eips.ethereum.org/EIPS/eip-165)"
(:require [status-im.ethereum.abi-spec :as abi-spec]
[status-im.ethereum.json-rpc :as json-rpc]))
(def supports-interface-hash "0x01ffc9a7")
(def marker-hash "0xffffffff")
(defn supports-interface?
[contract hash cb]
(json-rpc/eth-call
{:contract contract
:method "supportsInterface(bytes4)"
:params [hash]
:on-success cb}))
(defn supports?
"Calls cb with true if `supportsInterface` is supported by this contract.
See EIP for details."
[web3 contract cb]
(supports-interface?
contract
supports-interface-hash
#(if (true? (abi-spec/hex-to-boolean %))
(supports-interface? contract
marker-hash
(fn [response]
(cb (false? (abi-spec/hex-to-boolean response)))))
(cb false))))