mirror of
https://github.com/status-im/open-bounty.git
synced 2025-01-11 18:14:25 +00:00
Fix multisig wallet payout flow
This commit is contained in:
parent
1110f5817d
commit
401f8dcf8c
@ -9,3 +9,5 @@ ALTER TABLE public.issues
|
|||||||
ADD address VARCHAR(256);
|
ADD address VARCHAR(256);
|
||||||
ALTER TABLE public.issues
|
ALTER TABLE public.issues
|
||||||
DROP COLUMN comment_id;
|
DROP COLUMN comment_id;
|
||||||
|
ALTER TABLE public.issues
|
||||||
|
DROP COLUMN execute_hash;
|
||||||
|
@ -6,6 +6,8 @@ ALTER TABLE public.issues
|
|||||||
ADD confirm_hash VARCHAR(128) NULL;
|
ADD confirm_hash VARCHAR(128) NULL;
|
||||||
ALTER TABLE public.issues
|
ALTER TABLE public.issues
|
||||||
ADD comment_id INTEGER NULL;
|
ADD comment_id INTEGER NULL;
|
||||||
|
ALTER TABLE public.issues
|
||||||
|
ADD execute_hash VARCHAR(128) NULL;
|
||||||
-- noinspection SqlResolve
|
-- noinspection SqlResolve
|
||||||
ALTER TABLE public.issues
|
ALTER TABLE public.issues
|
||||||
DROP COLUMN address;
|
DROP COLUMN address;
|
||||||
|
@ -175,14 +175,35 @@ FROM issues i
|
|||||||
AND p.repo_id = i.repo_id
|
AND p.repo_id = i.repo_id
|
||||||
INNER JOIN users u
|
INNER JOIN users u
|
||||||
ON u.id = p.user_id
|
ON u.id = p.user_id
|
||||||
WHERE i.confirm_hash IS NULL;
|
WHERE i.execute_hash IS NULL;
|
||||||
|
|
||||||
|
-- :name pending-payouts-list :? :*
|
||||||
|
-- :doc lists all recently closed issues awaiting to be confirmed
|
||||||
|
SELECT
|
||||||
|
i.contract_address AS contract_address,
|
||||||
|
i.issue_id AS issue_id,
|
||||||
|
i.execute_hash AS execute_hash
|
||||||
|
FROM issues i
|
||||||
|
INNER JOIN pull_requests p
|
||||||
|
ON (p.commit_id = i.commit_id OR coalesce(p.issue_number, -1) = i.issue_number)
|
||||||
|
AND p.repo_id = i.repo_id
|
||||||
|
INNER JOIN users u
|
||||||
|
ON u.id = p.user_id
|
||||||
|
WHERE i.confirm_hash IS NULL
|
||||||
|
AND i.execute_hash IS NOT NULL;
|
||||||
|
|
||||||
-- :name update-confirm-hash :! :n
|
-- :name update-confirm-hash :! :n
|
||||||
-- :doc updates issue with transaction hash
|
-- :doc updates issue with confirmation hash
|
||||||
UPDATE issues
|
UPDATE issues
|
||||||
SET confirm_hash = :confirm_hash
|
SET confirm_hash = :confirm_hash
|
||||||
WHERE issue_id = :issue_id;
|
WHERE issue_id = :issue_id;
|
||||||
|
|
||||||
|
-- :name update-execute-hash :! :n
|
||||||
|
-- :doc updates issue with execute transaction hash
|
||||||
|
UPDATE issues
|
||||||
|
SET execute_hash = :execute_hash
|
||||||
|
WHERE issue_id = :issue_id;
|
||||||
|
|
||||||
-- :name all-bounties-list :? :*
|
-- :name all-bounties-list :? :*
|
||||||
-- :doc lists all issues labeled as 'bounty'
|
-- :doc lists all issues labeled as 'bounty'
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -24,11 +24,21 @@
|
|||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/pending-bounties-list con-db)))
|
(db/pending-bounties-list con-db)))
|
||||||
|
|
||||||
|
(defn pending-payouts-list
|
||||||
|
[]
|
||||||
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
(db/pending-payouts-list con-db)))
|
||||||
|
|
||||||
(defn update-confirm-hash
|
(defn update-confirm-hash
|
||||||
[issue-id confirm-hash]
|
[issue-id confirm-hash]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/update-confirm-hash con-db {:issue_id issue-id :confirm_hash confirm-hash})))
|
(db/update-confirm-hash con-db {:issue_id issue-id :confirm_hash confirm-hash})))
|
||||||
|
|
||||||
|
(defn update-execute-hash
|
||||||
|
[issue-id execute-hash]
|
||||||
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
(db/update-execute-hash con-db {:issue_id issue-id :execute_hash execute-hash})))
|
||||||
|
|
||||||
(defn get-bounty-address
|
(defn get-bounty-address
|
||||||
[user repo issue-number]
|
[user repo issue-number]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
(:require [commiteth.eth.core :as eth]
|
(:require [commiteth.eth.core :as eth]
|
||||||
[clojure.tools.logging :as log]))
|
[clojure.tools.logging :as log]))
|
||||||
|
|
||||||
|
(def confirmation-topic "0xe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda")
|
||||||
|
|
||||||
(defn get-owner
|
(defn get-owner
|
||||||
[contract index]
|
[contract index]
|
||||||
(eth/call contract "0xc41a360a" index))
|
(eth/call contract "0xc41a360a" index))
|
||||||
@ -10,3 +12,12 @@
|
|||||||
[contract to value]
|
[contract to value]
|
||||||
(log/debug "multisig.execute(contract, to, value)" contract to value)
|
(log/debug "multisig.execute(contract, to, value)" contract to value)
|
||||||
(eth/execute (eth/eth-account) contract "0xb61d27f6" to value "0x60" "0x0" "0x0"))
|
(eth/execute (eth/eth-account) contract "0xb61d27f6" to value "0x60" "0x0" "0x0"))
|
||||||
|
|
||||||
|
(defn find-confirmation-hash
|
||||||
|
[receipt]
|
||||||
|
(let [logs (:logs receipt)
|
||||||
|
has-confirmation-event #(some (fn [topic] (= topic confirmation-topic)) (:topics %))
|
||||||
|
confirmation-event (first (filter has-confirmation-event logs))
|
||||||
|
confirmation-data (:data confirmation-event)]
|
||||||
|
(when confirmation-data
|
||||||
|
(subs confirmation-data 66))))
|
||||||
|
@ -36,7 +36,18 @@
|
|||||||
:let [value (eth/get-balance-hex contract-address)]]
|
:let [value (eth/get-balance-hex contract-address)]]
|
||||||
(->>
|
(->>
|
||||||
(wallet/execute contract-address payout-address value)
|
(wallet/execute contract-address payout-address value)
|
||||||
(bounties/update-confirm-hash issue-id))))
|
(bounties/update-execute-hash issue-id))))
|
||||||
|
|
||||||
|
(defn update-confirm-hash
|
||||||
|
"Gets transaction receipt for each pending payout and updates confirm_hash"
|
||||||
|
[]
|
||||||
|
(doseq [{issue-id :issue_id
|
||||||
|
execute-hash :execute_hash} (bounties/pending-payouts-list)]
|
||||||
|
(log/debug "pending payout:" execute-hash)
|
||||||
|
(when-let [receipt (eth/get-transaction-receipt execute-hash)]
|
||||||
|
(log/info "execution receipt for issue #" issue-id ": " receipt)
|
||||||
|
(when-let [confirm-hash (wallet/find-confirmation-hash receipt)]
|
||||||
|
(bounties/update-confirm-hash issue-id confirm-hash)))))
|
||||||
|
|
||||||
(defn update-balance
|
(defn update-balance
|
||||||
[]
|
[]
|
||||||
@ -64,7 +75,7 @@
|
|||||||
(first (filter #(= name (.getName %)) threads))))
|
(first (filter #(= name (.getName %)) threads))))
|
||||||
|
|
||||||
(defn every
|
(defn every
|
||||||
[ms do-fn]
|
[ms tasks]
|
||||||
(.start (new Thread
|
(.start (new Thread
|
||||||
(fn []
|
(fn []
|
||||||
(while (not (.isInterrupted (Thread/currentThread)))
|
(while (not (.isInterrupted (Thread/currentThread)))
|
||||||
@ -72,7 +83,9 @@
|
|||||||
(Thread/sleep ms)
|
(Thread/sleep ms)
|
||||||
(catch InterruptedException _
|
(catch InterruptedException _
|
||||||
(.interrupt (Thread/currentThread))))
|
(.interrupt (Thread/currentThread))))
|
||||||
(do-fn))))
|
(doseq [task tasks]
|
||||||
|
(try (task)
|
||||||
|
(catch Exception e (log/error e)))))))
|
||||||
scheduler-thread-name)))
|
scheduler-thread-name)))
|
||||||
|
|
||||||
(defn stop-scheduler []
|
(defn stop-scheduler []
|
||||||
@ -80,16 +93,17 @@
|
|||||||
(log/debug "Stopping scheduler thread")
|
(log/debug "Stopping scheduler thread")
|
||||||
(.interrupt scheduler)))
|
(.interrupt scheduler)))
|
||||||
|
|
||||||
(defn restart-scheduler [ms task]
|
(defn restart-scheduler [ms tasks]
|
||||||
(stop-scheduler)
|
(stop-scheduler)
|
||||||
(log/debug "Starting scheduler thread")
|
(log/debug "Starting scheduler thread")
|
||||||
(while (get-thread-by-name scheduler-thread-name)
|
(while (get-thread-by-name scheduler-thread-name)
|
||||||
(Thread/sleep 1))
|
(Thread/sleep 1))
|
||||||
(every ms task))
|
(every ms tasks))
|
||||||
|
|
||||||
(mount/defstate scheduler
|
(mount/defstate scheduler
|
||||||
:start (restart-scheduler 60000 (fn []
|
:start (restart-scheduler 60000
|
||||||
(update-issue-contract-address)
|
[update-issue-contract-address
|
||||||
(self-sign-bounty)
|
update-confirm-hash
|
||||||
(update-balance)))
|
self-sign-bounty
|
||||||
|
update-balance])
|
||||||
:stop (stop-scheduler))
|
:stop (stop-scheduler))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user