Initial changes for comment updates and state transitions
This commit is contained in:
parent
c1158a187f
commit
156d4fd24c
|
@ -267,7 +267,7 @@ SELECT
|
|||
i.tokens AS tokens,
|
||||
i.value_usd AS value_usd,
|
||||
u.login AS winner_login,
|
||||
u.address AS payout_address
|
||||
u.address AS winner_address
|
||||
FROM issues i, pull_requests p, users u, repositories r
|
||||
WHERE
|
||||
p.issue_id = i.issue_id
|
||||
|
@ -322,27 +322,23 @@ AND i.payout_hash IS NOT NULL;
|
|||
-- :name update-confirm-hash :! :n
|
||||
-- :doc updates issue with confirmation hash
|
||||
UPDATE issues
|
||||
SET confirm_hash = :confirm_hash,
|
||||
SET confirm_hash = :confirm-hash,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE issue_id = :issue_id;
|
||||
WHERE issue_id = :issue-id;
|
||||
|
||||
-- :name update-execute-hash :! :n
|
||||
-- :doc updates issue with execute transaction hash
|
||||
-- :name update-execute-hash-and-winner-login :! :n
|
||||
-- :doc updates issue with execute transaction hash and winner login
|
||||
UPDATE issues
|
||||
SET execute_hash = :execute_hash,
|
||||
SET execute_hash = :execute-hash,
|
||||
winner_login = :winner-login,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE issue_id = :issue_id;
|
||||
|
||||
-- :name update-winner-login :! :n
|
||||
UPDATE issues
|
||||
SET winner_login = :winner_login
|
||||
WHERE issue_id = :issue_id;
|
||||
WHERE issue_id = :issue-id;
|
||||
|
||||
-- :name update-watch-hash :! :n
|
||||
-- :doc updates issue with watch transaction hash
|
||||
UPDATE issues
|
||||
SET watch_hash = :watch_hash
|
||||
WHERE issue_id = :issue_id;
|
||||
SET watch_hash = :watch-hash
|
||||
WHERE issue_id = :issue-id;
|
||||
|
||||
-- :name pending-watch-calls :? :*
|
||||
-- :doc issues with a pending watch transaction
|
||||
|
@ -356,9 +352,9 @@ WHERE watch_hash IS NOT NULL;
|
|||
-- :name update-payout-hash :! :n
|
||||
-- :doc updates issue with payout transaction hash
|
||||
UPDATE issues
|
||||
SET payout_hash = :payout_hash,
|
||||
SET payout_hash = :payout-hash,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE issue_id = :issue_id;
|
||||
WHERE issue_id = :issue-id;
|
||||
|
||||
-- :name reset-payout-hash :! :n
|
||||
-- :doc sets issue's payout transaction hash to NULL
|
||||
|
@ -371,26 +367,9 @@ WHERE issue_id = :issue_id;
|
|||
-- :name update-payout-receipt :! :n
|
||||
-- :doc updates issue with payout transaction receipt
|
||||
UPDATE issues
|
||||
SET payout_receipt = :payout_receipt::jsonb,
|
||||
SET payout_receipt = :payout-receipt::jsonb,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE issue_id = :issue_id;
|
||||
|
||||
|
||||
-- :name update-token-balances :! :n
|
||||
-- :doc updates issue with given token balances
|
||||
UPDATE issues
|
||||
SET tokens = :token_balances::jsonb,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE contract_address = :contract_address;
|
||||
|
||||
|
||||
-- :name update-usd-value :! :n
|
||||
-- :doc updates issue with given USD value
|
||||
UPDATE issues
|
||||
SET value_usd = :usd_value,
|
||||
value_usd_updated = timezone('utc'::text, now())
|
||||
WHERE contract_address = :contract_address;
|
||||
|
||||
WHERE issue_id = :issue-id;
|
||||
|
||||
-- :name update-issue-open :! :n
|
||||
-- :doc updates issue's open status
|
||||
|
@ -535,17 +514,19 @@ SELECT
|
|||
r.owner AS owner,
|
||||
r.repo AS repo
|
||||
FROM issues i, repositories r
|
||||
WHERE i.issue_number = :issue_number
|
||||
WHERE i.issue_number = :issue-number
|
||||
AND r.repo_id = i.repo_id
|
||||
AND r.owner = :owner
|
||||
AND r.repo = :repo;
|
||||
|
||||
-- :name update-eth-balance :! :n
|
||||
-- :name update-balances :! :n
|
||||
-- :doc updates balance of a wallet attached to a given issue
|
||||
UPDATE issues
|
||||
SET balance_eth = :balance_eth,
|
||||
SET balance_eth = :balance-eth,
|
||||
tokens = :token-balances::jsonb,
|
||||
value_usd = :usd-value,
|
||||
updated = timezone('utc'::text, now())
|
||||
WHERE contract_address = :contract_address;
|
||||
WHERE contract_address = :contract-address;
|
||||
|
||||
|
||||
-- :name save-issue-comment-image! :<! :1
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
(:require [commiteth.db.issues :as issues]
|
||||
[commiteth.db.users :as users]
|
||||
[commiteth.db.repositories :as repos]
|
||||
[commiteth.db.comment-images :as comment-images]
|
||||
[commiteth.eth.core :as eth]
|
||||
[commiteth.github.core :as github]
|
||||
[commiteth.util.util :refer [to-map]]
|
||||
[commiteth.eth.multisig-wallet :as multisig]
|
||||
[commiteth.util.png-rendering :as png-rendering]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
|
||||
|
@ -30,13 +29,7 @@
|
|||
(do
|
||||
(log/info "Contract deployed, transaction-hash:"
|
||||
transaction-hash)
|
||||
(let [resp (github/post-deploying-comment owner
|
||||
repo
|
||||
issue-number
|
||||
transaction-hash)
|
||||
_ (log/info "post-deploying-comment response:" resp)
|
||||
comment-id (:id resp)]
|
||||
(issues/update-comment-id issue-id comment-id))
|
||||
(github/update-comment (to-map owner repo issue-number transaction-hash))
|
||||
(issues/update-transaction-hash issue-id transaction-hash))
|
||||
(log/error "Failed to deploy contract to" owner-address)))))
|
||||
|
||||
|
@ -45,11 +38,10 @@
|
|||
issue-number :number
|
||||
issue-title :title} issue
|
||||
created-issue (issues/create repo-id issue-id issue-number issue-title)
|
||||
{owner-address :address
|
||||
owner :owner} (users/get-repo-owner repo-id)]
|
||||
(log/debug "Adding bounty for issue " repo issue-number "owner address: " owner-address)
|
||||
{:keys [address owner]} (users/get-repo-owner repo-id)]
|
||||
(log/debug "Adding bounty for issue " repo issue-number "owner address: " address)
|
||||
(if (= 1 created-issue)
|
||||
(deploy-contract owner owner-address repo issue-id issue-number)
|
||||
(deploy-contract owner address repo issue-id issue-number)
|
||||
(log/debug "Issue already exists in DB, ignoring"))))
|
||||
|
||||
(defn maybe-add-bounty-for-issue [repo repo-id issue]
|
||||
|
@ -65,9 +57,8 @@
|
|||
;; We have a max-limit to ensure people can't add more issues and
|
||||
;; drain bot account until we have economic design in place
|
||||
(defn add-bounties-for-existing-issues [full-name]
|
||||
(let [{repo-id :repo_id
|
||||
owner :owner
|
||||
repo :repo} (repos/get-repo full-name)
|
||||
(let [{:keys [repo-id
|
||||
owner repo] } (repos/get-repo full-name)
|
||||
issues (github/get-issues owner repo)
|
||||
bounty-issues (filter has-bounty-label? issues)
|
||||
max-bounties (take max-issues-limit bounty-issues)]
|
||||
|
@ -77,30 +68,13 @@
|
|||
(map (partial maybe-add-bounty-for-issue repo repo-id) max-bounties))))
|
||||
|
||||
|
||||
(defn update-bounty-comment-image [issue-id owner repo issue-number contract-address eth-balance eth-balance-str tokens]
|
||||
(let [hash (github/github-comment-hash owner repo issue-number eth-balance)
|
||||
issue-url (str owner "/" repo "/issues/" (str issue-number))
|
||||
png-data (png-rendering/gen-comment-image
|
||||
contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
issue-url)]
|
||||
(log/debug "update-bounty-comment-image" issue-id owner repo issue-number)
|
||||
(log/debug contract-address eth-balance-str)
|
||||
(log/debug "hash" hash)
|
||||
|
||||
(if png-data
|
||||
(comment-images/save-image! issue-id hash png-data)
|
||||
(log/error "Failed ot generate PNG"))))
|
||||
|
||||
|
||||
(defn update-bounty-issue-titles
|
||||
"Update stored titles for bounty issues if changed on Github side"
|
||||
[]
|
||||
(log/debug "update-bounty-issue-titles")
|
||||
(for [{:keys [title issue_number repo owner]}
|
||||
(for [{:keys [title issue-number repo owner]}
|
||||
(issues/get-issue-titles)]
|
||||
(let [gh-issue (github/get-issue owner repo issue_number)]
|
||||
(let [gh-issue (github/get-issue owner repo issue-number)]
|
||||
(if-not (= title (:title gh-issue))
|
||||
(do
|
||||
(log/info "Updating changed title for issue" (:id gh-issue))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns commiteth.db.bounties
|
||||
(:require [commiteth.db.core :refer [*db*] :as db]
|
||||
[commiteth.util.util :refer [to-db-map]]
|
||||
[clojure.java.jdbc :as jdbc]
|
||||
[clojure.set :refer [rename-keys]]))
|
||||
|
||||
|
@ -43,22 +44,19 @@
|
|||
(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})))
|
||||
(db/update-confirm-hash con-db (to-db-map issue-id confirm-hash))))
|
||||
|
||||
(defn update-execute-hash
|
||||
[issue-id execute-hash]
|
||||
(defn update-execute-hash-and-winner-login
|
||||
[issue-id execute-hash winner-login]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-execute-hash con-db {:issue_id issue-id :execute_hash execute-hash})))
|
||||
|
||||
(defn update-winner-login
|
||||
[issue-id login]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-winner-login con-db {:issue_id issue-id :winner_login login})))
|
||||
(db/update-execute-hash-and-winner-login con-db
|
||||
(to-db-map issue-id execute-hash winner-login)
|
||||
)))
|
||||
|
||||
(defn update-watch-hash
|
||||
[issue-id watch-hash]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-watch-hash con-db {:issue_id issue-id :watch_hash watch-hash})))
|
||||
(db/update-watch-hash con-db (to-db-map issue-id watch-hash))))
|
||||
|
||||
(defn pending-watch-calls
|
||||
[]
|
||||
|
@ -68,7 +66,7 @@
|
|||
(defn update-payout-hash
|
||||
[issue-id payout-hash]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-payout-hash con-db {:issue_id issue-id :payout_hash payout-hash})))
|
||||
(db/update-payout-hash con-db (to-db-map issue-id payout-hash))))
|
||||
|
||||
(defn reset-payout-hash
|
||||
[issue-id]
|
||||
|
@ -78,13 +76,12 @@
|
|||
(defn update-payout-receipt
|
||||
[issue-id payout-receipt]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-payout-receipt con-db {:issue_id issue-id
|
||||
:payout_receipt payout-receipt})))
|
||||
(db/update-payout-receipt con-db (to-db-map issue-id payout-receipt))))
|
||||
|
||||
(defn get-bounty
|
||||
[owner repo issue-number]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/get-bounty con-db {:owner owner :repo repo :issue_number issue-number})))
|
||||
(db/get-bounty con-db (to-db-map owner repo issue-number))))
|
||||
|
||||
(defn open-bounty-contracts
|
||||
[]
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
[mount.core :refer [defstate]]
|
||||
[migratus.core :as migratus]
|
||||
[mpg.core :as mpg]
|
||||
[hugsql.core]
|
||||
[clojure.string :as str])
|
||||
(:import org.postgresql.util.PGobject
|
||||
java.sql.Array
|
||||
|
@ -92,3 +93,30 @@
|
|||
|
||||
(defn update! [& args]
|
||||
(apply jdbc/update! *db* args))
|
||||
|
||||
(defn convert-keys-to-lisp-case [res]
|
||||
(->> res
|
||||
(map #(vector (keyword (str/replace (name (first %1)) "_" "-"))
|
||||
(second %1)))
|
||||
(into {})))
|
||||
|
||||
(defn result-one-sql->lisp
|
||||
[this result options]
|
||||
(convert-keys-to-lisp-case (first result)))
|
||||
|
||||
(defn result-many-sql->lisp
|
||||
[this result options]
|
||||
(map convert-keys-to-lisp-case result))
|
||||
|
||||
(defmethod hugsql.core/hugsql-result-fn :1 [sym]
|
||||
'commiteth.db.core/result-one-sql->lisp)
|
||||
|
||||
(defmethod hugsql.core/hugsql-result-fn :one [sym]
|
||||
'commiteth.db.core/result-one-sql->lisp)
|
||||
|
||||
(defmethod hugsql.core/hugsql-result-fn :* [sym]
|
||||
'commiteth.db.core/result-many-sql->lisp)
|
||||
|
||||
(defmethod hugsql.core/hugsql-result-fn :many [sym]
|
||||
'commiteth.db.core/result-many-sql->lisp)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns commiteth.db.issues
|
||||
(:require [commiteth.db.core :refer [*db*] :as db]
|
||||
[clojure.java.jdbc :as jdbc]
|
||||
[commiteth.util.util :refer [to-db-map]]
|
||||
[clojure.set :refer [rename-keys]]))
|
||||
|
||||
(defn create
|
||||
|
@ -63,23 +64,13 @@
|
|||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/list-pending-deployments con-db)))
|
||||
|
||||
(defn update-eth-balance
|
||||
[contract-address balance-eth]
|
||||
(defn update-balances
|
||||
[contract-address balance-eth token-balances usd-value]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-eth-balance con-db {:contract_address contract-address
|
||||
:balance_eth balance-eth})))
|
||||
|
||||
(defn update-token-balances
|
||||
[contract-address balances]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-token-balances con-db {:contract_address contract-address
|
||||
:token_balances balances})))
|
||||
|
||||
(defn update-usd-value
|
||||
[contract-address usd-value]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/update-usd-value con-db {:contract_address contract-address
|
||||
:usd_value usd-value})))
|
||||
(db/update-balances con-db (to-db-map contract-address
|
||||
balance-eth
|
||||
token-balances
|
||||
usd-value))))
|
||||
|
||||
(defn update-open-status
|
||||
[issue-id is-open]
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
[digest :refer [sha-256]]
|
||||
[clojure.tools.logging :as log]
|
||||
[cheshire.core :as json]
|
||||
[commiteth.util.png-rendering :as png-rendering]
|
||||
[commiteth.db.issues :as db-issues]
|
||||
[commiteth.db.bounties :as db-bounties]
|
||||
[commiteth.db.comment-images :as comment-images]
|
||||
[clojure.string :as str])
|
||||
(:import [java.util UUID]))
|
||||
|
||||
|
@ -271,13 +275,6 @@
|
|||
(learn-more-text))
|
||||
eth-balance-str payee-login))
|
||||
|
||||
|
||||
(defn post-deploying-comment
|
||||
[owner repo issue-number tx-id]
|
||||
(let [comment (generate-deploying-comment owner repo issue-number tx-id)]
|
||||
(log/info "Posting comment to" (str owner "/" repo "/" issue-number) ":" comment)
|
||||
(issues/create-comment owner repo issue-number comment (self-auth-params))))
|
||||
|
||||
(defn make-patch-request [end-point positional query]
|
||||
(let [{:keys [auth oauth-token]
|
||||
:as query} query
|
||||
|
@ -296,54 +293,70 @@
|
|||
:otp))]
|
||||
(assoc req :body (json/generate-string (or raw-query proper-query)))))
|
||||
|
||||
(defn update-bounty-comment-image [issue-id owner repo issue-number contract-address eth-balance eth-balance-str tokens]
|
||||
(let [hash (github-comment-hash owner repo issue-number eth-balance)
|
||||
issue-url (str owner "/" repo "/issues/" (str issue-number))
|
||||
png-data (png-rendering/gen-comment-image
|
||||
contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
issue-url)]
|
||||
(log/debug "update-bounty-comment-image" issue-id owner repo issue-number)
|
||||
(log/debug contract-address eth-balance-str)
|
||||
(log/debug "hash" hash)
|
||||
|
||||
(if png-data
|
||||
(comment-images/save-image! issue-id hash png-data)
|
||||
(log/error "Failed ot generate PNG"))))
|
||||
|
||||
(defn update-comment
|
||||
"Update comment for an open bounty issue"
|
||||
[owner repo comment-id issue-number contract-address eth-balance eth-balance-str tokens]
|
||||
(let [comment (generate-open-comment owner
|
||||
repo
|
||||
issue-number
|
||||
contract-address
|
||||
eth-balance
|
||||
eth-balance-str
|
||||
tokens)]
|
||||
[{:keys [issue-id owner repo comment-id issue-number contract-address
|
||||
eth-balance eth-balance-str tokens
|
||||
payout-receipt
|
||||
winner-login winner-address transaction-hash] :as issue}]
|
||||
(let [state (cond (nil? comment-id) :deployed
|
||||
(not (nil? payout-receipt)) :paid
|
||||
(not (str/blank? winner-login)) :merged
|
||||
:else :open)
|
||||
comment (cond (= state :deployed)
|
||||
(generate-deploying-comment owner repo issue-number transaction-hash)
|
||||
(= state :open)
|
||||
(generate-open-comment owner
|
||||
repo
|
||||
issue-number
|
||||
contract-address
|
||||
eth-balance
|
||||
eth-balance-str
|
||||
tokens)
|
||||
(= state :merged)
|
||||
(generate-merged-comment contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
winner-login
|
||||
(str/blank? winner-address))
|
||||
(= state :paid)
|
||||
(generate-paid-comment contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
winner-login)
|
||||
)]
|
||||
(when (= :paid state)
|
||||
(db-bounties/update-payout-receipt issue-id payout-receipt))
|
||||
|
||||
(when (= :open state)
|
||||
(update-bounty-comment-image issue-id owner repo issue-number contract-address eth-balance eth-balance-str tokens))
|
||||
|
||||
(log/debug (str "Updating " owner "/" repo "/" issue-number
|
||||
" comment #" comment-id " with contents: " comment))
|
||||
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
||||
[owner repo comment-id]
|
||||
(assoc (self-auth-params) :body comment))]
|
||||
(tentacles/safe-parse (http/request req)))))
|
||||
|
||||
|
||||
|
||||
(defn update-merged-issue-comment
|
||||
"Update comment for a bounty issue with winning claim (waiting to be
|
||||
signed off by maintainer/user ETH address missing)"
|
||||
[owner repo comment-id contract-address eth-balance-str tokens winner-login winner-address-missing?]
|
||||
(let [comment (generate-merged-comment contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
winner-login
|
||||
winner-address-missing?)]
|
||||
(log/debug (str "Updating merged bounty issue (" owner "/" repo ")"
|
||||
" comment#" comment-id " with contents: " comment))
|
||||
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
||||
[owner repo comment-id]
|
||||
(assoc (self-auth-params) :body comment))]
|
||||
(tentacles/safe-parse (http/request req)))))
|
||||
|
||||
(defn update-paid-issue-comment
|
||||
"Update comment for a paid out bounty issue"
|
||||
[owner repo comment-id contract-address eth-balance-str tokens payee-login]
|
||||
(let [comment (generate-paid-comment contract-address
|
||||
eth-balance-str
|
||||
tokens
|
||||
payee-login)]
|
||||
(log/debug (str "Updating paid bounty (" owner "/" repo ")"
|
||||
" comment#" comment-id " with contents: " comment))
|
||||
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
||||
[owner repo comment-id]
|
||||
(assoc (self-auth-params) :body comment))]
|
||||
(tentacles/safe-parse (http/request req)))))
|
||||
(if (= state :deployed)
|
||||
(let [resp (issues/create-comment owner repo issue-number comment (self-auth-params))
|
||||
comment-id (:id resp)]
|
||||
(db-issues/update-comment-id issue-id comment-id))
|
||||
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
||||
[owner repo comment-id]
|
||||
(assoc (self-auth-params) :body comment))]
|
||||
(tentacles/safe-parse (http/request req))))))
|
||||
|
||||
(defn get-issue
|
||||
[owner repo issue-number]
|
||||
|
|
|
@ -78,9 +78,7 @@
|
|||
(into {}))))
|
||||
|
||||
(defn top-hunters []
|
||||
(let [renames {:user_name :display-name
|
||||
:avatar_url :avatar-url
|
||||
:total_usd :total-usd}]
|
||||
(let [renames {:user-name :display-name}]
|
||||
(map #(-> %
|
||||
(rename-keys renames)
|
||||
(update :total-usd usd-decimal->str))
|
||||
|
@ -107,16 +105,8 @@
|
|||
(into {})
|
||||
(assoc bounty :tokens)))
|
||||
renames {:user_name :display-name
|
||||
:user_avatar_url :avatar-url
|
||||
:issue_title :issue-title
|
||||
:type :item-type
|
||||
:repo_name :repo-name
|
||||
:repo_owner :repo-owner
|
||||
:issue_number :issue-number
|
||||
:value_usd :value-usd
|
||||
:claim_count :claim-count
|
||||
:balance_eth :balance-eth
|
||||
:user_has_address :user-has-address}]
|
||||
:user-avatar-url :avatar-url
|
||||
:type :item-type }]
|
||||
(map #(-> %
|
||||
(rename-keys renames)
|
||||
(update :value-usd usd-decimal->str)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[commiteth.eth.token-data :as token-data]
|
||||
[commiteth.github.core :as github]
|
||||
[commiteth.db.issues :as issues]
|
||||
[commiteth.util.util :refer [to-map]]
|
||||
[taoensso.tufte :as tufte :refer (defnp p profiled profile)]
|
||||
[commiteth.db.bounties :as db-bounties]
|
||||
[commiteth.bounties :as bounties]
|
||||
|
@ -11,6 +12,7 @@
|
|||
[commiteth.util.util :refer [eth-decimal->str]]
|
||||
[clojure.tools.logging :as log]
|
||||
[mount.core :as mount]
|
||||
[clojure.string :as str]
|
||||
[clj-time.core :as t]
|
||||
[clj-time.coerce :as time-coerce]
|
||||
[clj-time.periodic :refer [periodic-seq]]
|
||||
|
@ -29,12 +31,10 @@
|
|||
(profile {} (update-watch-hash))
|
||||
(profile {} (update-payout-receipt))
|
||||
(profile {} (update-contract-internal-balances))
|
||||
(profile {} (update-open-issue-usd-values))
|
||||
(profile {} (update-balances))
|
||||
(profile {}
|
||||
(doseq [i (range 5)]
|
||||
(update-contract-internal-balances)
|
||||
(update-open-issue-usd-values)
|
||||
(update-balances)))
|
||||
|
||||
)
|
||||
|
@ -44,39 +44,28 @@
|
|||
[]
|
||||
(log/info "In update-issue-contract-address")
|
||||
(p :update-issue-contract-address
|
||||
(doseq [{issue-id :issue_id
|
||||
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
|
||||
(doseq [{:keys [issue-id transaction-hash]} (issues/list-pending-deployments)]
|
||||
(log/info "pending deployment:" transaction-hash)
|
||||
(try
|
||||
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
|
||||
(log/info "update-issue-contract-address: transaction receipt for issue #"
|
||||
issue-id ": " receipt)
|
||||
(if-let [contract-address (multisig/find-created-multisig-address receipt)]
|
||||
(let [issue (issues/update-contract-address issue-id contract-address)
|
||||
{owner :owner
|
||||
repo :repo
|
||||
comment-id :comment_id
|
||||
issue-number :issue_number} issue
|
||||
(let [{:keys [owner repo comment-id issue-number] :as issue}
|
||||
(issues/update-contract-address issue-id contract-address)
|
||||
balance-eth-str (eth/get-balance-eth contract-address 6)
|
||||
balance-eth (read-string balance-eth-str)]
|
||||
(log/info "Updating comment image")
|
||||
(bounties/update-bounty-comment-image issue-id
|
||||
owner
|
||||
repo
|
||||
issue-number
|
||||
contract-address
|
||||
balance-eth
|
||||
balance-eth-str
|
||||
{})
|
||||
balance-eth (read-string balance-eth-str)
|
||||
tokens {}]
|
||||
(log/info "Updating comment")
|
||||
(github/update-comment owner
|
||||
repo
|
||||
comment-id
|
||||
issue-number
|
||||
contract-address
|
||||
balance-eth
|
||||
balance-eth-str
|
||||
{}))
|
||||
(github/update-comment (to-map issue-id
|
||||
owner
|
||||
repo
|
||||
comment-id
|
||||
issue-number
|
||||
contract-address
|
||||
balance-eth
|
||||
balance-eth-str
|
||||
tokens)))
|
||||
(log/error "Failed to find contract address in tx logs")))
|
||||
(catch Throwable ex
|
||||
(do (log/error "update-issue-contract-address exception:" ex)
|
||||
|
@ -88,11 +77,8 @@
|
|||
"Under high-concurrency circumstances or in case geth is in defunct state, a bounty contract may not deploy successfully when the bounty label is addded to an issue. This function deploys such contracts."
|
||||
[]
|
||||
(p :deploy-pending-contracts
|
||||
(doseq [{issue-id :issue_id
|
||||
issue-number :issue_number
|
||||
owner :owner
|
||||
owner-address :owner_address
|
||||
repo :repo} (db-bounties/pending-contracts)]
|
||||
(doseq [{:keys [issue-id issue-number owner owner-address repo]}
|
||||
(db-bounties/pending-contracts)]
|
||||
(log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id)
|
||||
(bounties/deploy-contract owner owner-address repo issue-id issue-number))))
|
||||
|
||||
|
@ -101,54 +87,26 @@
|
|||
[]
|
||||
(log/info "In self-sign-bounty")
|
||||
(p :self-sign-bounty
|
||||
(doseq [{contract-address :contract_address
|
||||
issue-id :issue_id
|
||||
payout-address :payout_address
|
||||
repo :repo
|
||||
owner :owner
|
||||
comment-id :comment_id
|
||||
issue-number :issue_number
|
||||
balance-eth :balance_eth
|
||||
tokens :tokens
|
||||
winner-login :winner_login} (db-bounties/pending-bounties)]
|
||||
(try
|
||||
(let [value (eth/get-balance-hex contract-address)]
|
||||
(if (empty? payout-address)
|
||||
(do
|
||||
(log/error "Cannot sign pending bounty - winner has no payout address")
|
||||
(github/update-merged-issue-comment owner
|
||||
repo
|
||||
comment-id
|
||||
contract-address
|
||||
(eth-decimal->str balance-eth)
|
||||
tokens
|
||||
winner-login
|
||||
true))
|
||||
(let [execute-hash (multisig/send-all contract-address payout-address)]
|
||||
(log/info "Payout self-signed, called sign-all(" contract-address payout-address ") tx:" execute-hash)
|
||||
(db-bounties/update-execute-hash issue-id execute-hash)
|
||||
(db-bounties/update-winner-login issue-id winner-login)
|
||||
(github/update-merged-issue-comment owner
|
||||
repo
|
||||
comment-id
|
||||
contract-address
|
||||
(eth-decimal->str balance-eth)
|
||||
tokens
|
||||
winner-login
|
||||
false))))
|
||||
(catch Throwable ex
|
||||
(do (log/error "self-sign-bounty exception:" ex)
|
||||
(clojure.stacktrace/print-stack-trace ex))))))
|
||||
(log/info "Exit self-sign-bounty")
|
||||
)
|
||||
(doseq [{:keys [contract-address winner-address issue-id winner-login] :as issue}
|
||||
(db-bounties/pending-bounties)]
|
||||
(try
|
||||
(let [value (eth/get-balance-hex contract-address)]
|
||||
(when-not (empty? winner-address)
|
||||
(let [execute-hash (multisig/send-all contract-address winner-address)]
|
||||
(log/info "Payout self-signed, called sign-all(" contract-address winner-address ") tx:" execute-hash)
|
||||
(db-bounties/update-execute-hash-and-winner-login issue-id execute-hash winner-login)))
|
||||
(github/update-comment issue))
|
||||
(catch Throwable ex
|
||||
(do (log/error "self-sign-bounty exception:" ex)
|
||||
(clojure.stacktrace/print-stack-trace ex))))))
|
||||
(log/info "Exit self-sign-bounty"))
|
||||
|
||||
(defn update-confirm-hash
|
||||
"Gets transaction receipt for each pending payout and updates DB confirm_hash with tranaction ID of commiteth bot account's confirmation."
|
||||
[]
|
||||
(log/info "In update-confirm-hash")
|
||||
(p :update-confirm-hash
|
||||
(doseq [{issue-id :issue_id
|
||||
execute-hash :execute_hash} (db-bounties/pending-payouts)]
|
||||
(doseq [{:keys [issue-id execute-hash]} (db-bounties/pending-payouts)]
|
||||
(log/info "pending payout:" execute-hash)
|
||||
(when-let [receipt (eth/get-transaction-receipt execute-hash)]
|
||||
(log/info "execution receipt for issue #" issue-id ": " receipt)
|
||||
|
@ -162,8 +120,7 @@
|
|||
"Sets watch-hash to NULL for bounties where watch tx has been mined. Used to avoid unneeded watch transactions in update-bounty-token-balances"
|
||||
[]
|
||||
(p :update-watch-hash
|
||||
(doseq [{issue-id :issue_id
|
||||
watch-hash :watch_hash} (db-bounties/pending-watch-calls)]
|
||||
(doseq [{:keys [issue-id watch-hash]} (db-bounties/pending-watch-calls)]
|
||||
(log/info "pending watch call" watch-hash)
|
||||
(when-let [receipt (eth/get-transaction-receipt watch-hash)]
|
||||
(db-bounties/update-watch-hash issue-id nil)))))
|
||||
|
@ -182,18 +139,8 @@
|
|||
[]
|
||||
(log/info "In update-payout-receipt")
|
||||
(p :update-payout-receipt
|
||||
(doseq [{issue-id :issue_id
|
||||
payout-hash :payout_hash
|
||||
contract-address :contract_address
|
||||
repo :repo
|
||||
owner :owner
|
||||
comment-id :comment_id
|
||||
issue-number :issue_number
|
||||
balance-eth :balance_eth
|
||||
tokens :tokens
|
||||
confirm-id :confirm_hash
|
||||
payee-login :payee_login
|
||||
updated :updated} (db-bounties/confirmed-payouts)]
|
||||
(doseq [{:keys [payout-hash contract-address confirm-hash issue-id updated] :as issue}
|
||||
(db-bounties/confirmed-payouts)]
|
||||
(log/debug "confirmed payout:" payout-hash)
|
||||
(try
|
||||
(if-let [receipt (eth/get-transaction-receipt payout-hash)]
|
||||
|
@ -204,21 +151,14 @@
|
|||
(> contract-eth-balance 0))
|
||||
(do
|
||||
(log/info "Contract still has funds")
|
||||
(when (multisig/is-confirmed? contract-address confirm-id)
|
||||
(when (multisig/is-confirmed? contract-address confirm-hash)
|
||||
(log/info "Detected bounty with funds and confirmed payout, calling executeTransaction")
|
||||
(let [execute-tx-hash (multisig/execute-tx contract-address confirm-id)]
|
||||
(let [execute-tx-hash (multisig/execute-tx contract-address confirm-hash)]
|
||||
(log/info "execute tx:" execute-tx-hash))))
|
||||
|
||||
(do
|
||||
(log/info "Payout has succeeded, saving payout receipt for issue #" issue-id ": " receipt)
|
||||
(db-bounties/update-payout-receipt issue-id receipt)
|
||||
(github/update-paid-issue-comment owner
|
||||
repo
|
||||
comment-id
|
||||
contract-address
|
||||
(eth-decimal->str balance-eth)
|
||||
tokens
|
||||
payee-login))))
|
||||
(github/update-comment (assoc issue :payout-receipt receipt)))))
|
||||
(when (older-than-3h? updated)
|
||||
(log/info "Resetting payout hash for issue" issue-id "as it has not been mined in 3h")
|
||||
(db-bounties/reset-payout-hash issue-id)))
|
||||
|
@ -265,39 +205,11 @@
|
|||
[]
|
||||
(log/info "In update-contract-internal-balances")
|
||||
(p :update-contract-internal-balances
|
||||
(doseq [{issue-id :issue_id
|
||||
bounty-address :contract_address
|
||||
watch-hash :watch_hash}
|
||||
(doseq [{:keys [issue-id bounty-address watch-hash]}
|
||||
(db-bounties/open-bounty-contracts)]
|
||||
(update-bounty-token-balances issue-id bounty-address watch-hash)))
|
||||
(log/info "Exit update-contract-internal-balances"))
|
||||
|
||||
(defn get-bounty-funds
|
||||
"Get funds in given bounty contract.
|
||||
Returns map of asset -> balance
|
||||
+ key total-usd -> current total USD value for all funds"
|
||||
[bounty-addr]
|
||||
(let [token-balances (multisig/token-balances bounty-addr)
|
||||
eth-balance (read-string (eth/get-balance-eth bounty-addr 6))
|
||||
all-funds
|
||||
(merge token-balances
|
||||
{:ETH eth-balance})]
|
||||
(merge all-funds {:total-usd (fiat-util/bounty-usd-value all-funds)})))
|
||||
|
||||
|
||||
(defn update-issue-usd-value
|
||||
[bounty-addr]
|
||||
(let [funds (get-bounty-funds bounty-addr)]
|
||||
(issues/update-usd-value bounty-addr
|
||||
(:total-usd funds))))
|
||||
|
||||
(defn update-open-issue-usd-values
|
||||
"Sum up current USD values of all crypto assets in a bounty and store to DB"
|
||||
[]
|
||||
(p :update-open-issue-usd-values
|
||||
(doseq [{bounty-addr :contract_address}
|
||||
(db-bounties/open-bounty-contracts)]
|
||||
(update-issue-usd-value bounty-addr))))
|
||||
|
||||
(defn float=
|
||||
([x y] (float= x y 0.0000001))
|
||||
|
@ -314,55 +226,38 @@
|
|||
[]
|
||||
(log/info "In update-balances")
|
||||
(p :update-balances
|
||||
(doseq [{contract-address :contract_address
|
||||
owner :owner
|
||||
repo :repo
|
||||
comment-id :comment_id
|
||||
issue-id :issue_id
|
||||
db-balance-eth :balance_eth
|
||||
db-tokens :tokens
|
||||
issue-number :issue_number} (db-bounties/open-bounty-contracts)]
|
||||
(try
|
||||
(when comment-id
|
||||
(let [balance-eth-str (eth/get-balance-eth contract-address 6)
|
||||
balance-eth (read-string balance-eth-str)
|
||||
token-balances (multisig/token-balances contract-address)]
|
||||
(log/debug "update-balances" balance-eth
|
||||
balance-eth-str token-balances owner repo issue-number)
|
||||
(doseq [{:keys [contract-address owner
|
||||
repo balance-eth tokens
|
||||
issue-number
|
||||
comment-id] :as issue}
|
||||
(db-bounties/open-bounty-contracts)]
|
||||
(try
|
||||
(when comment-id
|
||||
(let [balance-eth-str (eth/get-balance-eth contract-address 6)
|
||||
current-balance-eth (read-string balance-eth-str)
|
||||
token-balances (multisig/token-balances contract-address)]
|
||||
(log/debug "update-balances" balance-eth
|
||||
balance-eth-str token-balances owner repo issue-number)
|
||||
|
||||
(when (or
|
||||
(not (float= db-balance-eth balance-eth))
|
||||
(not (map-float= db-tokens token-balances)))
|
||||
(log/info "balances differ")
|
||||
(log/info "ETH (db):" db-balance-eth (type db-balance-eth) )
|
||||
(log/info "ETH (chain):" balance-eth (type balance-eth) )
|
||||
(log/info "ETH cmp:" (float= db-balance-eth balance-eth))
|
||||
(log/info "tokens (db):" db-tokens (type db-tokens) (type (:SNT db-tokens)))
|
||||
(log/info "tokens (chain):" token-balances (type token-balances) (type (:SNT token-balances)))
|
||||
(log/debug "tokens cmp:" (= db-tokens token-balances))
|
||||
(when (or
|
||||
(not (float= current-balance-eth balance-eth))
|
||||
(not (map-float= tokens token-balances)))
|
||||
(log/info "balances differ")
|
||||
(log/info "ETH (db):" balance-eth (type balance-eth) )
|
||||
(log/info "ETH (chain):" current-balance-eth (type current-balance-eth) )
|
||||
(log/info "ETH cmp:" (float= balance-eth current-balance-eth))
|
||||
(log/info "tokens (db):" tokens (type tokens) (type (:SNT tokens)))
|
||||
(log/info "tokens (chain):" token-balances (type token-balances) (type (:SNT token-balances)))
|
||||
(log/debug "tokens cmp:" (= tokens token-balances))
|
||||
|
||||
(issues/update-eth-balance contract-address balance-eth)
|
||||
(issues/update-token-balances contract-address token-balances)
|
||||
(bounties/update-bounty-comment-image issue-id
|
||||
owner
|
||||
repo
|
||||
issue-number
|
||||
contract-address
|
||||
balance-eth
|
||||
balance-eth-str
|
||||
token-balances)
|
||||
(github/update-comment owner
|
||||
repo
|
||||
comment-id
|
||||
issue-number
|
||||
contract-address
|
||||
balance-eth
|
||||
balance-eth-str
|
||||
token-balances)
|
||||
(update-issue-usd-value contract-address))))
|
||||
(catch Throwable ex
|
||||
(do (log/error "update-balances exception:" ex)
|
||||
(clojure.stacktrace/print-stack-trace ex))))))
|
||||
(issues/update-balances contract-address
|
||||
current-balance-eth token-balances
|
||||
(fiat-util/bounty-usd-value
|
||||
(merge token-balances {:ETH current-balance-eth})))
|
||||
(github/update-comment issue))))
|
||||
(catch Throwable ex
|
||||
(do (log/error "update-balances exception:" ex)
|
||||
(clojure.stacktrace/print-stack-trace ex))))))
|
||||
(log/info "Exit update-balances"))
|
||||
|
||||
|
||||
|
@ -398,8 +293,7 @@
|
|||
(log/info "run-10-min-interval-tasks" time)
|
||||
(run-tasks
|
||||
[update-contract-internal-balances
|
||||
update-balances
|
||||
update-open-issue-usd-values])
|
||||
update-balances])
|
||||
(log/info "run-10-min-interval-tasks done")))
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns commiteth.util.png-rendering
|
||||
(:require [commiteth.layout :refer [render]]
|
||||
[commiteth.config :refer [env]]
|
||||
[commiteth.github.core :as github]
|
||||
[commiteth.db.comment-images :as db]
|
||||
[commiteth.db.bounties :as db-bounties]
|
||||
[clj.qrgen :as qr]
|
||||
|
@ -58,21 +57,6 @@
|
|||
nil))))
|
||||
|
||||
|
||||
(defn export-comment-image
|
||||
"Retrieve image PNG from DB and write to file"
|
||||
[owner repo issue-number filename]
|
||||
(let [{owner :owner
|
||||
repo :repo
|
||||
issue-id :issue_id
|
||||
balance-eth :balance_eth} (db-bounties/get-bounty owner repo issue-number)
|
||||
hash (github/github-comment-hash
|
||||
owner
|
||||
repo
|
||||
issue-number
|
||||
balance-eth)]
|
||||
(with-open [w (io/output-stream filename)]
|
||||
(.write w (:png_data (db/get-image-data issue-id hash))))))
|
||||
|
||||
|
||||
(comment
|
||||
(with-open [w (io/output-stream "foo.png")]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns commiteth.util.util
|
||||
(:require
|
||||
[clj-http.client :as http]
|
||||
[clojure.string :as str]
|
||||
[clojure.data.json :as json]))
|
||||
|
||||
|
||||
|
@ -14,3 +15,10 @@
|
|||
(->> (http/get url)
|
||||
(:body)
|
||||
(json/read-str)))
|
||||
|
||||
(defmacro to-map [& vars]
|
||||
(into {} (map #(vector (keyword %1) %1) vars)))
|
||||
|
||||
(defmacro to-db-map [& vars]
|
||||
(into {} (map #(vector (keyword (str/replace (name %1) "-" "_")) %1) vars)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue