Migrate to latest sticker contract

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Julien Eluard 2019-07-17 15:39:20 +02:00 committed by Andrey Shovkoplyas
parent d8645e2859
commit f29f02d961
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
3 changed files with 38 additions and 21 deletions

View File

@ -8,7 +8,14 @@
:status/tribute-to-talk
{:testnet "0xC61aa0287247a0398589a66fCD6146EC0F295432"}
:status/stickers
{:testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"}})
{:testnet "0x8cc272396be7583c65bee82cd7b743c69a87287d"
:mainnet "0x0577215622f43a39f4bc9640806dfea9b10d2a36"}
:status/sticker-market
{:testnet "0x6CC7274aF9cE9572d22DFD8545Fb8c9C9Bcb48AD"
:mainnet "0x12824271339304d3a9f7e096e62a2a7e73b4a7e7"}
:status/sticker-pack
{:testnet "0xf852198d0385c4b871e0b91804ecd47c6ba97351"
:mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"}})
(defn get-address
[db contract]

View File

@ -64,21 +64,29 @@
(json-rpc/eth-call
{:contract contract
;; Returns vector of owned tokens ids in the contract by address
:method "tokensOwnedBy(address)"
:method "balanceOf(address)"
:params [address]
:outputs ["uint256[]"]
:outputs ["uint256"]
:on-success
(fn [[tokens]]
(doseq [id tokens]
(fn [[count]]
(dotimes [id count]
(json-rpc/eth-call
{:contract contract
;; Returns pack id in the contract by token id
:method "tokenPackId(uint256)"
:params [id]
:method "tokenOfOwnerByIndex(address,uint256)"
:params [address id]
:outputs ["uint256"]
:on-success
(fn [[pack-id]]
(re-frame/dispatch [:stickers/pack-owned pack-id]))})))})))
(fn [[token-id]]
(json-rpc/eth-call
{:contract contract
;; Returns pack id in the contract by token id
:method "tokenPackId(uint256)"
:params [token-id]
:outputs ["uint256"]
:on-success
(fn [[pack-id]]
(re-frame/dispatch [:stickers/pack-owned pack-id]))}))})))})))
(fx/defn init-stickers-packs
[{:keys [db]}]
@ -137,29 +145,30 @@
(fx/defn load-packs
[{:keys [db]}]
(let [contract (contracts/get-address db :status/stickers)
address (ethereum/current-address db)]
(let [contract (contracts/get-address db :status/stickers)
pack-contract (contracts/get-address db :status/sticker-pack)
address (ethereum/current-address db)]
(when contract
{:stickers/owned-packs-fx [contract address]
{:stickers/owned-packs-fx [pack-contract address]
:stickers/load-packs-fx [contract]})))
(fx/defn approve-pack
[{db :db :as cofx} pack-id price]
(let [address (ethereum/current-address db)
stickers-contract (contracts/get-address db :status/stickers)
snt-contract (contracts/get-address db :status/snt)]
(let [address (ethereum/current-address db)
sticker-market-contract (contracts/get-address db :status/sticker-market)
snt-contract (contracts/get-address db :status/snt)]
(signing/eth-transaction-call
cofx
{:contract snt-contract
:method "approveAndCall(address,uint256,bytes)"
:params [stickers-contract
:params [sticker-market-contract
price
(abi-spec/encode "buyToken(uint256,address)" [pack-id address])]
(abi-spec/encode "buyToken(uint256,address,uint256)" [pack-id address price])]
:on-result [:stickers/pending-pack pack-id]})))
(fx/defn pending-pack
[{:keys [db] :as cofx} id]
(let [contract (contracts/get-address db :status/stickers)
(let [contract (contracts/get-address db :status/sticker-pack)
address (ethereum/current-address db)]
(when contract
(fx/merge cofx
@ -171,7 +180,7 @@
(fx/defn pending-timeout
[{{:stickers/keys [packs-pending packs-owned] :as db} :db}]
(let [packs-diff (clojure.set/difference packs-pending packs-owned)
contract (contracts/get-address db :status/stickers)
contract (contracts/get-address db :status/sticker-pack)
address (ethereum/current-address db)]
(when contract
(merge {:db (assoc db :stickers/packs-pending packs-diff)}
@ -184,7 +193,7 @@
(fx/defn get-owned-pack
[{:keys [db]}]
(let [contract (contracts/get-address db :status/stickers)
(let [contract (contracts/get-address db :status/sticker-pack)
address (ethereum/current-address db)]
(when contract
{:stickers/owned-packs-fx [contract address]})))

View File

@ -8,7 +8,8 @@
[status-im.ethereum.ens :as ens]
[status-im.i18n :as i18n]
[status-im.utils.money :as money]
[status-im.utils.fx :as fx]))
[status-im.utils.fx :as fx]
[status-im.utils.handlers :as handlers]))
(fx/defn toggle-flashlight
{:events [:wallet/toggle-flashlight]}