From 498f80c24a868f335b716a97e9c390161e8b8318 Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Wed, 28 Feb 2018 12:02:13 +0100 Subject: [PATCH] assert that keys from enrichment process are present --- src/clj/commiteth/bounties.clj | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/clj/commiteth/bounties.clj b/src/clj/commiteth/bounties.clj index d804131..13661ae 100644 --- a/src/clj/commiteth/bounties.clj +++ b/src/clj/commiteth/bounties.clj @@ -106,6 +106,11 @@ (log/info "Updating changed title for issue" (:id gh-issue)) (issues/update-issue-title (:id gh-issue) (:title gh-issue))))))) +(defn assert-keys [m ks] + (doseq [k ks] + (when-not (find m k) + (throw (ex-info (format "Expected key missing from provided map: %s" k) {:map m}))))) + (defn bounty-state "Given a map as returned by `owner-bounties` return the state the provided bounty is in. @@ -117,6 +122,8 @@ - :pending-contributor-address - :pending-maintainer-confirmation" [bounty] + (assert-keys bounty [:winner_login :payout_address :confirm_hash :payout_hash + :claims :tokens :contract_address]) (if-let [merged? (:winner_login bounty)] (cond (nil? (:payout_address bounty)) :pending-contributor-address @@ -124,10 +131,10 @@ (:payout_hash bounty) :paid :else :merged) (cond ; not yet merged - (some-> (:claim_count bounty) (< 1)) :multiple-claims - (= 1 (:claim_count bounty)) :claimed - (seq (:tokens bounty)) :funded - (:contract_address bounty) :opened))) + (< 1 (count (:claims bounty))) :multiple-claims + (= 1 (count (:claims bounty))) :claimed + (seq (:tokens bounty)) :funded + (:contract_address bounty) :opened))) (comment (def user 97496)