use call-private-rpc in ethereum/call
- remove web3 parameter for ethereum/call - remove first parameter for callback of ethereum/call which was always nil Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
1bfa3cf178
commit
884a44b5df
|
@ -88,7 +88,7 @@
|
|||
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))))
|
||||
|
||||
(fx/defn resolve-url
|
||||
[{{:keys [web3 network] :as db} :db} {:keys [error? resolved-url]}]
|
||||
[{{:keys [network] :as db} :db} {:keys [error? resolved-url]}]
|
||||
(when (not error?)
|
||||
(let [current-url (get-current-url (get-current-browser db))
|
||||
host (http/url-host current-url)]
|
||||
|
@ -96,22 +96,20 @@
|
|||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)]
|
||||
{:db (update db :browser/options assoc :resolving? true)
|
||||
:browser/resolve-ens-content {:web3 web3
|
||||
:registry (get ens/ens-registries
|
||||
:browser/resolve-ens-content {:registry (get ens/ens-registries
|
||||
chain)
|
||||
:ens-name host
|
||||
:cb resolve-ens-content-callback}})
|
||||
{:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)}))))
|
||||
|
||||
(fx/defn resolve-ens-contenthash
|
||||
[{{:keys [web3 network] :as db} :db}]
|
||||
[{{:keys [network] :as db} :db}]
|
||||
(let [current-url (get-current-url (get-current-browser db))
|
||||
host (http/url-host current-url)]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)]
|
||||
{:db (update db :browser/options assoc :resolving? true)
|
||||
:browser/resolve-ens-contenthash {:web3 web3
|
||||
:registry (get ens/ens-registries
|
||||
:browser/resolve-ens-contenthash {:registry (get ens/ens-registries
|
||||
chain)
|
||||
:ens-name host
|
||||
:cb resolve-ens-contenthash-callback}})))
|
||||
|
@ -361,13 +359,13 @@
|
|||
|
||||
(re-frame/reg-fx
|
||||
:browser/resolve-ens-content
|
||||
(fn [{:keys [web3 registry ens-name cb]}]
|
||||
(resolver/content web3 registry ens-name cb)))
|
||||
(fn [{:keys [registry ens-name cb]}]
|
||||
(resolver/content registry ens-name cb)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:browser/resolve-ens-contenthash
|
||||
(fn [{:keys [web3 registry ens-name cb]}]
|
||||
(resolver/contenthash web3 registry ens-name cb)))
|
||||
(fn [{:keys [registry ens-name cb]}]
|
||||
(resolver/contenthash registry ens-name cb)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:browser/send-to-bridge
|
||||
|
@ -396,4 +394,3 @@
|
|||
:browser/show-web-browser-selection
|
||||
(fn [link]
|
||||
(list-selection/browse-in-web-browser link)))
|
||||
|
||||
|
|
|
@ -36,11 +36,12 @@
|
|||
(first address)
|
||||
address)]
|
||||
(if (ens/is-valid-eth-name? first-address)
|
||||
(let [{:keys [web3 network]} db
|
||||
(let [{:keys [network]} db
|
||||
network-info (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network-info)
|
||||
registry (get ens/ens-registries chain)]
|
||||
(ens/get-addr web3 registry first-address #(f db (assoc arguments address-keyword %))))
|
||||
(ens/get-addr registry first-address
|
||||
#(f db (assoc arguments address-keyword %))))
|
||||
(f db arguments))))
|
||||
|
||||
(defn prepare-extension-transaction [params contacts on-success on-failure]
|
||||
|
@ -375,11 +376,12 @@
|
|||
:extensions/ethereum-resolve-ens
|
||||
(fn [{db :db} [_ _ {:keys [name on-success on-failure]}]]
|
||||
(if (ens/is-valid-eth-name? name)
|
||||
(let [{:keys [web3 network]} db
|
||||
(let [{:keys [network]} db
|
||||
network-info (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network-info)
|
||||
registry (get ens/ens-registries chain)]
|
||||
(ens/get-addr web3 registry name #(on-success {:value %})))
|
||||
(ens/get-addr registry name
|
||||
#(on-success {:value %})))
|
||||
(when on-failure
|
||||
(on-failure {:value (str "'" name "' is not a valid name")})))))
|
||||
|
||||
|
|
|
@ -42,13 +42,14 @@
|
|||
(when (and (#{constants/swarm-proto-code constants/ipfs-proto-code} proto-code) hash)
|
||||
(re-frame/dispatch [:stickers/load-pack proto-code hash id price open?])))))
|
||||
|
||||
(fx/defn open-sticker-pack [{{:keys [web3 network] :stickers/keys [packs packs-installed] :as db} :db :as cofx} id]
|
||||
(fx/defn open-sticker-pack
|
||||
[{{:keys [network] :stickers/keys [packs packs-installed] :as db} :db :as cofx} id]
|
||||
(when id
|
||||
(let [pack (or (get packs-installed id) (get packs id))
|
||||
network (get-in db [:account/account :networks network])]
|
||||
(if pack
|
||||
(navigation/navigate-to-cofx cofx :stickers-pack-modal pack)
|
||||
{:stickers/pack-data-fx [web3 network id true]}))))
|
||||
{:stickers/pack-data-fx [network id true]}))))
|
||||
|
||||
(fx/defn load-pack [cofx proto-code hash id price open?]
|
||||
{:http-get {:url (str (if (= constants/swarm-proto-code proto-code)
|
||||
|
@ -59,11 +60,11 @@
|
|||
[:stickers/load-sticker-pack-success o id price open?])
|
||||
:failure-event-creator (constantly nil)}})
|
||||
|
||||
(fx/defn load-packs [{{:keys [web3 network] :as db} :db}]
|
||||
(fx/defn load-packs [{{:keys [network] :as db} :db}]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
address (ethereum/normalized-address (get-in db [:account/account :address]))]
|
||||
{:stickers/owned-packs-fx [web3 network address]
|
||||
:stickers/load-packs-fx [web3 network]}))
|
||||
{:stickers/owned-packs-fx [network address]
|
||||
:stickers/load-packs-fx [network]}))
|
||||
|
||||
(defn prepare-transaction [id tx on-result]
|
||||
(merge {:id id
|
||||
|
@ -86,37 +87,40 @@
|
|||
(prepare-transaction "approve" tx-object [:stickers/pending-pack pack-id])
|
||||
tx-object)))
|
||||
|
||||
(fx/defn pending-pack [{{:keys [web3 network] :as db} :db :as cofx} id]
|
||||
(fx/defn pending-pack
|
||||
[{{:keys [network] :as db} :db :as cofx} id]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
address (ethereum/normalized-address (get-in db [:account/account :address]))]
|
||||
(fx/merge cofx
|
||||
{:db (update db :stickers/packs-pendning conj id)
|
||||
:stickers/owned-packs-fx [web3 network address]}
|
||||
:stickers/owned-packs-fx [network address]}
|
||||
(navigation/navigate-to-clean :wallet-transaction-sent-modal {})
|
||||
#(when (zero? (count (:stickers/packs-pendning db)))
|
||||
{:stickers/set-pending-timout-fx nil}))))
|
||||
|
||||
(fx/defn pending-timeout [{{:keys [web3 network] :stickers/keys [packs-pendning packs-owned] :as db} :db}]
|
||||
(fx/defn pending-timeout
|
||||
[{{:keys [network] :stickers/keys [packs-pendning packs-owned] :as db} :db}]
|
||||
(let [packs-diff (clojure.set/difference packs-pendning packs-owned)
|
||||
network (get-in db [:account/account :networks network])
|
||||
address (ethereum/normalized-address (get-in db [:account/account :address]))]
|
||||
(merge {:db (assoc db :stickers/packs-pendning packs-diff)}
|
||||
(when-not (zero? (count packs-diff))
|
||||
{:stickers/owned-packs-fx [web3 network address]
|
||||
{:stickers/owned-packs-fx [network address]
|
||||
:stickers/set-pending-timout-fx nil}))))
|
||||
|
||||
(fx/defn pack-owned [{db :db} id]
|
||||
{:db (update db :stickers/packs-owned conj id)})
|
||||
|
||||
(fx/defn get-owned-pack [{{:keys [web3 network] :as db} :db}]
|
||||
(fx/defn get-owned-pack
|
||||
[{{:keys [network] :as db} :db}]
|
||||
(let [address (ethereum/normalized-address (get-in db [:account/account :address]))]
|
||||
{:stickers/owned-packs-fx [web3 network address]}))
|
||||
{:stickers/owned-packs-fx [network address]}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:stickers/pack-data-fx
|
||||
(fn [[web3 network id open?]]
|
||||
(fn [[network id open?]]
|
||||
(when-let [contract (get ethereum.stickers/contracts (ethereum/network->chain-keyword network))]
|
||||
(ethereum.stickers/pack-data web3 contract id (pack-data-callback id open?)))))
|
||||
(ethereum.stickers/pack-data contract id (pack-data-callback id open?)))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:stickers/set-pending-timout-fx
|
||||
|
@ -125,19 +129,19 @@
|
|||
|
||||
(re-frame/reg-fx
|
||||
:stickers/load-packs-fx
|
||||
(fn [[web3 network]]
|
||||
(fn [[network]]
|
||||
(when-let [contract (get ethereum.stickers/contracts (ethereum/network->chain-keyword network))]
|
||||
(ethereum.stickers/pack-count web3 contract
|
||||
(ethereum.stickers/pack-count contract
|
||||
(fn [count]
|
||||
(dotimes [n count]
|
||||
(ethereum.stickers/pack-data web3 contract n (pack-data-callback n false))))))))
|
||||
(ethereum.stickers/pack-data contract n (pack-data-callback n false))))))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:stickers/owned-packs-fx
|
||||
(fn [[web3 network address]]
|
||||
(fn [[network address]]
|
||||
(when-let [contract (get ethereum.stickers/contracts (ethereum/network->chain-keyword network))]
|
||||
(ethereum.stickers/owned-tokens web3 contract address
|
||||
(ethereum.stickers/owned-tokens contract address
|
||||
(fn [tokens]
|
||||
(doseq [n tokens]
|
||||
(ethereum.stickers/token-pack-id web3 contract n
|
||||
(ethereum.stickers/token-pack-id contract n
|
||||
#(re-frame/dispatch [:stickers/pack-owned %]))))))))
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
(re-frame/reg-fx
|
||||
:resolve-public-key
|
||||
(fn [{:keys [web3 registry ens-name cb]}]
|
||||
(resolver/pubkey web3 registry ens-name cb)))
|
||||
(fn [{:keys [registry ens-name cb]}]
|
||||
(resolver/pubkey registry ens-name cb)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:new-chat/set-new-identity
|
||||
(fn [{{:keys [web3 network network-status] :as db} :db} [_ new-identity]]
|
||||
(fn [{{:keys [network network-status] :as db} :db} [_ new-identity]]
|
||||
(let [is-public-key? (and (string? new-identity)
|
||||
(string/starts-with? new-identity "0x"))]
|
||||
(merge {:db (assoc db
|
||||
|
@ -23,8 +23,7 @@
|
|||
(when-not is-public-key?
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)]
|
||||
{:resolve-public-key {:web3 web3
|
||||
:registry (get ens/ens-registries chain)
|
||||
{:resolve-public-key {:registry (get ens/ens-registries chain)
|
||||
:ens-name (if (ens/is-valid-eth-name? new-identity)
|
||||
new-identity
|
||||
(str new-identity ".stateofus.eth"))
|
||||
|
|
|
@ -69,8 +69,8 @@
|
|||
|
||||
(re-frame/reg-fx
|
||||
:resolve-address
|
||||
(fn [{:keys [web3 registry ens-name cb]}]
|
||||
(ens/get-addr web3 registry ens-name cb)))
|
||||
(fn [{:keys [registry ens-name cb]}]
|
||||
(ens/get-addr registry ens-name cb)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:wallet.send/set-recipient
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
ids)}))
|
||||
|
||||
;; TODO(andrey) Each HTTP call will return up to 100 kitties. Maybe we need to implement some kind of paging later
|
||||
(defmethod collectibles/load-collectibles-fx ck [_ _ _ items-number address _]
|
||||
(defmethod collectibles/load-collectibles-fx ck [_ _ items-number address _]
|
||||
{:http-get {:url (str "https://api.cryptokitties.co/kitties?offset=0&limit="
|
||||
items-number
|
||||
"&owner_wallet_address="
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
(defmethod load-collectible-fx :default [_ _ _] nil)
|
||||
|
||||
(defmulti load-collectibles-fx (fn [_ _ symbol _ _] symbol))
|
||||
(defmulti load-collectibles-fx (fn [_ symbol _ _] symbol))
|
||||
|
||||
(defmethod load-collectibles-fx :default [web3 all-tokens symbol items-number address chain-id]
|
||||
{:load-collectibles-fx [web3 all-tokens symbol items-number address chain-id]})
|
||||
(defmethod load-collectibles-fx :default [all-tokens symbol items-number address chain-id]
|
||||
{:load-collectibles-fx [all-tokens symbol items-number address chain-id]})
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:show-collectibles-list
|
||||
|
@ -25,22 +25,22 @@
|
|||
items-number (money/to-number amount)
|
||||
loaded-items-number (count (get-in db [:collectibles symbol]))]
|
||||
(merge (when (not= items-number loaded-items-number)
|
||||
(load-collectibles-fx (:web3 db) all-tokens symbol items-number address chain-id))
|
||||
(load-collectibles-fx all-tokens symbol items-number address chain-id))
|
||||
{:dispatch [:navigate-to :collectibles-list collectible]}))))
|
||||
|
||||
(defn load-token [web3 i items-number contract address symbol]
|
||||
(defn load-token [i items-number contract address symbol]
|
||||
(when (< i items-number)
|
||||
(erc721/token-of-owner-by-index web3 contract address i
|
||||
(fn [v1 v2]
|
||||
(load-token web3 (inc i) items-number contract address symbol)
|
||||
(re-frame/dispatch [:load-collectible symbol (.toNumber v2)])))))
|
||||
(erc721/token-of-owner-by-index contract address i
|
||||
(fn [response]
|
||||
(load-token (inc i) items-number contract address symbol)
|
||||
(re-frame/dispatch [:load-collectible symbol (.toNumber response)])))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:load-collectibles-fx
|
||||
(fn [[web3 all-tokens symbol items-number address chain-id]]
|
||||
(fn [[all-tokens symbol items-number address chain-id]]
|
||||
(let [chain (ethereum/chain-id->chain-keyword chain-id)
|
||||
contract (:address (tokens/symbol->token all-tokens chain symbol))]
|
||||
(load-token web3 0 items-number contract address symbol))))
|
||||
(load-token 0 items-number contract address symbol))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:load-collectible
|
||||
|
|
|
@ -14,18 +14,19 @@
|
|||
(defmethod collectibles/load-collectible-fx kudos [{db :db} symbol id]
|
||||
(let [chain-id (get-in constants/default-networks [(:network db) :config :NetworkId])
|
||||
all-tokens (:wallet/all-tokens db)]
|
||||
{:erc721-token-uri [(:web3 db) all-tokens symbol id chain-id]}))
|
||||
{:erc721-token-uri [all-tokens symbol id chain-id]}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:erc721-token-uri
|
||||
(fn [[web3 all-tokens symbol tokenId chain-id]]
|
||||
(fn [[all-tokens symbol tokenId chain-id]]
|
||||
(let [chain (ethereum/chain-id->chain-keyword chain-id)
|
||||
contract (:address (tokens/symbol->token all-tokens chain symbol))]
|
||||
(erc721/token-uri web3 contract tokenId
|
||||
(erc721/token-uri contract
|
||||
tokenId
|
||||
#(re-frame/dispatch [:token-uri-success
|
||||
tokenId
|
||||
(when %2
|
||||
(subs %2 (.indexOf %2 "http")))]))))) ;; extra chars in rinkeby
|
||||
(when %
|
||||
(subs % (.indexOf % "http")))]))))) ;; extra chars in rinkeby
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:token-uri-success
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
imageUri
|
||||
}}}}"))
|
||||
|
||||
(defmethod collectibles/load-collectibles-fx superrare [_ _ _ _ address _]
|
||||
(defmethod collectibles/load-collectibles-fx superrare [_ _ _ address _]
|
||||
{:http-post {:url graphql-url
|
||||
:data (types/clj->json {:query (graphql-query (ethereum/naked-address address))})
|
||||
:opts {:headers {"Content-Type" "application/json"}}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns status-im.utils.ethereum.core
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.js-dependencies :as dependencies]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.money :as money]
|
||||
[taoensso.timbre :as log]))
|
||||
|
@ -124,8 +125,16 @@
|
|||
(defn- sig->method-id [signature]
|
||||
(apply str (take 10 (sha3 signature))))
|
||||
|
||||
(defn call [web3 params cb]
|
||||
(.call (.-eth web3) (clj->js params) cb))
|
||||
(defn call [params callback]
|
||||
(status/call-private-rpc
|
||||
(.stringify js/JSON (clj->js {:jsonprc "2.0"
|
||||
:id 1
|
||||
:method "eth_call"
|
||||
:params [params "latest"]}))
|
||||
(fn [response]
|
||||
(if (= "" response)
|
||||
(log/warn :web3-response-error)
|
||||
(callback (get (js->clj (.parse js/JSON response)) "result"))))))
|
||||
|
||||
(defn call-params [contract method-sig & params]
|
||||
(let [data (apply format-call-params (sig->method-id method-sig) params)]
|
||||
|
|
|
@ -5,18 +5,20 @@
|
|||
(def supports-interface-hash "0x01ffc9a7")
|
||||
(def marker-hash "0xffffffff")
|
||||
|
||||
(defn supports-interface? [web3 contract hash cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "supportsInterface(bytes4)" hash)
|
||||
#(cb %1 %2)))
|
||||
(defn supports-interface? [contract hash cb]
|
||||
(ethereum/call (ethereum/call-params contract "supportsInterface(bytes4)" hash)
|
||||
#(cb %)))
|
||||
|
||||
(defn supports?
|
||||
"Calls cb with true if `supportsInterface` is supported by this contract.
|
||||
See EIP for details."
|
||||
[web3 contract cb]
|
||||
(supports-interface? web3 contract supports-interface-hash
|
||||
#(if (true? (ethereum/hex->boolean %2))
|
||||
(supports-interface? web3 contract marker-hash
|
||||
(fn [o oo]
|
||||
(cb o (false? (ethereum/hex->boolean oo)))))
|
||||
(cb %1 false))))
|
||||
(supports-interface?
|
||||
contract
|
||||
supports-interface-hash
|
||||
#(if (true? (ethereum/hex->boolean %))
|
||||
(supports-interface? contract
|
||||
marker-hash
|
||||
(fn [response]
|
||||
(cb (false? (ethereum/hex->boolean response)))))
|
||||
(cb false))))
|
||||
|
|
|
@ -18,98 +18,114 @@
|
|||
(def default-address "0x0000000000000000000000000000000000000000")
|
||||
(def default-key "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
|
||||
(defn namehash [s]
|
||||
(ethereum/normalized-address (if (string/blank? s)
|
||||
default-namehash
|
||||
(let [[label remainder] (-> s
|
||||
string/lower-case
|
||||
(string/split #"\." 2))]
|
||||
(ethereum/sha3 (+ (namehash remainder)
|
||||
(subs (ethereum/sha3 label) 2))
|
||||
{:encoding "hex"})))))
|
||||
(defn namehash
|
||||
[s]
|
||||
(ethereum/normalized-address
|
||||
(if (string/blank? s)
|
||||
default-namehash
|
||||
(let [[label remainder] (-> s
|
||||
string/lower-case
|
||||
(string/split #"\." 2))]
|
||||
(ethereum/sha3 (+ (namehash remainder)
|
||||
(subs (ethereum/sha3 label) 2))
|
||||
{:encoding "hex"})))))
|
||||
|
||||
;; Registry contract
|
||||
|
||||
(defn resolver [web3 registry ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params registry
|
||||
(defn resolver
|
||||
[registry ens-name cb]
|
||||
(ethereum/call (ethereum/call-params registry
|
||||
"resolver(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [_ address] (let [address (ethereum/hex->address address)]
|
||||
(cb (if (and address (not= address default-address)) address ""))))))
|
||||
(fn [address]
|
||||
(let [address (ethereum/hex->address address)]
|
||||
(cb (if (and address (not= address default-address)) address ""))))))
|
||||
|
||||
(defn owner [web3 registry ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params registry
|
||||
(defn owner
|
||||
[registry ens-name cb]
|
||||
(ethereum/call (ethereum/call-params registry
|
||||
"owner(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [_ address] (cb address))))
|
||||
(fn [address]
|
||||
(cb address))))
|
||||
|
||||
(defn ttl [web3 registry ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params registry
|
||||
(defn ttl
|
||||
[registry ens-name cb]
|
||||
(ethereum/call (ethereum/call-params registry
|
||||
"ttl(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [_ ttl] (cb (ethereum/hex->int ttl)))))
|
||||
(fn [ttl]
|
||||
(cb (ethereum/hex->int ttl)))))
|
||||
|
||||
;; Resolver contract
|
||||
;; Resolver must implement EIP65 (supportsInterface). When interacting with an unknown resolver it's safer to rely on it.
|
||||
|
||||
(def addr-hash "0x3b3b57de")
|
||||
|
||||
(defn addr [web3 resolver ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params resolver "addr(bytes32)" (namehash ens-name))
|
||||
(fn [_ address] (cb (ethereum/hex->address address)))))
|
||||
(defn addr
|
||||
[resolver ens-name cb]
|
||||
(ethereum/call (ethereum/call-params resolver "addr(bytes32)" (namehash ens-name))
|
||||
(fn [address]
|
||||
(cb (ethereum/hex->address address)))))
|
||||
|
||||
(def name-hash "0x691f3431")
|
||||
|
||||
;; Defined by https://eips.ethereum.org/EIPS/eip-181
|
||||
|
||||
(defn name [web3 resolver ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params resolver
|
||||
(defn name
|
||||
[resolver ens-name cb]
|
||||
(ethereum/call (ethereum/call-params resolver
|
||||
"name(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [_ address] (cb (ethereum/hex->address address)))))
|
||||
(fn [address]
|
||||
(cb (ethereum/hex->address address)))))
|
||||
|
||||
(defn contenthash [web3 resolver ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params resolver "contenthash(bytes32)" (namehash ens-name))
|
||||
(fn [_ hash] (cb hash))))
|
||||
(defn contenthash
|
||||
[resolver ens-name cb]
|
||||
(ethereum/call (ethereum/call-params resolver
|
||||
"contenthash(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [hash]
|
||||
(cb hash))))
|
||||
|
||||
(defn content [web3 resolver ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params resolver "content(bytes32)" (namehash ens-name))
|
||||
(fn [_ hash] (cb hash))))
|
||||
(defn content
|
||||
[resolver ens-name cb]
|
||||
(ethereum/call (ethereum/call-params resolver
|
||||
"content(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [hash]
|
||||
(cb hash))))
|
||||
|
||||
(def ABI-hash "0x2203ab56")
|
||||
(def pubkey-hash "0xc8690233")
|
||||
|
||||
(defn add-uncompressed-public-key-prefix [key]
|
||||
(defn add-uncompressed-public-key-prefix
|
||||
[key]
|
||||
(when (and key
|
||||
(not= "0x" key)
|
||||
(not= default-key key))
|
||||
(str "0x04" (subs key 2))))
|
||||
|
||||
(defn is-valid-eth-name? [ens-name]
|
||||
(defn is-valid-eth-name?
|
||||
[ens-name]
|
||||
(and ens-name
|
||||
(string? ens-name)
|
||||
(string/ends-with? ens-name ".eth")))
|
||||
|
||||
(defn pubkey [web3 resolver ens-name cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params resolver
|
||||
(defn pubkey
|
||||
[resolver ens-name cb]
|
||||
(ethereum/call (ethereum/call-params resolver
|
||||
"pubkey(bytes32)"
|
||||
(namehash ens-name))
|
||||
(fn [_ key] (when-let [public-key (add-uncompressed-public-key-prefix key)]
|
||||
(cb public-key)))))
|
||||
(fn [key]
|
||||
(when-let [public-key (add-uncompressed-public-key-prefix key)]
|
||||
(cb public-key)))))
|
||||
|
||||
(defn get-addr [web3 registry ens-name cb]
|
||||
(defn get-addr
|
||||
[registry ens-name cb]
|
||||
{:pre [(is-valid-eth-name? ens-name)]}
|
||||
(resolver web3
|
||||
registry
|
||||
(resolver registry
|
||||
ens-name
|
||||
#(addr web3 % ens-name cb)))
|
||||
#(addr % ens-name cb)))
|
||||
|
||||
;; TODO ABI, pubkey
|
||||
|
|
|
@ -127,16 +127,23 @@
|
|||
on-completed))
|
||||
|
||||
(defn transfer-from [web3 contract from-address to-address value cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "transferFrom(address,address,uint256)" (ethereum/normalized-address from-address) (ethereum/normalized-address to-address) (ethereum/int->hex value))
|
||||
#(cb %1 (ethereum/hex->boolean %2))))
|
||||
(ethereum/call (ethereum/call-params contract
|
||||
"transferFrom(address,address,uint256)"
|
||||
(ethereum/normalized-address from-address)
|
||||
(ethereum/normalized-address to-address)
|
||||
(ethereum/int->hex value))
|
||||
#(cb (ethereum/hex->boolean %))))
|
||||
|
||||
(defn approve [web3 contract address value cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "approve(address,uint256)" (ethereum/normalized-address address) (ethereum/int->hex value))
|
||||
#(cb %1 (ethereum/hex->boolean %2))))
|
||||
(ethereum/call (ethereum/call-params contract
|
||||
"approve(address,uint256)"
|
||||
(ethereum/normalized-address address)
|
||||
(ethereum/int->hex value))
|
||||
#(cb (ethereum/hex->boolean %))))
|
||||
|
||||
(defn allowance [web3 contract owner-address spender-address cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "allowance(address,address)" (ethereum/normalized-address owner-address) (ethereum/normalized-address spender-address))
|
||||
#(cb %1 (ethereum/hex->bignumber %2))))
|
||||
(ethereum/call (ethereum/call-params contract
|
||||
"allowance(address,address)"
|
||||
(ethereum/normalized-address owner-address)
|
||||
(ethereum/normalized-address spender-address))
|
||||
#(cb (ethereum/hex->bignumber %))))
|
||||
|
|
|
@ -4,20 +4,17 @@
|
|||
"
|
||||
(:require [status-im.utils.ethereum.core :as ethereum]))
|
||||
|
||||
(defn token-of-owner-by-index [web3 contract address index cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params
|
||||
(defn token-of-owner-by-index [contract address index cb]
|
||||
(ethereum/call (ethereum/call-params
|
||||
contract
|
||||
"tokenOfOwnerByIndex(address,uint256)"
|
||||
(ethereum/normalized-address address)
|
||||
(ethereum/int->hex index))
|
||||
#(cb %1 (ethereum/hex->bignumber %2))))
|
||||
#(cb (ethereum/hex->bignumber %))))
|
||||
|
||||
(defn token-uri [web3 contract tokenId cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params
|
||||
(defn token-uri [contract tokenId cb]
|
||||
(ethereum/call (ethereum/call-params
|
||||
contract
|
||||
"tokenURI(uint256)"
|
||||
(ethereum/int->hex tokenId))
|
||||
(fn [v1 v2]
|
||||
(cb v1 (ethereum/hex->string v2)))))
|
||||
#(cb (ethereum/hex->string %))))
|
||||
|
|
|
@ -4,28 +4,24 @@
|
|||
|
||||
(def default-hash "0x0000000000000000000000000000000000000000000000000000000000000000")
|
||||
|
||||
(defn contenthash [web3 registry ens-name cb]
|
||||
(ens/resolver web3
|
||||
registry
|
||||
(defn contenthash [registry ens-name cb]
|
||||
(ens/resolver registry
|
||||
ens-name
|
||||
#(ens/contenthash web3 % ens-name cb)))
|
||||
#(ens/contenthash % ens-name cb)))
|
||||
|
||||
(defn content [web3 registry ens-name cb]
|
||||
(ens/resolver web3
|
||||
registry
|
||||
(defn content [registry ens-name cb]
|
||||
(ens/resolver registry
|
||||
ens-name
|
||||
#(ens/content web3 % ens-name cb)))
|
||||
#(ens/content % ens-name cb)))
|
||||
|
||||
(defn name [web3 registry ens-name cb]
|
||||
(ens/resolver web3
|
||||
registry
|
||||
(defn name [registry ens-name cb]
|
||||
(ens/resolver registry
|
||||
ens-name
|
||||
#(ens/name web3 % ens-name cb)))
|
||||
#(ens/name % ens-name cb)))
|
||||
|
||||
(defn pubkey
|
||||
[web3 registry ens-name cb]
|
||||
[registry ens-name cb]
|
||||
{:pre [(ens/is-valid-eth-name? ens-name)]}
|
||||
(ens/resolver web3
|
||||
registry
|
||||
(ens/resolver registry
|
||||
ens-name
|
||||
#(ens/pubkey web3 % ens-name cb)))
|
||||
#(ens/pubkey % ens-name cb)))
|
||||
|
|
|
@ -9,30 +9,26 @@
|
|||
|
||||
(defn pack-count
|
||||
"Returns number of packs rigestered in the contract"
|
||||
[web3 contract cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "packCount()")
|
||||
(fn [_ count] (cb (ethereum/hex->int count)))))
|
||||
[contract cb]
|
||||
(ethereum/call (ethereum/call-params contract "packCount()")
|
||||
(fn [count] (cb (ethereum/hex->int count)))))
|
||||
|
||||
(defn pack-data
|
||||
"Returns vector of pack data parameters by pack id: [category owner mintable timestamp price contenthash]"
|
||||
[web3 contract pack-id cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "getPackData(uint256)" (ethereum/int->hex pack-id))
|
||||
(fn [_ data]
|
||||
[contract pack-id cb]
|
||||
(ethereum/call (ethereum/call-params contract "getPackData(uint256)" (ethereum/int->hex pack-id))
|
||||
(fn [data]
|
||||
(cb (abi-spec/decode data ["bytes4[]" "address" "bool" "uint256" "uint256" "bytes"])))))
|
||||
|
||||
(defn owned-tokens
|
||||
"Returns vector of owned tokens ids in the contract by address"
|
||||
[web3 contract address cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "tokensOwnedBy(address)" (ethereum/normalized-address address))
|
||||
(fn [_ data]
|
||||
[contract address cb]
|
||||
(ethereum/call (ethereum/call-params contract "tokensOwnedBy(address)" (ethereum/normalized-address address))
|
||||
(fn [data]
|
||||
(cb (first (abi-spec/decode data ["uint256[]"]))))))
|
||||
|
||||
(defn token-pack-id
|
||||
"Returns pack id in the contract by token id"
|
||||
[web3 contract token cb]
|
||||
(ethereum/call web3
|
||||
(ethereum/call-params contract "tokenPackId(uint256)" (ethereum/int->hex token))
|
||||
(fn [_ data] (cb (ethereum/hex->int data)))))
|
||||
[contract token cb]
|
||||
(ethereum/call (ethereum/call-params contract "tokenPackId(uint256)" (ethereum/int->hex token))
|
||||
(fn [data] (cb (ethereum/hex->int data)))))
|
||||
|
|
Loading…
Reference in New Issue