Update github comment only when balance changes

This commit is contained in:
kagel 2016-09-13 19:50:04 +03:00
parent c673bb1ded
commit 7fb0f9ddae
6 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,3 @@
-- noinspection SqlResolve
ALTER TABLE public.issues
DROP COLUMN balance;

View File

@ -0,0 +1,2 @@
ALTER TABLE public.issues
ADD balance VARCHAR(32) DEFAULT '0x0';

View File

@ -248,3 +248,15 @@ FROM issues i
INNER JOIN repositories r ON r.repo_id = i.repo_id
WHERE i.issue_number = :issue_number
AND r.login = :login AND r.repo = :repo;
-- :name get-balance :? :1
-- :doc gets current balance of a wallet attached to a given issue
SELECT balance
FROM issues
WHERE contract_address = :contract_address;
-- :name update-banlance :! :n
-- :doc updates balance of a wallet attached to a given issue
UPDATE issues
SET balance = :balance
WHERE contract_address = :contract_address;

View File

@ -44,3 +44,14 @@
[]
(jdbc/with-db-connection [con-db *db*]
(db/list-pending-deployments con-db)))
(defn get-balance
[contract-address]
(jdbc/with-db-connection [con-db *db*]
(db/get-balance con-db {:contract_address contract-address})))
(defn update-balance
[contract-address balance]
(jdbc/with-db-connection [con-db *db*]
(db/update-balance con-db {:contract_address contract-address
:balance balance})))

View File

@ -32,6 +32,10 @@
[wei]
(/ wei 1000000000000000000))
(defn hex->eth
[hex digits]
(->> hex hex->big-integer from-wei double (format (str "%." digits "f"))))
(defn get-balance-hex
[account]
(eth-rpc "eth_getBalance" [account "latest"]))
@ -42,7 +46,7 @@
(defn get-balance-eth
[account digits]
(->> (get-balance-wei account) from-wei double (format (str "%." digits "f"))))
(hex->eth (get-balance-hex account) digits))
(defn send-transaction
[from to value & [params]]

View File

@ -51,8 +51,12 @@
comment-id :comment_id
issue-number :issue_number} (bounties/list-wallets)]
(when comment-id
(let [balance (eth/get-balance-eth contract-address 8)]
(github/update-comment login repo comment-id issue-number balance)))))
(let [old-balance (issues/get-balance contract-address)
current-balance-hex (eth/get-balance-hex contract-address)
current-balance-eth (eth/hex->eth current-balance-hex 8)]
(when-not (= old-balance current-balance-hex)
(issues/update-balance contract-address current-balance-hex)
(github/update-comment login repo comment-id issue-number current-balance-eth))))))
(mount/defstate scheduler :start
(do