Merge branch 'develop' into develop
This commit is contained in:
commit
55cba00fa0
|
@ -164,11 +164,29 @@ WHERE issue_id = :issue_id;
|
|||
-- :name list-pending-deployments :? :*
|
||||
-- :doc retrieves pending transaction ids
|
||||
SELECT
|
||||
issue_id,
|
||||
transaction_hash
|
||||
FROM issues
|
||||
WHERE contract_address IS NULL
|
||||
AND issues.transaction_hash IS NOT NULL;
|
||||
i.issue_id as issue_id,
|
||||
i.transaction_hash as transaction_hash,
|
||||
u.address as owner_address
|
||||
FROM issues i, users u, repositories r
|
||||
WHERE r.user_id = u.id
|
||||
AND i.repo_id = r.repo_id
|
||||
AND i.contract_address IS NULL
|
||||
AND i.transaction_hash IS NOT NULL;
|
||||
|
||||
|
||||
-- :name list-failed-deployments :? :*
|
||||
-- :doc retrieves failed contract deployments
|
||||
SELECT
|
||||
i.issue_id as issue_id,
|
||||
i.transaction_hash as transaction_hash,
|
||||
u.address as owner_address
|
||||
FROM issues i, users u, repositories r
|
||||
WHERE r.user_id = u.id
|
||||
AND i.repo_id = r.repo_id
|
||||
AND i.contract_address IS NULL
|
||||
AND i.transaction_hash IS NOT NULL
|
||||
AND i.updated < now() at time zone 'UTC' - interval '1 hour';
|
||||
|
||||
|
||||
-- Pull Requests -------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -46,6 +46,12 @@
|
|||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/list-pending-deployments con-db)))
|
||||
|
||||
|
||||
(defn list-failed-deployments
|
||||
[]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
(db/list-failed-deployments con-db)))
|
||||
|
||||
(defn get-balance
|
||||
[contract-address]
|
||||
(jdbc/with-db-connection [con-db *db*]
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
[clojure.string :as str]
|
||||
[pandect.core :as pandect]))
|
||||
|
||||
(def eth-rpc-url "http://localhost:8545")
|
||||
(defn eth-rpc-url [] (env :eth-rpc-url "http://localhost:8545"))
|
||||
(defn eth-account [] (:eth-account env))
|
||||
(defn eth-password [] (:eth-password env))
|
||||
(defn gas-price [] (:gas-price env))
|
||||
|
||||
(defn eth-rpc
|
||||
[method params]
|
||||
|
@ -21,7 +22,7 @@
|
|||
:id request-id})
|
||||
options {:headers {"content-type" "application/json"}
|
||||
:body body}
|
||||
response (:body @(post eth-rpc-url options))
|
||||
response (:body @(post (eth-rpc-url) options))
|
||||
result (json/read-str response :key-fn keyword)]
|
||||
(log/debug body "\n" result)
|
||||
(if (= (:id result) request-id)
|
||||
|
@ -65,11 +66,12 @@
|
|||
(defn send-transaction
|
||||
[from to value & [params]]
|
||||
(let [gas (estimate-gas from to value params)
|
||||
gasPrice (format "0x%x" 10000000000)
|
||||
args (merge params {:from from
|
||||
args (merge params
|
||||
{:from from
|
||||
:value value
|
||||
:gas gas
|
||||
:gasPrice gasPrice})]
|
||||
:gas gas}
|
||||
(when-not (nil? (gas-price))
|
||||
{:gasPrice gas-price}))]
|
||||
(eth-rpc
|
||||
"personal_sendTransaction"
|
||||
[(if-not (nil? to)
|
||||
|
|
|
@ -45,18 +45,33 @@
|
|||
balance-str))))))
|
||||
|
||||
|
||||
(defn deploy-contract [owner-address issue-id]
|
||||
(let [transaction-hash (eth/deploy-contract owner-address)]
|
||||
(if (nil? transaction-hash)
|
||||
(log/error "Failed to deploy contract to" owner-address)
|
||||
(log/info "Contract deployed, transaction-hash:"
|
||||
transaction-hash ))
|
||||
(issues/update-transaction-hash issue-id transaction-hash)))
|
||||
|
||||
|
||||
(defn redeploy-failed-contracts
|
||||
"If the bot account runs out of gas, we end up with transaction-id in db, but with nothing written to blockchain. In this case we should try to re-deploy the contract."
|
||||
[]
|
||||
(doseq [{issue-id :issue_id
|
||||
transaction-hash :transaction_hash
|
||||
owner-address :owner_address} (issues/list-failed-deployments)]
|
||||
(when (nil? (eth/get-transaction-receipt transaction-hash))
|
||||
(log/info "Detected nil transaction receipt for pending contract deployment for issue" issue-id ", re-deploying contract")
|
||||
(deploy-contract owner-address issue-id))))
|
||||
|
||||
|
||||
(defn deploy-pending-contracts
|
||||
"Under high-concurrency circumstances or in case geth is in defunct state, a bounty contract may not deploy successfully when the bounty label is addded to an issue. This function deploys such contracts."
|
||||
[]
|
||||
(doseq [{issue-id :issue_id
|
||||
owner-address :owner_address} (db-bounties/pending-contracts)]
|
||||
(log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id)
|
||||
(let [transaction-hash (eth/deploy-contract owner-address)]
|
||||
(if (nil? transaction-hash)
|
||||
(log/error "Failed to deploy contract to" owner-address)
|
||||
(log/info "Contract deployed, transaction-hash:"
|
||||
transaction-hash ))
|
||||
(issues/update-transaction-hash issue-id transaction-hash))))
|
||||
(deploy-contract owner-address issue-id)))
|
||||
|
||||
(defn self-sign-bounty
|
||||
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
|
||||
|
@ -169,6 +184,9 @@
|
|||
(defn run-periodic-tasks [time]
|
||||
(do
|
||||
(log/debug "run-periodic-tasks" time)
|
||||
;; TODO: disabled for now. looks like it may cause extraneus
|
||||
;; contract deployments and costs
|
||||
#_(redeploy-failed-contracts)
|
||||
(deploy-pending-contracts)
|
||||
(update-issue-contract-address)
|
||||
(update-confirm-hash)
|
||||
|
|
Loading…
Reference in New Issue