From c25b6ec630f11992a11fd5c8dd5d0ad672abf3ca Mon Sep 17 00:00:00 2001 From: Eric Dvorsak Date: Tue, 31 Jul 2018 13:07:46 +0200 Subject: [PATCH] working version for stateofus.eth usernames addr and text["statusAccount"] functions allow to retrive ethereum address and whisper address --- src/status_im/utils/ethereum/ens.cljs | 36 --------------------- src/status_im/utils/ethereum/stateofus.cljs | 31 ++++++++++++++++-- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/status_im/utils/ethereum/ens.cljs b/src/status_im/utils/ethereum/ens.cljs index 4a29ba5fee..af8289754a 100644 --- a/src/status_im/utils/ethereum/ens.cljs +++ b/src/status_im/utils/ethereum/ens.cljs @@ -48,12 +48,6 @@ (fn [_ ttl] (cb (ethereum/hex->int ttl))))) ;; Resolver contract - -(def status-resolvers - {:mainnet "0x314159265dd8dbb310642f98f50c066173c1259b" - :ropsten "0x5FfC014343cd971B7eb70732021E26C35B744cc4" - :rinkeby "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"}) - ;; Resolver must implement EIP65 (supportsInterface). When interacting with an unknown resolver it's safer to rely on it. (def addr-hash "0x3b3b57de") @@ -63,13 +57,6 @@ (ethereum/call-params resolver "addr(bytes32)" (namehash ens-name)) (fn [_ address] (cb (ethereum/hex->address address))))) -(defn content [web3 resolver ens-name cb] - (ethereum/call web3 - (ethereum/call-params resolver - "content(bytes32)" - (namehash ens-name)) - (fn [_ content] (cb content #_(ethereum/hex->string content))))) - (def name-hash "0x691f3431") ;; Defined by https://eips.ethereum.org/EIPS/eip-181 @@ -81,30 +68,7 @@ (namehash ens-name)) (fn [_ address] (cb (ethereum/hex->address address))))) -(defn text [web3 resolver ens-name key cb] - (ethereum/call web3 - (ethereum/call-params resolver - "text(bytes32)" - (namehash ens-name) - (ethereum/string->hex key)) - (fn [err text] (cb err text)))) - (def ABI-hash "0x2203ab56") (def pubkey-hash "0xc8690233") ;; TODO ABI, pubkey - -(comment - (let [web3-o (:web3 @re-frame.db/app-db)] - (resolver web3-o (:ropsten ens-registries) "test.stateofus.eth" println)) - - (let [web3-o (:web3 @re-frame.db/app-db)] - (addr web3-o "0x5FfC014343cd971B7eb70732021E26C35B744cc4" "test.stateofus.eth" #(println %))) - - (let [web3-o (:web3 @re-frame.db/app-db)] - (text web3-o "0x5FfC014343cd971B7eb70732021E26C35B744cc4" "test.stateofus.eth" "statusAccount" println)) - - (ethereum/call-params "0x5FfC014343cd971B7eb70732021E26C35B744cc4" - "text(bytes32,string)" - (namehash "test.stateofus.eth") - (ethereum/string->hex "statusAccount"))) diff --git a/src/status_im/utils/ethereum/stateofus.cljs b/src/status_im/utils/ethereum/stateofus.cljs index ba036cd9b9..9276f3d16b 100644 --- a/src/status_im/utils/ethereum/stateofus.cljs +++ b/src/status_im/utils/ethereum/stateofus.cljs @@ -4,6 +4,31 @@ [status-im.utils.ethereum.core :as ethereum] [status-im.utils.ethereum.ens :as ens])) -(defn name [web3 registry name cb] - (ens/resolver web3 registry name - #(ens/name web3 %2 name cb))) +(defn is-stateofus-name? [ens-name] + (string/ends-with? ens-name ".stateofus.eth")) + +(defn addr [web3 registry ens-name cb] + {:pre [(is-stateofus-name? ens-name)]} + (ens/resolver web3 + registry + ens-name + #(ens/addr web3 % ens-name cb))) + +(defn text + "calls the text function on the stateofus resolver contract for `statusAccount` key + TODO: https://solidity.readthedocs.io/en/develop/abi-spec.html needs to be implemented + to replace this by dynamic parameters" + [web3 registry ens-name cb] + {:pre [(is-stateofus-name? ens-name)]} + (ens/resolver web3 + registry + ens-name + #(ethereum/call web3 + {:to % + :data (str "0x59d1d43c" + (subs (ens/namehash ens-name) 2) + "0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000d7374617475734163636f756e7400000000000000000000000000000000000000")} + (fn [_ text] (cb (ethereum/hex->string (subs text 130 214))))))) + +#_(addr (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "test.stateofus.eth" println) +#_(text (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "test.stateofus.eth" println)