diff --git a/src/clj/commiteth/eth/multisig_wallet.clj b/src/clj/commiteth/eth/multisig_wallet.clj index 157c03d..051444d 100644 --- a/src/clj/commiteth/eth/multisig_wallet.clj +++ b/src/clj/commiteth/eth/multisig_wallet.clj @@ -2,21 +2,25 @@ (:require [commiteth.eth.core :as eth] [clojure.tools.logging :as log])) -(defonce method-ids +(defonce methods {:submit-transaction (eth/sig->method-id "submitTransaction(address,uint256,bytes)") - :withdraw-everything (eth/sig->method-id "withdrawEverything(address)")}) + :withdraw-everything (eth/sig->method-id "withdrawEverything(address)") + :token-balances (eth/sig->method-id "tokenBalances(address)") + :get-token-list (eth/sig->method-id "getTokenList()") + :create (eth/sig->method-id "create(address[],uint256)") + :watch (eth/sig->method-id "watch(address,bytes)")}) -(defonce factory "0xbcBc5b8cE5c76Ed477433636926f76897401f838") +(defonce topics + {:factory-create (eth/event-sig->topic-id "Create(address,address)") + :submission (eth/event-sig->topic-id "Submission(uint256)")}) -(defonce factory-topic "0x96b5b9b8a7193304150caccf9b80d150675fa3d6af57761d8d8ef1d6f9a1a909") +(defonce factory-contract-addr "0xbcBc5b8cE5c76Ed477433636926f76897401f838") -(defonce confirmation-topic "0xc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51") - -(defn create-new +(defn create-new [owner1 owner2 required] (eth/execute (eth/eth-account) - factory - "0xf8f73808" + factory-contract-addr + (:create methods) 0x40 0x2 required @@ -28,7 +32,7 @@ (log/debug "multisig.execute(contract, to, value)" contract to value) (eth/execute (eth/eth-account) contract - (:submit-transaction method-ids) + (:submit-transaction methods) to value "0x60" @@ -38,10 +42,12 @@ (defn find-confirmation-hash [receipt] (let [logs (:logs receipt) - has-confirmation-event #(some (fn [topic] (= topic - confirmation-topic)) + confirmation-topic? (fn [topic] + (= topic + (:submission topics))) + has-confirmation-event? #(some confirmation-topic? (:topics %)) - confirmation-event (first (filter has-confirmation-event logs)) + confirmation-event (first (filter has-confirmation-event? logs)) confirmation-data (:data confirmation-event)] (when confirmation-data (subs confirmation-data 2 66)))) @@ -49,24 +55,26 @@ (defn find-factory-hash [receipt] (let [logs (:logs receipt) - has-factory-event #(some (fn [topic] (= topic - factory-topic)) - (:topics %)) - factory-event (first (filter has-factory-event logs)) + factory-topic? (fn [topic] + (= topic + (:factory-create topics))) + has-factory-event? #(some factory-topic? + (:topics %)) + factory-event (first (filter has-factory-event? logs)) factory-data (:data factory-event)] (when factory-data (subs factory-data 2 66)))) - - + + (defn send-all [contract to] (log/debug "multisig.send-all(contract, to)" contract to) (let [params (eth/format-call-params - (:withdraw-everything method-ids) + (:withdraw-everything methods) to)] (eth/execute (eth/eth-account) contract - (:submit-transaction method-ids) + (:submit-transaction methods) contract 0 "0x60" @@ -74,20 +82,19 @@ params))) - (defn watch-token - [contract token] - (log/debug "multisig.watch-token(contract, token)" contract token) - (eth/execute (eth/eth-account) - contract - "0xf375c07a" - token - 0)) - - (defn token-balance - [contract token] - (eth/call contract "0x523fba7f" token)) +(defn watch-token + [contract token] + (log/debug "multisig.watch-token(contract, token)" contract token) + (eth/execute (eth/eth-account) + contract + (:watch methods) + token + 0)) - (defn tokens-list - [contract] - (eth/call contract "0x273cbaa0")) - +(defn token-balance + [contract token] + (eth/call contract (:token-balances methods) token)) + +(defn tokens-list + [contract] + (eth/call contract (:get-token-list methods)))