Various bugfixes:

* extra newline in contract data
* insufficient gas
* wrong headless image generation
* stop scheduler threads on exit
etc.
This commit is contained in:
kagel 2016-09-18 23:43:38 +03:00
parent c0e4f51069
commit bce7ef436a
6 changed files with 45 additions and 34 deletions

View File

@ -141,7 +141,8 @@ SELECT
issue_id,
transaction_hash
FROM issues
WHERE contract_address IS NULL;
WHERE contract_address IS NULL
AND issues.transaction_hash IS NOT NULL;
-- Pull Requests -------------------------------------------------------------------

View File

@ -24,6 +24,12 @@
(log/error "Method: " method ", error: " error))
(:result result)))
(defn estimate-gas
[from to value & [params]]
(eth-rpc "eth_estimateGas" [(merge params {:from from
:to to
:value value})]))
(defn hex->big-integer
[hex]
(new BigInteger (subs hex 2) 16))
@ -50,10 +56,13 @@
(defn send-transaction
[from to value & [params]]
(eth-rpc "personal_signAndSendTransaction" [(merge params {:from from
:to to
:value value})
(eth-password)]))
;; todo: estimate gas instead of hardcoding
(let [gas 1248650]
(eth-rpc "personal_signAndSendTransaction" [(merge params {:from from
:to to
:value value
:gas gas})
(eth-password)])))
(defn get-transaction-receipt
[hash]
@ -62,9 +71,7 @@
(defn deploy-contract
[]
(let [contract-code (-> "contracts/wallet.data" io/resource slurp)]
(send-transaction (eth-account) nil 1
{:gas 1248650
:data contract-code})))
(send-transaction (eth-account) nil 1 {:data contract-code})))
(defn- format-param
[param]

View File

@ -120,13 +120,13 @@
(defn post-comment
[user repo issue-number balance]
(let [comment (generate-comment user repo issue-number balance)]
(log/debug "Posting comment to" (str user "/" repo) ":" comment)
(log/debug "Posting comment to" (str user "/" repo "/" issue-number) ":" comment)
(issues/create-comment user repo issue-number comment (self-auth-params))))
(defn update-comment
[user repo comment-id issue-number balance]
(let [comment (generate-comment user repo issue-number balance)]
(log/debug (str "Updating " user "/" repo " comment #" comment-id " with contents: " comment))
(log/debug (str "Updating " user "/" repo "/" issue-number " comment #" comment-id " with contents: " comment))
(issues/edit-comment user repo comment-id comment (self-auth-params))))
(defn get-issue

View File

@ -5,7 +5,7 @@
[commiteth.db.issues :as issues]
[commiteth.db.users :as users]
[commiteth.db.bounties :as bounties]
[overtone.at-at :refer [every mk-pool]]
[overtone.at-at :refer [every mk-pool stop-and-reset-pool!]]
[clojure.tools.logging :as log]
[mount.core :as mount]))
@ -15,8 +15,9 @@
"For each pending deployment:
gets transasction receipt, updates db state, posts github comment and adds owners to the wallet"
[]
(for [{issue-id :issue_id
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
(doseq [{issue-id :issue_id
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
(log/debug "pending deployment:" transaction-hash)
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
(log/info "transaction receipt for issue #" issue-id ": " receipt)
(when-let [contract-address (:contractAddress receipt)]
@ -35,31 +36,34 @@
(defn self-sign-bounty
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
[]
(for [{contract-address :contract_address
issue-id :issue_id
payout-address :payout_address} (bounties/pending-bounties-list)]
(let [value (eth/get-balance-hex contract-address)]
(->>
(wallet/execute contract-address payout-address value)
(bounties/update-confirm-hash issue-id)))))
(doseq [{contract-address :contract_address
issue-id :issue_id
payout-address :payout_address} (bounties/pending-bounties-list)
:let [value (eth/get-balance-hex contract-address)]]
(->>
(wallet/execute contract-address payout-address value)
(bounties/update-confirm-hash issue-id))))
(defn update-balance
[]
(for [{contract-address :contract_address
login :login
repo :repo
comment-id :comment_id
issue-number :issue_number} (bounties/list-wallets)]
(doseq [{contract-address :contract_address
login :login
repo :repo
comment-id :comment_id
issue-number :issue_number} (bounties/list-wallets)]
(when comment-id
(let [old-balance (issues/get-balance contract-address)
(let [{old-balance :balance} (issues/get-balance contract-address)
current-balance-hex (eth/get-balance-hex contract-address)
current-balance-eth (eth/hex->eth current-balance-hex 8)]
(when-not (= old-balance current-balance-hex)
(issues/update-balance contract-address current-balance-hex)
(github/update-comment login repo comment-id issue-number current-balance-eth))))))
(mount/defstate scheduler :start
(do
(every (* 5 60 1000) update-issue-contract-address pool)
(every (* 60 1000) self-sign-bounty pool)
(every (* 5 60 1000) update-balance pool)))
(mount/defstate scheduler
:start (do
(every (* 1 60 1000) update-issue-contract-address pool)
(every (* 1 60 1000) self-sign-bounty pool)
(every (* 1 60 1000) update-balance pool))
:stop (do
(log/info "Stopping scheduler pool")
(stop-and-reset-pool! pool)))

View File

@ -7,8 +7,7 @@
(defn ^BufferedImage create-image
[width height]
(.. GraphicsEnvironment getLocalGraphicsEnvironment getDefaultScreenDevice getDefaultConfiguration
(createCompatibleImage width height)))
(new BufferedImage width height BufferedImage/TYPE_INT_ARGB))
(defn html->image
[html width height]