More fixes for db field renaming

This commit is contained in:
Vitaliy Vlasov 2018-05-24 00:36:46 +03:00
parent 3d9fb55621
commit 8672376a98
No known key found for this signature in database
GPG Key ID: A7D57C347F2B2964
11 changed files with 72 additions and 49 deletions

View File

@ -447,6 +447,7 @@ SELECT
i.payout_receipt AS payout_receipt,
i.commit_sha AS commit_sha,
u.address AS owner_address,
u.login AS owner_login,
i.contract_address AS contract_address,
i.confirm_hash AS confirm_hash,
i.title AS title,

View File

@ -22,12 +22,17 @@
(let [labels (:labels issue)]
(some #(= label-name (:name %)) labels)))
(def last-states (atom {}))
(defn transition [{:keys [issue-id tx-info] :as bounty} state]
(let [bounty-not= (fn [current db]
(some #(not= (%1 current) (%1 db))
(disj (set (keys current)) :tx-info)))
bounty-from-db (issues/get-issue-by-id issue-id)
bounty (and (bounty-not= bounty bounty-from-db)
bounty (and (or
(and (= state :pending-contributor-address)
(not= state (get @last-states issue-id)))
(bounty-not= bounty bounty-from-db))
(merge bounty-from-db bounty))]
(when bounty
(case state
@ -64,9 +69,10 @@
(:balance-eth bounty)
(:tokens bounty)
(:value-usd bounty)))
nil)
(github/update-comment bounty state)))
(swap! last-states assoc issue-id state))
)
(github/update-comment bounty state))))
(defn deploy-contract [owner-address issue-id]
(if (empty? owner-address)
(log/errorf "issue %s: Unable to deploy bounty contract because repo owner has no Ethereum addres" issue-id)
@ -82,6 +88,20 @@
(log/errorf "issue %s Failed to deploy contract to %s" issue-id owner-address))
(catch Exception ex (log/errorf ex "issue %s: deploy-contract exception" issue-id)))))
(defn execute-payout [issue-id contract-address payout-address]
(if (empty? payout-address)
(do
(log/warn "issue %s: Cannot sign pending bounty - winner has no payout address" issue-id)
(transition {:issue-id issue-id} :pending-contributor-address))
(let [tx-info (multisig/send-all {:contract contract-address
:payout-address payout-address
:internal-tx-id [:execute issue-id]})]
(log/infof "issue %s: Payout self-signed, called sign-all(%s) tx: %s" issue-id contract-address payout-address (:tx-hash tx-info))
(transition {:execute-hash (:tx-hash tx-info)
:issue-id issue-id
:tx-info tx-info} :pending-sob-confirmation)
tx-info)))
(defn add-bounty-for-issue [repo repo-id issue]
(let [{issue-id :id
issue-number :number

View File

@ -68,17 +68,17 @@
(db/reset-payout-hash con-db {:issue_id issue-id})))
(def payout-receipt-keys
[:issue_id
:payout_hash
:contract_address
[:issue-id
:payout-hash
:contract-address
:repo
:owner
:comment_id
:issue_number
:balance_eth
:comment-id
:issue-number
:balance-eth
:tokens
:confirm_hash
:payee_login
:confirm-hash
:payee-login
:updated])
(defn update-payout-receipt

View File

@ -333,7 +333,8 @@
[{:keys [issue-id owner repo comment-id issue-number contract-address
balance-eth tokens
payout-receipt
winner-login winner-address transaction-hash] :as issue}
owner-login
winner-login transaction-hash] :as issue}
state]
(let [comment (case state
:deploying
@ -345,17 +346,23 @@
contract-address
balance-eth
tokens)
(:pending-maintainer-confirmation :pending-contributor-address)
:pending-sob-confirmation
(generate-merged-comment contract-address
balance-eth
tokens
winner-login
(str/blank? winner-address))
(or winner-login owner-login)
false)
:pending-contributor-address
(generate-merged-comment contract-address
balance-eth
tokens
(or winner-login owner-login)
true)
:paid
(generate-paid-comment contract-address
balance-eth
tokens
winner-login)
(or winner-login owner-login))
nil)]
(log/info (str "Updating " owner "/" repo "/" issue-number
" comment #" comment-id " with contents: " comment))

View File

