mirror of
https://github.com/status-im/open-bounty.git
synced 2025-02-17 11:56:30 +00:00
Update github comment only when balance changes
This commit is contained in:
parent
c673bb1ded
commit
7fb0f9ddae
@ -0,0 +1,3 @@
|
|||||||
|
-- noinspection SqlResolve
|
||||||
|
ALTER TABLE public.issues
|
||||||
|
DROP COLUMN balance;
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE public.issues
|
||||||
|
ADD balance VARCHAR(32) DEFAULT '0x0';
|
@ -248,3 +248,15 @@ FROM issues i
|
|||||||
INNER JOIN repositories r ON r.repo_id = i.repo_id
|
INNER JOIN repositories r ON r.repo_id = i.repo_id
|
||||||
WHERE i.issue_number = :issue_number
|
WHERE i.issue_number = :issue_number
|
||||||
AND r.login = :login AND r.repo = :repo;
|
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;
|
||||||
|
@ -44,3 +44,14 @@
|
|||||||
[]
|
[]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/list-pending-deployments con-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})))
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
[wei]
|
[wei]
|
||||||
(/ wei 1000000000000000000))
|
(/ wei 1000000000000000000))
|
||||||
|
|
||||||
|
(defn hex->eth
|
||||||
|
[hex digits]
|
||||||
|
(->> hex hex->big-integer from-wei double (format (str "%." digits "f"))))
|
||||||
|
|
||||||
(defn get-balance-hex
|
(defn get-balance-hex
|
||||||
[account]
|
[account]
|
||||||
(eth-rpc "eth_getBalance" [account "latest"]))
|
(eth-rpc "eth_getBalance" [account "latest"]))
|
||||||
@ -42,7 +46,7 @@
|
|||||||
|
|
||||||
(defn get-balance-eth
|
(defn get-balance-eth
|
||||||
[account digits]
|
[account digits]
|
||||||
(->> (get-balance-wei account) from-wei double (format (str "%." digits "f"))))
|
(hex->eth (get-balance-hex account) digits))
|
||||||
|
|
||||||
(defn send-transaction
|
(defn send-transaction
|
||||||
[from to value & [params]]
|
[from to value & [params]]
|
||||||
|
@ -51,8 +51,12 @@
|
|||||||
comment-id :comment_id
|
comment-id :comment_id
|
||||||
issue-number :issue_number} (bounties/list-wallets)]
|
issue-number :issue_number} (bounties/list-wallets)]
|
||||||
(when comment-id
|
(when comment-id
|
||||||
(let [balance (eth/get-balance-eth contract-address 8)]
|
(let [old-balance (issues/get-balance contract-address)
|
||||||
(github/update-comment login repo comment-id issue-number balance)))))
|
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
|
(mount/defstate scheduler :start
|
||||||
(do
|
(do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user