diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 81316d8..c17641b 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -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! :> 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) + diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index fe4b6ce..806828c 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -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] diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index a121461..9e293d9 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -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] diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index ce5d426..5e5e475 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -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) diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 8400033..04d8136 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -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"))) diff --git a/src/clj/commiteth/util/png_rendering.clj b/src/clj/commiteth/util/png_rendering.clj index 997ad5a..1bd31aa 100644 --- a/src/clj/commiteth/util/png_rendering.clj +++ b/src/clj/commiteth/util/png_rendering.clj @@ -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")] diff --git a/src/clj/commiteth/util/util.clj b/src/clj/commiteth/util/util.clj index f85211e..d95cdec 100644 --- a/src/clj/commiteth/util/util.clj +++ b/src/clj/commiteth/util/util.clj @@ -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))) +