Throw exception if attempting to create tx with the same nonce
This commit is contained in:
parent
61e8d2188f
commit
24e39ad867
|
@ -23,7 +23,7 @@
|
|||
(defn deploy-contract [owner owner-address repo issue-id issue-number]
|
||||
(if (empty? owner-address)
|
||||
(log/errorf "issue %s: Unable to deploy bounty contract because repo owner has no Ethereum addres" issue-id)
|
||||
(do
|
||||
(try
|
||||
(log/infof "issue %s: Deploying contract to %s" issue-id owner-address)
|
||||
(if-let [transaction-hash (multisig/deploy-multisig owner-address)]
|
||||
(do
|
||||
|
@ -36,7 +36,8 @@
|
|||
(log/infof "issue %s: post-deploying-comment response: %s" issue-id resp)
|
||||
(issues/update-comment-id issue-id comment-id))
|
||||
(issues/update-transaction-hash issue-id transaction-hash))
|
||||
(log/errorf "issue %s Failed to deploy contract to %s" issue-id owner-address)))))
|
||||
(log/errorf "issue %s Failed to deploy contract to %s" issue-id owner-address))
|
||||
(catch Exception ex (log/errorf ex "issue %s: deploy-contract exception" issue-id)))))
|
||||
|
||||
(defn add-bounty-for-issue [repo repo-id issue]
|
||||
(let [{issue-id :id
|
||||
|
|
|
@ -53,18 +53,27 @@
|
|||
(throw (ex-info "Make sure you provided proper credentials in appropriate resources/config.edn"
|
||||
{:password password :file-path file-path}))))))
|
||||
|
||||
(defn get-nonce []
|
||||
(let [current-nonce (atom nil)]
|
||||
(fn []
|
||||
(let [nonce (.. (.ethGetTransactionCount (create-web3j)
|
||||
(env :eth-account)
|
||||
DefaultBlockParameterName/LATEST)
|
||||
sendAsync
|
||||
get
|
||||
getTransactionCount)]
|
||||
(if (= nonce @current-nonce)
|
||||
(throw (Exception. (str "Attempting to create transaction with the same nonce: " nonce)))
|
||||
(swap! current-nonce (constantly nonce)))
|
||||
(log/info "Current nonce:" nonce)
|
||||
nonce))))
|
||||
|
||||
(defn get-signed-tx [gas-price gas-limit to data]
|
||||
"Create a sign a raw transaction.
|
||||
'From' argument is not needed as it's already
|
||||
encoded in credentials.
|
||||
See https://web3j.readthedocs.io/en/latest/transactions.html#offline-transaction-signing"
|
||||
(let [web3j (create-web3j)
|
||||
nonce (.. (.ethGetTransactionCount web3j
|
||||
(env :eth-account)
|
||||
DefaultBlockParameterName/LATEST)
|
||||
sendAsync
|
||||
get
|
||||
getTransactionCount)
|
||||
(let [nonce ((get-nonce))
|
||||
tx (RawTransaction/createTransaction
|
||||
nonce
|
||||
gas-price
|
||||
|
|
Loading…
Reference in New Issue