Fix payouts

This commit is contained in:
Vitaliy Vlasov 2018-05-22 22:06:34 +03:00
parent 8b44cac1f4
commit 3d9fb55621
No known key found for this signature in database
GPG Key ID: A7D57C347F2B2964
6 changed files with 62 additions and 66 deletions

View File

@ -67,14 +67,14 @@
(def bounty-renames
;; TODO this needs to go away ASAP we need to be super consistent
;; about keys unless we will just step on each others toes constantly
{:user_name :display-name
:user_avatar_url :avatar-url
{:user-name :display-name
:user-avatar-url :avatar-url
:type :item-type})
(defn ^:private enrich-owner-bounties [owner-bounty]
(let [claims (map
#(update % :value_usd usd-decimal->str)
(bounties-db/bounty-claims (:issue_id owner-bounty)))
#(update % :value-usd usd-decimal->str)
(bounties-db/bounty-claims (:issue-id owner-bounty)))
with-claims (assoc owner-bounty :claims claims)]
(-> with-claims
(rename-keys bounty-renames)
@ -246,7 +246,7 @@
(POST "/revoke" {{issue-id :issue-id} :params}
:auth-rules authenticated?
:current-user user
(let [{contract-address :contract_address owner-address :owner_address} (issues/get-issue-by-id issue-id)]
(let [{:keys [contract-address owner-address]} (issues/get-issue-by-id issue-id)]
(do (log/infof "calling revoke-initiate for %s with %s %s" issue-id contract-address owner-address)
(if-let [{:keys [execute-hash]} (execute-revocation issue-id contract-address owner-address)]
(ok {:issue-id issue-id

View File

@ -164,33 +164,31 @@
(defn update-payout-receipt
"Gets transaction receipt for each confirmed payout and updates payout_hash"
[]
[{:keys [payout-hash contract-address confirm-hash issue-id updated] :as issue}]
(log/info "In update-payout-receipt")
(p :update-payout-receipt
(doseq [{:keys [payout-hash contract-address confirm-hash issue-id updated] :as issue}
(db-bounties/confirmed-payouts)]
(log/infof "issue %s: confirmed payout: %s" issue-id payout-hash)
(try
(if-let [receipt (eth/get-transaction-receipt payout-hash)]
(let [contract-tokens (multisig/token-balances contract-address)
contract-eth-balance (eth/get-balance-wei contract-address)]
(if (or
(some #(> (second %) 0.0) contract-tokens)
(> contract-eth-balance 0))
(do
(log/infof "issue %s: Contract (%s) still has funds" issue-id contract-address)
(when (multisig/is-confirmed? contract-address confirm-hash)
(log/infof "issue %s: Detected bounty with funds and confirmed payout, calling executeTransaction" issue-id)
(let [execute-tx-hash (multisig/execute-tx contract-address confirm-hash)]
(log/infof "issue %s: execute tx: %s" issue-id execute-tx-hash))))
(do
(log/infof "issue %s: Payout has succeeded, payout receipt %s" issue-id receipt)
(bounties/transition (assoc issue :payout-receipt receipt) :paid))))
(when (older-than-3h? updated)
(log/warn "issue %s: Resetting payout hash for issue as it has not been mined in 3h" issue-id)
(db-bounties/reset-payout-hash issue-id)))
(catch Throwable ex
(log/error ex "issue %s: update-payout-receipt exception" issue-id))))))
(try
(log/infof "issue %s: confirmed payout: %s" issue-id payout-hash)
(if-let [receipt (eth/get-transaction-receipt payout-hash)]
(let [contract-tokens (multisig/token-balances contract-address)
contract-eth-balance (eth/get-balance-wei contract-address)]
(if (or
(some #(> (second %) 0.0) contract-tokens)
(> contract-eth-balance 0))
(do
(log/infof "issue %s: Contract (%s) still has funds" issue-id contract-address)
(when (multisig/is-confirmed? contract-address confirm-hash)
(log/infof "issue %s: Detected bounty with funds and confirmed payout, calling executeTransaction" issue-id)
(let [execute-tx-hash (multisig/execute-tx contract-address confirm-hash)]
(log/infof "issue %s: execute tx: %s" issue-id execute-tx-hash))))
(do
(log/infof "issue %s: Payout has succeeded, payout receipt %s" issue-id receipt)
(bounties/transition (assoc issue :payout-receipt receipt) :paid))))
(when (older-than-3h? updated)
(log/warn "issue %s: Resetting payout hash for issue as it has not been mined in 3h" issue-id)
(db-bounties/reset-payout-hash issue-id)))
(catch Throwable ex
(log/error ex "issue %s: update-payout-receipt exception" issue-id)))))
(defn update-payout-receipts
"Gets transaction receipt for each confirmed payout and updates payout_hash"

View File

@ -11,20 +11,20 @@
;; to communicate what datatypes are returned where.
(defn open? [claim]
(assert (find claim :pr_state))
(= 0 (:pr_state claim)))
(assert (find claim :pr-state))
(= 0 (:pr-state claim)))
(defn merged? [claim]
(assert (find claim :pr_state))
(= 1 (:pr_state claim)))
(assert (find claim :pr-state))
(= 1 (:pr-state claim)))
(defn paid? [claim]
(assert (find claim :payout_hash))
(not-empty (:payout_hash claim)))
(assert (find claim :payout-hash))
(not-empty (:payout-hash claim)))
(defn bot-confirm-unmined? [bounty]
(assert (find bounty :confirm_hash))
(empty? (:confirm_hash bounty)))
(assert (find bounty :confirm-hash))
(empty? (:confirm-hash bounty)))
(defn confirming? [bounty]
(:confirming? bounty))

View File

@ -484,10 +484,11 @@
(reg-event-fx
:confirm-payout
interceptors
(fn [{:keys [db]} [_ {issue-id :issue_id
owner-address :owner_address
contract-address :contract_address
confirm-hash :confirm_hash} issue]]
(fn [{:keys [db]} [_ {:keys [issue-id
owner-address
contract-address
confirm-hash]
:as issue}]]
(println (:web3 db))
(let [w3 (:web3 db)
pending-revocations (::db/pending-revocations db)

View File

@ -12,10 +12,7 @@
(defn dispatch-confirm-payout [bounty]
"dispatches a bounty via reframe dispatch"
(rf/dispatch [:confirm-payout {:issue_id (:issue-id bounty)
:owner_address (:owner_address bounty)
:contract_address (:contract_address bounty)
:confirm_hash (:confirm_hash bounty)}]))
(rf/dispatch [:confirm-payout bounty]))
(defn dispatch-set-pending-revocation [bounty]
"update the currently confirming account to owner"

View File

@ -9,9 +9,9 @@
[commiteth.config :as config]
[commiteth.common :as common :refer [human-time]]))
(defn pr-url [{owner :repo_owner
pr-number :pr_number
repo :repo_name}]
(defn pr-url [{owner :repo-owner
pr-number :pr-number
repo :repo-name}]
(str "https://github.com/" owner "/" repo "/pull/" pr-number))
(defn etherscan-tx-url [tx-id]
@ -57,7 +57,7 @@
(when (and merged? (not paid?))
[primary-button-button
(merge {:on-click #(rf/dispatch [:confirm-payout claim])}
(if (and merged? (not paid?) (:payout_address bounty))
(if (and merged? (not paid?) (:payout-address bounty))
{}
{:disabled true})
(when (and (or (bnt/confirming? bounty)
@ -71,11 +71,11 @@
(defn confirm-row [bounty claim]
(let [payout-address-available? (:payout_address bounty)]
(let [payout-address-available? (:payout-address bounty)]
[:div
(when-not payout-address-available?
[:div.bg-sob-blue-o-20.pv2.ph3.br3.mb3.f6
[:p [:span.pg-med (or (:user_name claim) (:user_login claim))
[:p [:span.pg-med (or (:user-name claim) (:user-login claim))
"s payment address is pending."] " You will be able to confirm the payment once the address is provided."]])
[:div.cf
[:div.dt.fr
@ -97,10 +97,10 @@
"View Pull Request"])
(defn claim-card [bounty claim {:keys [render-view-claim-button?] :as opts}]
(let [{user-name :user_name
user-login :user_login
avatar-url :user_avatar_url} claim
winner-login (:winner_login bounty)]
(let [{user-name :user-name
user-login :user-login
avatar-url :user-avatar-url} claim
winner-login (:winner-login bounty)]
[:div.pv2
[:div.flex
{:class (when (and (bnt/paid? claim) (not (= user-login winner-login)))
@ -118,7 +118,7 @@
[:span "No payout"]))]
[:div.f6.gray "Submitted a claim via "
[:a.gray {:href (pr-url claim)}
(str (:repo_owner claim) "/" (:repo_name claim) " PR #" (:pr_number claim))]]
(str (:repo-owner claim) "/" (:repo-name claim) " PR #" (:pr-number claim))]]
;; We render the button twice for difference screen sizes, first button is for small screens:
;; 1) db + dn-ns: `display: block` + `display: none` for not-small screens
;; 2) dn + db-ns: `display: none` + `display: block` for not-small screens
@ -139,7 +139,7 @@
;; FIXME we remove all bounties that Andy 'won' as this basically
;; has been our method for revocations. This needs to be cleaned up ASAP.
;; https://github.com/status-im/open-bounty/issues/284
(for [bounty (filter #(not= "andytudhope" (:winner_login %)) bounties)
(for [bounty (filter #(not= "andytudhope" (:winner-login %)) bounties)
;; Identifying the winning claim like this is a bit
;; imprecise if there have been two PRs for the same
;; bounty by the same contributor
@ -147,8 +147,8 @@
;; ignore this edge case for a first version
:let [winning-claim (->> (:claims bounty)
(filter #(and (bnt/merged? %)
(= (:user_login %)
(:winner_login bounty))))
(= (:user-login %)
(:winner-login bounty))))
util/assert-first)]]
^{:key (:issue-id bounty)}
[:div.mb3.br3.shadow-6.bg-white
@ -176,7 +176,7 @@
(str "Current Claims (" (count claims) ")")
"Current Claim")]
(for [[idx claim] (zipmap (range) claims)]
^{:key (:pr_id claim)}
^{:key (:pr-id claim)}
[:div
{:class (when (> idx 0) "bt b--light-gray pt2")}
[claim-card bounty claim {:render-view-claim-button? true}]])]]))))
@ -275,7 +275,7 @@
(let [bounty @(rf/subscribe [:revoke-modal-bounty])]
(fn []
(when bounty
(let [owner-address (:owner_address bounty)]
(let [owner-address (:owner-address bounty)]
;; width requires a deliberate override of semantic.min.css
[:div.ui.active.modal.br3 {:style {:top 100
:width 650}}
@ -325,7 +325,7 @@
[:div
[bounty-title-link bounty {:show-date? false :max-length 60}]
[:div.f6.mt1.gray
"Paid out to " [:span.pg-med.fw5 "@" (or (:winner_login bounty)
"Paid out to " [:span.pg-med.fw5 "@" (or (:winner-login bounty)
;; use repo owner for revoked bounties
;; where no winner login is set
(:owner-login bounty))]]]
@ -358,17 +358,17 @@
(when @banner-info
(into [:div]
(for [revoking-bounty @banner-info]
^{:key (:contract_address revoking-bounty)}
^{:key (:contract-address revoking-bounty)}
[:div.relative.pa3.pr4.bg-sob-green.br3.nt1
[:div
(case (:confirming-account revoking-bounty)
:commiteth [:p.v-mid [check-box "ic-check-circle-black-24dp-2x.png"]
[:span.pg-med "Transaction sent."] " Your refund requires two confirmations. After the first one "
[:a.sob-blue.pg-med {:href (etherscan-address-url (:contract_address revoking-bounty)) :target "_blank"} " completes "]
[:a.sob-blue.pg-med {:href (etherscan-address-url (:contract-address revoking-bounty)) :target "_blank"} " completes "]
"you'll be prompted to sign the second via metamask."]
:owner [:p.v-mid [check-box "ic-check-circle-black-24dp-2x.png"]
[:span.pg-med "Transaction sent."] " Once your metamask transaction is confirmed your revocation will be complete. Follow the final step "
[:a.sob-blue.pg-med {:href (etherscan-address-url (:contract_address revoking-bounty)) :target "_blank"} " here. "]])]]))))))
[:a.sob-blue.pg-med {:href (etherscan-address-url (:contract-address revoking-bounty)) :target "_blank"} " here. "]])]]))))))
(defn salute []
(let [msg-info (rf/subscribe [:dashboard/banner-msg])]