Ensure that `confirm` future is only finished once

Should fix CI failure
https://github.com/status-im/nim-ethers/runs/6557104597
This commit is contained in:
Mark Spanbroek 2022-05-23 16:58:45 +02:00 committed by markspanbroek
parent 649dc8efd0
commit fff0d189a5
1 changed files with 6 additions and 4 deletions

View File

@ -261,15 +261,17 @@ method confirm*(tx: TransactionResponse,
if receipt.hasBeenMined(blkNum, wantedConfirms): if receipt.hasBeenMined(blkNum, wantedConfirms):
# fire and forget # fire and forget
discard subscription.unsubscribe() discard subscription.unsubscribe()
retFut.complete(receipt.get) if not retFut.finished:
retFut.complete(receipt.get)
elif timeoutInBlocks > 0: elif timeoutInBlocks > 0:
let blocksPassed = (blkNum - startBlock) + 1 let blocksPassed = (blkNum - startBlock) + 1
if blocksPassed >= timeoutInBlocks.u256: if blocksPassed >= timeoutInBlocks.u256:
discard subscription.unsubscribe() discard subscription.unsubscribe()
retFut.fail( if not retFut.finished:
newException(JsonRpcProviderError, "Transaction was not mined in " & let message =
$timeoutInBlocks & " blocks")) "Transaction was not mined in " & $timeoutInBlocks & " blocks"
retFut.fail(newException(JsonRpcProviderError, message))
# If our tx is already mined, return the receipt. Otherwise, check each # If our tx is already mined, return the receipt. Otherwise, check each
# new block to see if the tx has been mined # new block to see if the tx has been mined