Include token balances in Github issue comment

This commit is contained in:
Teemu Patja 2017-08-22 22:16:45 +03:00
parent 31d8a07b97
commit 5b639e1f20
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 47 additions and 16 deletions

View File

@ -188,34 +188,47 @@
"Mainnet") "Mainnet")
"\n")) "\n"))
(defn token-balances-text [token-balances]
(when-not (empty? token-balances)
(str "Tokens: "
(str/join "\n\t" (map (fn [[tla balance]] (format "%s: %.2f"
(subs (str tla) 1)
(float balance)))
token-balances))
"\n")))
(defn generate-open-comment (defn generate-open-comment
[owner repo issue-number contract-address balance balance-str] [owner repo issue-number contract-address eth-balance balance-str tokens]
(let [image-url (md-image "QR Code" (get-qr-url owner repo issue-number balance)) (let [image-url (md-image "QR Code" (get-qr-url owner repo issue-number eth-balance))
site-url (md-url (server-address) (server-address))] site-url (md-url (server-address) (server-address))]
(format (str "Current balance: %s ETH\n" (format (str "Current balance: %s ETH\n"
(token-balances-text tokens)
"Contract address: %s\n" "Contract address: %s\n"
"%s\n" "%s\n"
(network-text) (network-text)
"To claim this bounty sign up at %s") "To claim this bounty sign up at %s\n"
balance contract-address image-url site-url))) "To fund it, send ETH or ERC20 tokens to the contract address.")
eth-balance contract-address image-url site-url)))
(defn generate-merged-comment (defn generate-merged-comment
[contract-address balance-str winner-login] [contract-address eth-balance-str tokens winner-login]
(format (str "Balance: %s ETH\n" (format (str "Balance: %s ETH\n"
(token-balances-text tokens)
"Contract address: %s\n" "Contract address: %s\n"
(network-text) (network-text)
"Status: pending maintainer confirmation\n" "Status: pending maintainer confirmation\n"
"Winner: %s\n") "Winner: %s\n")
balance-str contract-address winner-login)) eth-balance-str contract-address winner-login))
(defn generate-paid-comment (defn generate-paid-comment
[contract-address balance-str payee-login] [contract-address eth-balance-str tokens payee-login]
(format (str "Balance: %s ETH\n" (format (str "Balance: %s ETH\n"
(token-balances-text tokens)
"Contract address: %s\n" "Contract address: %s\n"
(network-text) (network-text)
"Paid to: %s\n") "Paid to: %s\n")
balance-str contract-address payee-login)) eth-balance-str contract-address payee-login))
(defn post-deploying-comment (defn post-deploying-comment
@ -244,8 +257,14 @@
(defn update-comment (defn update-comment
"Update comment for an open bounty issue" "Update comment for an open bounty issue"
[owner repo comment-id issue-number contract-address balance balance-str] [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 balance balance-str)] (let [comment (generate-open-comment owner
repo
issue-number
contract-address
eth-balance
eth-balance-str
tokens)]
(log/debug (str "Updating " owner "/" repo "/" issue-number (log/debug (str "Updating " owner "/" repo "/" issue-number
" comment #" comment-id " with contents: " comment)) " comment #" comment-id " with contents: " comment))
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s" (let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
@ -256,8 +275,11 @@
(defn update-merged-issue-comment (defn update-merged-issue-comment
"Update comment for a bounty issue with winning claim (waiting to be "Update comment for a bounty issue with winning claim (waiting to be
signed off by maintainer)" signed off by maintainer)"
[owner repo comment-id contract-address balance-str winner-login] [owner repo comment-id contract-address eth-balance-str tokens winner-login]
(let [comment (generate-merged-comment contract-address balance-str winner-login)] (let [comment (generate-merged-comment contract-address
eth-balance-str
tokens
winner-login)]
(log/debug (str "Updating merged bounty issue (" owner "/" repo ")" (log/debug (str "Updating merged bounty issue (" owner "/" repo ")"
" comment#" comment-id " with contents: " comment)) " comment#" comment-id " with contents: " comment))
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s" (let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
@ -267,8 +289,11 @@
(defn update-paid-issue-comment (defn update-paid-issue-comment
"Update comment for a paid out bounty issue" "Update comment for a paid out bounty issue"
[owner repo comment-id contract-address balance-str payee-login] [owner repo comment-id contract-address eth-balance-str tokens payee-login]
(let [comment (generate-paid-comment contract-address balance-str payee-login)] (let [comment (generate-paid-comment contract-address
eth-balance-str
tokens
payee-login)]
(log/debug (str "Updating paid bounty (" owner "/" repo ")" (log/debug (str "Updating paid bounty (" owner "/" repo ")"
" comment#" comment-id " with contents: " comment)) " comment#" comment-id " with contents: " comment))
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s" (let [req (make-patch-request "repos/%s/%s/issues/comments/%s"

View File

@ -44,7 +44,8 @@
issue-number issue-number
contract-address contract-address
balance balance
balance-str)))))) balance-str
{}))))))
(defn deploy-contract [owner-address issue-id] (defn deploy-contract [owner-address issue-id]
@ -86,6 +87,7 @@
comment-id :comment_id comment-id :comment_id
issue-number :issue_number issue-number :issue_number
balance :balance balance :balance
tokens :tokens
winner-login :winner_login} (db-bounties/pending-bounties) winner-login :winner_login} (db-bounties/pending-bounties)
:let [value (eth/get-balance-hex contract-address)]] :let [value (eth/get-balance-hex contract-address)]]
(if (empty? payout-address) (if (empty? payout-address)
@ -97,6 +99,7 @@
comment-id comment-id
contract-address contract-address
(decimal->str balance) (decimal->str balance)
tokens
winner-login))))) winner-login)))))
(defn update-confirm-hash (defn update-confirm-hash
@ -121,6 +124,7 @@
comment-id :comment_id comment-id :comment_id
issue-number :issue_number issue-number :issue_number
balance :balance balance :balance
tokens :tokens
payee-login :payee_login} (db-bounties/confirmed-payouts)] payee-login :payee_login} (db-bounties/confirmed-payouts)]
(log/debug "confirmed payout:" payout-hash) (log/debug "confirmed payout:" payout-hash)
(when-let [receipt (eth/get-transaction-receipt payout-hash)] (when-let [receipt (eth/get-transaction-receipt payout-hash)]
@ -131,6 +135,7 @@
comment-id comment-id
contract-address contract-address
(decimal->str balance) (decimal->str balance)
tokens
payee-login)))) payee-login))))
@ -229,7 +234,8 @@
issue-number issue-number
contract-address contract-address
balance-eth balance-eth
balance-eth-str)))))) balance-eth-str
token-balances))))))
(defn run-1-min-interval-tasks [time] (defn run-1-min-interval-tasks [time]