mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-11 06:26:43 +00:00
make queries to web3 provider in parallel
This commit is contained in:
parent
586dadd94a
commit
e517ecaf8e
@ -4,6 +4,25 @@ import waku/incentivization/rpc
|
|||||||
|
|
||||||
const SimpleTransferGasUsed = Quantity(21000)
|
const SimpleTransferGasUsed = Quantity(21000)
|
||||||
|
|
||||||
|
proc eth_getTransactionByHash_async(
|
||||||
|
txHash: TxHash, web3: Web3
|
||||||
|
): Future[TransactionObject] {.async.} =
|
||||||
|
await web3.provider.eth_getTransactionByHash(txHash)
|
||||||
|
|
||||||
|
proc getMinedTransactionReceipt_async(
|
||||||
|
txHash: TxHash, web3: Web3
|
||||||
|
): Future[ReceiptObject] {.async.} =
|
||||||
|
await web3.getMinedTransactionReceipt(txHash)
|
||||||
|
|
||||||
|
proc getTxAndTxReceipt(
|
||||||
|
txHash: TxHash, web3: Web3
|
||||||
|
): Future[(TransactionObject, ReceiptObject)] {.async.} =
|
||||||
|
let txFuture = eth_getTransactionByHash_async(txHash, web3)
|
||||||
|
let receiptFuture = getMinedTransactionReceipt_async(txHash, web3)
|
||||||
|
let tx = await txFuture
|
||||||
|
let txReceipt = await receiptFuture
|
||||||
|
return (tx, txReceipt)
|
||||||
|
|
||||||
proc isEligibleTxId*(
|
proc isEligibleTxId*(
|
||||||
eligibilityProof: EligibilityProof,
|
eligibilityProof: EligibilityProof,
|
||||||
expectedToAddress: Address,
|
expectedToAddress: Address,
|
||||||
@ -28,9 +47,7 @@ proc isEligibleTxId*(
|
|||||||
var txReceipt: ReceiptObject
|
var txReceipt: ReceiptObject
|
||||||
let txHash = TxHash.fromHex(byteutils.toHex(eligibilityProof.proofOfPayment.get()))
|
let txHash = TxHash.fromHex(byteutils.toHex(eligibilityProof.proofOfPayment.get()))
|
||||||
try:
|
try:
|
||||||
# TODO: make requests in parallel (?)
|
(tx, txReceipt) = waitFor getTxAndTxReceipt(txHash, web3)
|
||||||
tx = await web3.provider.eth_getTransactionByHash(txHash)
|
|
||||||
txReceipt = await web3.getMinedTransactionReceipt(txHash)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
let errorMsg = "Failed to fetch tx or tx receipt: " & getCurrentExceptionMsg()
|
let errorMsg = "Failed to fetch tx or tx receipt: " & getCurrentExceptionMsg()
|
||||||
error "exception in isEligibleTxId", error = $errorMsg
|
error "exception in isEligibleTxId", error = $errorMsg
|
||||||
|
Loading…
x
Reference in New Issue
Block a user