Add multisig wallet owners

This commit is contained in:
kagel 2016-09-09 03:35:28 +03:00
parent 21a9682c5c
commit fcbf26e775
6 changed files with 64 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" /> <statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type <!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
@ -32,8 +32,8 @@
<AppenderRef ref="STDOUT"/> <AppenderRef ref="STDOUT"/>
<AppenderRef ref="FILE"/> <AppenderRef ref="FILE"/>
</logger> </logger>
<root level="INFO"> <root level="DEBUG">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT"/>
<appender-ref ref="FILE" /> <appender-ref ref="FILE"/>
</root> </root>
</configuration> </configuration>

View File

@ -40,6 +40,12 @@ SELECT *
FROM users FROM users
WHERE id = :id; WHERE id = :id;
-- :name get-repo-owner :? :1
SELECT *
FROM users u
INNER JOIN repositories r ON r.user_id = u.id
WHERE r.repo_id = :repo_id;
-- Repositories -------------------------------------------------------------------- -- Repositories --------------------------------------------------------------------
-- :name toggle-repository! :<! :1 -- :name toggle-repository! :<! :1
@ -111,6 +117,7 @@ WITH t AS (
i.title AS title, i.title AS title,
i.transaction_hash AS transaction_hash, i.transaction_hash AS transaction_hash,
i.contract_address AS contract_address, i.contract_address AS contract_address,
i.repo_id AS repo_id,
r.login AS login, r.login AS login,
r.repo AS repo r.repo AS repo
FROM issues i FROM issues i
@ -120,7 +127,7 @@ WITH t AS (
UPDATE issues i UPDATE issues i
SET contract_address = :contract_address SET contract_address = :contract_address
FROM t FROM t
RETURNING t.issue_id, t.issue_number, t.title, t.transaction_hash, t.contract_address, t.login, t.repo; RETURNING t.issue_id, t.issue_number, t.title, t.transaction_hash, t.contract_address, t.login, t.repo, t.repo_id;
-- :name list-pending-deployments :? :* -- :name list-pending-deployments :? :*
-- :doc retrieves pending transaction ids -- :doc retrieves pending transaction ids

View File

@ -35,3 +35,9 @@
[user-id token] [user-id token]
(jdbc/with-db-connection [con-db *db*] (jdbc/with-db-connection [con-db *db*]
(db/update-user-token! con-db {:id user-id :token token}))) (db/update-user-token! con-db {:id user-id :token token})))
(defn get-repo-owner
"Gets repository owner by given repository id"
[repo-id]
(jdbc/with-db-connection [con-db *db*]
(db/get-repo-owner {:repo_id repo-id})))

View File

@ -3,6 +3,7 @@
[org.httpkit.client :refer [post]] [org.httpkit.client :refer [post]]
[clojure.java.io :as io] [clojure.java.io :as io]
[commiteth.config :refer [env]] [commiteth.config :refer [env]]
[clojure.string :refer [join]]
[clojure.tools.logging :as log])) [clojure.tools.logging :as log]))
(def eth-rpc-url "http://localhost:8545") (def eth-rpc-url "http://localhost:8545")
@ -18,6 +19,7 @@
options {:body body} options {:body body}
response (:body @(post eth-rpc-url options)) response (:body @(post eth-rpc-url options))
result (json/read-str response :key-fn keyword)] result (json/read-str response :key-fn keyword)]
(log/debug body "\n" result)
(when-let [error (:error result)] (when-let [error (:error result)]
(log/error "Method: " method ", error: " error)) (log/error "Method: " method ", error: " error))
(:result result))) (:result result)))
@ -55,3 +57,24 @@
(send-transaction (eth-account) nil 1 (send-transaction (eth-account) nil 1
{:gas 1248650 {:gas 1248650
:data contract-code}))) :data contract-code})))
(defn- format-param
[param]
(if (number? param)
(format "%064x" param)
(clojure.string/replace (format "%64s" (subs param 2)) " " "0")))
(defn- format-call-params
[method-id & params]
(let [params (join (map format-param params))]
(str method-id params)))
(defn call
[contract method-id & params]
(let [data (apply format-call-params method-id params)]
(eth-rpc "eth_call" [{:to contract :data data} "latest"])))
(defn execute
[from contract method-id & params]
(let [data (apply format-call-params method-id params)]
(send-transaction from contract 1 {:data data})))

View File

@ -0,0 +1,14 @@
(ns commiteth.eth.multisig-wallet
(:require [commiteth.eth.core :as eth]))
(defn is-owner?
[contract address]
(eth/call contract "0x0ed5bc12" address))
(defn get-owner
[contract index]
(eth/call contract "0xc41a360a" index))
(defn add-owner
[contract owner]
(eth/execute (eth/eth-account) contract "0x7065cb48" owner))

View File

@ -1,7 +1,9 @@
(ns commiteth.scheduler (ns commiteth.scheduler
(:require [commiteth.eth.core :as eth] (:require [commiteth.eth.core :as eth]
[commiteth.eth.multisig-wallet :as wallet]
[commiteth.github.core :as github] [commiteth.github.core :as github]
[commiteth.db.issues :as issues] [commiteth.db.issues :as issues]
[commiteth.db.users :as users]
[overtone.at-at :refer [every mk-pool]] [overtone.at-at :refer [every mk-pool]]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[mount.core :as mount])) [mount.core :as mount]))
@ -9,17 +11,20 @@
(def pool (mk-pool)) (def pool (mk-pool))
(defn update-issue-contract-address [] (defn update-issue-contract-address []
(println "Hi.")
(for [{issue-id :issue_id (for [{issue-id :issue_id
transaction-hash :transaction_hash} (issues/list-pending-deployments)] transaction-hash :transaction_hash} (issues/list-pending-deployments)]
(when-let [receipt (eth/get-transaction-receipt transaction-hash)] (when-let [receipt (eth/get-transaction-receipt transaction-hash)]
(log/info "transaction receipt for issue #" issue-id ": " receipt) (log/info "transaction receipt for issue #" issue-id ": " receipt)
(when-let [contract-address (:contractAddress receipt)] (when-let [contract-address (:contractAddress receipt)]
(let [issue (issues/update-contract-address issue-id contract-address) (let [issue (issues/update-contract-address issue-id contract-address)
{user :login {user :login
repo :repo repo :repo
repo-id :repo_id
issue-number :issue_number} issue issue-number :issue_number} issue
balance (eth/get-balance-eth contract-address 4)] balance (eth/get-balance-eth contract-address 4)
(github/post-comment user repo issue-number contract-address balance)))))) repo-owner-address (:address (users/get-repo-owner repo-id))]
(github/post-comment user repo issue-number contract-address balance)
(wallet/add-owner contract-address (eth/eth-account))
(wallet/add-owner contract-address repo-owner-address))))))
(mount/defstate scheduler :start (every (* 5 60 1000) update-issue-contract-address pool)) (mount/defstate scheduler :start (every (* 5 60 1000) update-issue-contract-address pool))