[#7611] Update stickers contract and use "approveAndCall" feature

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-02-28 13:31:25 +01:00
parent 38aca129cd
commit 59feb5ecd8
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
4 changed files with 6 additions and 21 deletions

View File

@ -1716,11 +1716,6 @@
(fn [cofx [_ id price]] (fn [cofx [_ id price]]
(stickers/approve-pack cofx id price))) (stickers/approve-pack cofx id price)))
(handlers/register-handler-fx
:stickers/buy-token
(fn [cofx [_ id]]
(stickers/buy-token cofx id)))
(handlers/register-handler-fx (handlers/register-handler-fx
:stickers/get-owned-packs :stickers/get-owned-packs
(fn [cofx _] (fn [cofx _]

View File

@ -73,25 +73,17 @@
(when on-result {:on-result on-result}) (when on-result {:on-result on-result})
tx)) tx))
(fx/defn buy-token [{{:keys [network] :as db} :db} pack-id]
(let [network (get-in db [:account/account :networks network])
address (ethereum/normalized-address (get-in db [:account/account :address]))
tx-object {:to (get ethereum.stickers/contracts (ethereum/network->chain-keyword network))
:data (abi-spec/encode "buyToken(uint256,address)" [pack-id address])}]
(models.wallet/open-modal-wallet-for-transaction
db
(prepare-transaction "buy" tx-object [:stickers/pending-pack pack-id])
tx-object)))
(fx/defn approve-pack [{db :db} pack-id price] (fx/defn approve-pack [{db :db} pack-id price]
(let [network (get-in db [:account/account :networks (:network db)]) (let [network (get-in db [:account/account :networks (:network db)])
address (ethereum/normalized-address (get-in db [:account/account :address]))
chain (ethereum/network->chain-keyword network) chain (ethereum/network->chain-keyword network)
stickers-contract (get ethereum.stickers/contracts chain) stickers-contract (get ethereum.stickers/contracts chain)
data (abi-spec/encode "buyToken(uint256,address)" [pack-id address])
tx-object {:to (get erc20/snt-contracts chain) tx-object {:to (get erc20/snt-contracts chain)
:data (abi-spec/encode "approve(address,uint256)" [stickers-contract price])}] :data (abi-spec/encode "approveAndCall(address,uint256,bytes)" [stickers-contract price data])}]
(models.wallet/open-modal-wallet-for-transaction (models.wallet/open-modal-wallet-for-transaction
db db
(prepare-transaction "approve" tx-object [:stickers/buy-token pack-id]) (prepare-transaction "approve" tx-object [:stickers/pending-pack pack-id])
tx-object))) tx-object)))
(fx/defn pending-pack [{{:keys [web3 network] :as db} :db :as cofx} id] (fx/defn pending-pack [{{:keys [web3 network] :as db} :db :as cofx} id]

View File

@ -96,9 +96,7 @@
encoded-value (if encoded-value? encoded-value (if encoded-value?
(subs value 2) (subs value 2)
(from-utf8 value))] (from-utf8 value))]
(str (when dynamic? (enc {:type :int :value (if encoded-value? (str (when dynamic? (enc {:type :int :value (/ (count encoded-value) 2)}))
(count encoded-value)
(/ (count encoded-value) 2))}))
(right-pad encoded-value)))) (right-pad encoded-value))))
;; string: enc(X) = enc(enc_utf8(X)), i.e. X is utf-8 encoded and this ;; string: enc(X) = enc(enc_utf8(X)), i.e. X is utf-8 encoded and this

View File

@ -4,7 +4,7 @@
(def contracts (def contracts
{:mainnet nil {:mainnet nil
:testnet "0x82694E3DeabE4D6f4e6C180Fe6ad646aB8EF53ae" :testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"
:rinkeby nil}) :rinkeby nil})
(defn pack-count [web3 contract cb] (defn pack-count [web3 contract cb]