@ -27,10 +27,10 @@
[token]
(let [user (github/get-user token)
{email :email
user-id :id} user]
(log/debug "get-or-create-user" user)
(or
(users/get-user user-id)
user-id :id} user
db-user (users/get-user user-id)]
(if (:id db-user)
db-user
(create-user token user))))
(defroutes redirect-routes

View File

@ -19,7 +19,8 @@
[clojure.tools.logging :as log]
[commiteth.config :refer [env]]
[commiteth.util.util :refer [usd-decimal->str
eth-decimal->str]]
eth-decimal->str
to-db-map]]
[crypto.random :as random]
[clojure.set :refer [rename-keys]]
[clojure.string :as str]
@ -148,11 +149,8 @@
(defn execute-revocation [issue-id contract-address payout-address]
(log/info (str "executing revocation for " issue-id "at" contract-address))
(try
(let [tx-info (multisig/send-all {:contract contract-address
:payout-address payout-address
:internal-tx-id [:execute issue-id]})]
(tracker/track-tx! tx-info)
{:execute-hash (:tx-hash tx-info)})
(let [tx-info (bounties/execute-payout issue-id contract-address payout-address)]
(:tx-hash tx-info))
(catch Throwable ex
(log/errorf ex "error revoking funds for %s" issue-id))))
@ -197,11 +195,11 @@
:auth-rules authenticated?
:current-user user
:body [body {:address s/Str
:is_hidden_in_hunters s/Bool}]
:is-hidden-in-hunters s/Bool}]
:summary "Updates user's fields."
(let [user-id (:id user)
{:keys [address]} body]
{:keys [address is-hidden-in-hunters]} body]
(when-not (eth/valid-address? address)
(log/debugf "POST /user: Wrong address %s" address)
@ -210,7 +208,8 @@
(db/with-tx
(when-not (db/user-exists? {:id user-id})
(not-found! "No such a user."))
(db/update! :users body ["id = ?" user-id]))
(db/update! :users (to-db-map address is-hidden-in-hunters)
["id = ?" user-id]))
(ok)))
@ -248,7 +247,7 @@
:current-user user
(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)]
(if-let [execute-hash (execute-revocation issue-id contract-address owner-address)]
(ok {:issue-id issue-id
:execute-hash execute-hash
:contract-address contract-address})

View File

@ -79,24 +79,14 @@
[]
(log/info "In self-sign-bounty")
(p :self-sign-bounty
(doseq [{:keys [contract-address winner-address issue-id winner-login] :as issue}
(doseq [{:keys [contract-address winner-address issue-id] :as issue}
(db-bounties/pending-bounties)]
(try
;; TODO(martin) delete this shortly after org-dashboard deploy
;; as we're now setting `winner_login` when handling a new claims
;; coming in via webhooks (see `commiteth.routes.webhooks/handle-claim`)
;(db-bounties/update-winner-login issue-id winner-login)
(if (empty? winner-address)
(do
(log/warn "issue %s: Cannot sign pending bounty - winner has no payout address" issue-id)
(bounties/transition {:issue-id issue-id} :pending-contributor-address))
(let [tx-info (multisig/send-all {:contract contract-address
:payout-address winner-address
:internal-tx-id [:execute issue-id]})]
(log/infof "issue %s: Payout self-signed, called sign-all(%s) tx: %s" issue-id contract-address winner-address (:tx-hash tx-info))
(bounties/transition {:execute-hash (:tx-hash tx-info)
:issue-id issue-id
:tx-info tx-info} :pending-sob-confirmation)))
(bounties/execute-payout issue-id contract-address winner-address)
(catch Throwable ex
(log/error ex "issue %s: self-sign-bounty exception" issue-id)))))
(log/info "Exit self-sign-bounty"))
@ -164,7 +154,8 @@
(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}]
[{:keys [payout-hash contract-address confirm-hash issue-id updated] :as bounty}]
{:pre [(util/contains-all-keys bounty db-bounties/payout-receipt-keys)]}
(log/info "In update-payout-receipt")
(p :update-payout-receipt
(try
@ -183,7 +174,7 @@
(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))))
(bounties/transition (assoc bounty :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)))

View File

@ -21,3 +21,8 @@
(defmacro to-db-map [& vars]
(into {} (map #(vector (keyword (str/replace (name %1) "-" "_")) %1) vars)))
(defn contains-all-keys [m ks]
{:pre [(map? m) [(vector? ks)]]}
(every?
#(contains? m %) ks))

View File

@ -42,7 +42,7 @@
updated-bounties (get-in context [:effects :db :owner-bounties])
confirming-issue-id (get-confirming-issue-id :commiteth pending-revocations)]
(when-let [revoking-bounty (get updated-bounties confirming-issue-id)]
(if (:confirm_hash revoking-bounty)
(if (:confirm-hash revoking-bounty)
(do (dispatch-confirm-payout revoking-bounty)
(dispatch-set-pending-revocation revoking-bounty))
(println (str "currently revoking " confirming-issue-id " but confirm hash has not been set yet."))))
@ -69,7 +69,7 @@
updated-bounties (get-in context [:effects :db :owner-bounties])
confirming-issue-id (get-confirming-issue-id :owner pending-revocations)]
(when-let [revoking-bounty (get updated-bounties confirming-issue-id)]
(if (:payout_receipt revoking-bounty)
(if (:payout-receipt revoking-bounty)
(dispatch-remove-pending-revocation revoking-bounty)
(println (str "currently revoking " confirming-issue-id " but payout receipt has not been set yet."))))
;; interceptor must return context

View File

@ -10,7 +10,7 @@
(let [db (rf/subscribe [:db])
updating-user (rf/subscribe [:get-in [:updating-user]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))
hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden_in_hunters]]))]
hidden (r/atom @(rf/subscribe [:get-in [:user :is-hidden-in-hunters]]))]
(fn []
(let [web3 (:web3 @db)
@ -64,7 +64,7 @@
[:button
(merge {:on-click
#(rf/dispatch [:save-user-fields {:address @address
:is_hidden_in_hunters @hidden}])
:is-hidden-in-hunters @hidden}])
:disabled (str/blank? @address)
:class (str "ui button small update-address-button"
(when @updating-user

View File

@ -36,5 +36,5 @@
:address "address"
:created nil
:welcome_email_sent 0
:is_hidden_in_hunters false}
:is-hidden-in-hunters false}
(db/get-user t-conn {:id 1})))))