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 :? :*
|
-- :name list-pending-deployments :? :*
|
||||||
-- :doc retrieves pending transaction ids
|
-- :doc retrieves pending transaction ids
|
||||||
SELECT
|
SELECT
|
||||||
issue_id,
|
i.issue_id as issue_id,
|
||||||
transaction_hash
|
i.transaction_hash as transaction_hash,
|
||||||
FROM issues
|
u.address as owner_address
|
||||||
WHERE contract_address IS NULL
|
FROM issues i, users u, repositories r
|
||||||
AND issues.transaction_hash IS NOT NULL;
|
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 -------------------------------------------------------------------
|
-- Pull Requests -------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,12 @@
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/list-pending-deployments con-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
|
(defn get-balance
|
||||||
[contract-address]
|
[contract-address]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[pandect.core :as pandect]))
|
[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-account [] (:eth-account env))
|
||||||
(defn eth-password [] (:eth-password env))
|
(defn eth-password [] (:eth-password env))
|
||||||
|
(defn gas-price [] (:gas-price env))
|
||||||
|
|
||||||
(defn eth-rpc
|
(defn eth-rpc
|
||||||
[method params]
|
[method params]
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
:id request-id})
|
:id request-id})
|
||||||
options {:headers {"content-type" "application/json"}
|
options {:headers {"content-type" "application/json"}
|
||||||
:body body}
|
:body body}
|
||||||
response (:body @(post eth-rpc-url options))
|
response (:body @(post (eth-rpc-url) options))
|
||||||
result (json/read-str response :key-fn keyword)]
|
result (json/read-str response :key-fn keyword)]
|
||||||
(log/debug body "\n" result)
|
(log/debug body "\n" result)
|
||||||
(if (= (:id result) request-id)
|
(if (= (:id result) request-id)
|
||||||
|
@ -65,11 +66,12 @@
|
||||||
(defn send-transaction
|
(defn send-transaction
|
||||||
[from to value & [params]]
|
[from to value & [params]]
|
||||||
(let [gas (estimate-gas from to value params)
|
(let [gas (estimate-gas from to value params)
|
||||||
gasPrice (format "0x%x" 10000000000)
|
args (merge params
|
||||||
args (merge params {:from from
|
{:from from
|
||||||
:value value
|
:value value
|
||||||
:gas gas
|
:gas gas}
|
||||||
:gasPrice gasPrice})]
|
(when-not (nil? (gas-price))
|
||||||
|
{:gasPrice gas-price}))]
|
||||||
(eth-rpc
|
(eth-rpc
|
||||||
"personal_sendTransaction"
|
"personal_sendTransaction"
|
||||||
[(if-not (nil? to)
|
[(if-not (nil? to)
|
||||||
|
|
|
@ -45,18 +45,33 @@
|
||||||
balance-str))))))
|
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
|
(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."
|
"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
|
(doseq [{issue-id :issue_id
|
||||||
owner-address :owner_address} (db-bounties/pending-contracts)]
|
owner-address :owner_address} (db-bounties/pending-contracts)]
|
||||||
(log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id)
|
(log/debug "Trying to re-deploy failed bounty contract deployment, issue-id:" issue-id)
|
||||||
(let [transaction-hash (eth/deploy-contract owner-address)]
|
(deploy-contract owner-address issue-id)))
|
||||||
(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 self-sign-bounty
|
(defn self-sign-bounty
|
||||||
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
|
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
|
||||||
|
@ -169,6 +184,9 @@
|
||||||
(defn run-periodic-tasks [time]
|
(defn run-periodic-tasks [time]
|
||||||
(do
|
(do
|
||||||
(log/debug "run-periodic-tasks" time)
|
(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)
|
(deploy-pending-contracts)
|
||||||
(update-issue-contract-address)
|
(update-issue-contract-address)
|
||||||
(update-confirm-hash)
|
(update-confirm-hash)
|
||||||
|
|
Loading…
Reference in New Issue