Skip to content

Commit

Permalink
parallelize queries for tx and txreceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tikhomirov committed Dec 20, 2024
1 parent 93863c9 commit 758fe5f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions waku/incentivization/txid_proof.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ proc getMinedTransactionReceipt(
proc getTxAndTxReceipt(
txHash: TxHash, web3: Web3
): Future[Result[(TransactionObject, ReceiptObject), string]] {.async.} =
# get tx
let txFuture = getTransactionByHash(txHash, web3)
let tx = await txFuture
# get tx receipt
let receiptFuture = getMinedTransactionReceipt(txHash, web3)
let txReceipt = await receiptFuture
await allFutures(txFuture, receiptFuture)
let tx = txFuture.read()
let txReceipt = receiptFuture.read()
if txReceipt.isErr:
return err("Cannot get tx receipt")
return ok((tx, txReceipt.value()))
return ok((tx, txReceipt.get()))

proc isEligibleTxId*(
eligibilityProof: EligibilityProof,
Expand All @@ -55,10 +54,15 @@ proc isEligibleTxId*(
var tx: TransactionObject
var txReceipt: ReceiptObject
let txHash = TxHash.fromHex(byteutils.toHex(eligibilityProof.proofOfPayment.get()))
let txAndTxReceipt = await getTxAndTxReceipt(txHash, web3)
txAndTxReceipt.isOkOr:
return err("Failed to fetch tx or tx receipt")
(tx, txReceipt) = txAndTxReceipt.value()
try:
let txAndTxReceipt = await getTxAndTxReceipt(txHash, web3)
txAndTxReceipt.isOkOr:
return err("Failed to fetch tx or tx receipt")
(tx, txReceipt) = txAndTxReceipt.value()
except ValueError:
let errorMsg = "Failed to fetch tx or tx receipt: " & getCurrentExceptionMsg()
error "exception in isEligibleTxId", error = $errorMsg
return err($errorMsg)
# check that it is not a contract creation tx
let toAddressOption = txReceipt.to
if toAddressOption.isNone:
Expand Down

0 comments on commit 758fe5f

Please sign in to comment.