Sign transaction

This commit is contained in:
kagel 2016-09-10 02:06:56 +03:00
parent fcbf26e775
commit c1af7788eb
7 changed files with 67 additions and 3 deletions

View File

@ -3,5 +3,7 @@ ALTER TABLE public.issues
DROP COLUMN transaction_hash;
ALTER TABLE public.issues
DROP COLUMN contract_address;
ALTER TABLE public.issues
DROP COLUMN confirm_hash;
ALTER TABLE public.issues
ADD address VARCHAR(256);

View File

@ -2,6 +2,8 @@ ALTER TABLE public.issues
ADD transaction_hash VARCHAR(128) NULL;
ALTER TABLE public.issues
ADD contract_address VARCHAR(42) NULL;
ALTER TABLE public.issues
ADD confirm_hash VARCHAR(128) NULL;
-- noinspection SqlResolve
ALTER TABLE public.issues
DROP COLUMN address;

View File

@ -155,6 +155,26 @@ INSERT INTO pull_requests (repo_id, pr_id, pr_number, issue_number, commit_id, u
-- Bounties ------------------------------------------------------------------------
-- :name pending-bounties-list :? :*
-- :doc lists all recently closed issues awaiting to be signed
SELECT
i.contract_address AS contract_address,
i.issue_id AS issue_id,
u.address AS payout_address
FROM issues i
INNER JOIN pull_requests p
ON (p.commit_id = i.commit_id OR coalesce(p.issue_number, -1) = i.issue_number)
AND p.repo_id = i.repo_id
INNER JOIN users u
ON u.id = p.user_id
WHERE i.confirm_hash IS NULL;
-- :name update-confirm-hash :! :n
-- :doc updates issue with transaction hash
UPDATE issues
SET confirm_hash = :confirm_hash
WHERE issue_id = :issue_id;
-- :name bounties-list :? :*
-- :doc lists fixed issues
SELECT

View File

@ -13,3 +13,13 @@
[owner-id]
(jdbc/with-db-connection [con-db *db*]
(db/issues-list con-db {:owner_id owner-id})))
(defn pending-bounties-list
[]
(jdbc/with-db-connection [con-db *db*]
(db/pending-bounties-list con-db)))
(defn update-confirm-hash
[issue-id confirm-hash]
(jdbc/with-db-connection [con-db *db*]
(db/update-confirm-hash con-db {:issue_id issue-id :confirm_hash confirm-hash})))

View File

@ -32,9 +32,13 @@
[wei]
(/ wei 1000000000000000000))
(defn get-balance-hex
[account]
(eth-rpc "eth_getBalance" [account "latest"]))
(defn get-balance-wei
[account]
(hex->big-integer (eth-rpc "eth_getBalance" [account "latest"])))
(hex->big-integer (get-balance-hex account)))
(defn get-balance-eth
[account digits]

View File

@ -12,3 +12,11 @@
(defn add-owner
[contract owner]
(eth/execute (eth/eth-account) contract "0x7065cb48" owner))
(defn execute
[contract to value]
(eth/execute (eth/eth-account) contract "0xb61d27f6" to value))
(defn confirm
[contract hash]
(eth/execute (eth/eth-account) contract "0x797af627" hash))

View File

@ -4,13 +4,17 @@
[commiteth.github.core :as github]
[commiteth.db.issues :as issues]
[commiteth.db.users :as users]
[commiteth.db.bounties :as bounties]
[overtone.at-at :refer [every mk-pool]]
[clojure.tools.logging :as log]
[mount.core :as mount]))
(def pool (mk-pool))
(defn update-issue-contract-address []
(defn update-issue-contract-address
"For each pending deployment:
gets transasction receipt, updates db state, posts github comment and adds owners to the wallet"
[]
(for [{issue-id :issue_id
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
@ -27,4 +31,18 @@
(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))
(defn self-sign-bounty
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
[]
(for [{contract-address :contract_address
issue-id :issue_id
payout-address :payout_address} (bounties/pending-bounties-list)]
(let [value (eth/get-balance-hex contract-address)]
(->>
(wallet/execute contract-address payout-address value)
(bounties/update-confirm-hash issue-id)))))
(mount/defstate scheduler :start
(do
(every (* 5 60 1000) update-issue-contract-address pool)
(every (* 60 1000) self-sign-bounty pool)))