-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] remove ethereum
call
and call-params
- use `json-rpc/eth-call` and `json-rpc/eth-transaction-call` everywhere - move all conversions to abi-spec
- Loading branch information
yenda
committed
May 20, 2019
1 parent
1b6419b
commit b8869a3
Showing
18 changed files
with
507 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,17 @@ | ||
(ns status-im.ethereum.contracts | ||
(:require [re-frame.core :as re-frame] | ||
[status-im.utils.ethereum.abi-spec :as abi-spec] | ||
[status-im.utils.ethereum.core :as ethereum] | ||
[status-im.utils.fx :as fx] | ||
[status-im.utils.money :as money] | ||
[status-im.wallet.core :as wallet])) | ||
(:require [status-im.utils.ethereum.core :as ethereum])) | ||
|
||
(def contracts | ||
{:status/tribute-to-talk | ||
{:address | ||
{:mainnet nil | ||
:testnet "0x3da3fc53e24707f36c5b4433b442e896c4955f0e" | ||
:rinkeby nil} | ||
:methods | ||
{:get-manifest | ||
{:signature "getManifest(address)" | ||
:outputs ["bytes"]} | ||
:set-manifest | ||
{:signature "setManifest(bytes)" | ||
:write? true}}}}) | ||
{:status/snt | ||
{:mainnet "0x744d70fdbe2ba4cf95131626614a1763df805b9e" | ||
:testnet "0xc55cf4b03948d7ebc8b9e8bad92643703811d162"} | ||
:status/tribute-to-talk | ||
{:testnet "0x3da3fc53e24707f36c5b4433b442e896c4955f0e"} | ||
:status/stickers | ||
{:testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"}}) | ||
|
||
(re-frame/reg-fx | ||
::call | ||
(fn [{:keys [address data callback]}] | ||
(ethereum/call {:to address | ||
:data data} | ||
callback))) | ||
|
||
(defn get-contract-address | ||
(defn get-address | ||
[db contract] | ||
(let [chain-keyword (-> (get-in db [:account/account :networks (:network db)]) | ||
ethereum/network->chain-keyword)] | ||
(get-in contracts [contract :address chain-keyword]))) | ||
|
||
(fx/defn call | ||
[{:keys [db] :as cofx} | ||
{:keys [contract contract-address method params | ||
callback on-result on-error details]}] | ||
(when-let [contract-address (or contract-address | ||
(get-contract-address db contract))] | ||
(let [{:keys [signature outputs write?]} | ||
(get-in contracts [contract :methods method]) | ||
data (abi-spec/encode signature params)] | ||
(if write? | ||
(wallet/open-sign-transaction-flow | ||
cofx | ||
(merge {:to contract-address | ||
:data data | ||
:id "approve" | ||
:symbol :ETH | ||
:method "eth_sendTransaction" | ||
:amount (money/bignumber 0) | ||
:on-result on-result | ||
:on-error on-error} | ||
details)) | ||
{::call {:address contract-address | ||
:data data | ||
:callback #(callback (if (empty? outputs) | ||
% | ||
(abi-spec/decode % outputs)))}})))) | ||
(get-in contracts [contract chain-keyword]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.