Skip to content

Instantly share code, notes, and snippets.

@yenda
Last active March 29, 2019 12:21
Show Gist options
  • Save yenda/caeffa5ea61b2e088f095a4fb7b121e7 to your computer and use it in GitHub Desktop.
Save yenda/caeffa5ea61b2e088f095a4fb7b121e7 to your computer and use it in GitHub Desktop.
(def contracts
{:status/tribute-to-talk
{:address
{:mainnet nil
:testnet "0x3da3fc53e24707f36c5b4433b442e896c4955f0e"
:rinkeby nil}
:methods
{:get-manifest
{:signature "getManifest(address)"
:return-params ["bytes"]}}}
:status/sticker-market
{:address
{:mainnet nil
:testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"
:rinkeby nil}
:methods
{:pack-count
{:signature "packCount()"
:return-params ["uint256"]}
:pack-data
{:signature "getPackData(uint256)"
:return-params ["bytes4[]" "address" "bool" "uint256" "uint256" "bytes"]}}}} )
(fx/defn call
[{:keys [db]} {:keys [contract method params callback]}]
(let [chain-keyword (-> (get-in db [:account/account :networks (:network db)])
ethereum/network->chain-keyword)
contract-address (get-in contracts [contract :address chain-keyword])]
(when contact-address
(let [{:keys [signature return-params]}
(get-in contracts [contract :methods method])]
{::call {:address contract-address
:data (abi-spec/encode signature params)
:callback #(callback (abi-spec/decode % return-params))}}))))
(re-frame/reg-fx
::call
(fn [[address data callback]]
(ethereum/call {:to address
:data data}
callback)))
(call cofx
{:contract :status/tribute-to-talk
:method :get-manifest
:params ["0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"]
:callback #(re-frame/dispatch [:tribute-to-talk.callback/get-manifest-success (first %)])} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment