Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions source/deth/rpcconnector.d
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,33 @@ class RPCConnector : JsonRpcAutoAttributeClient!IEthRPC
/// Params:
/// txHash = hash of the transaction
/// Returns: TransactionReceipt of mined transaction or throws an exception
TransactionReceipt waitForTransactionReceipt(Hash txHash) @safe
TransactionReceipt waitForTransactionReceipt(Hash txHash, ulong confirmations = 1) @safe
{
enforce(confirmations >= 1, "confirmations must be at least 1");
ulong count;
while (getTransaction(txHash).blockHash.isNull)
{
enforce(count < 500, "Timeout for waiting tx"); // TODO: add timeout into connector
() @trusted { Thread.sleep(200.dur!"msecs"); }();
count++;
}
return getTransactionReceipt(txHash).get;
auto receipt = getTransactionReceipt(txHash).get;

if (confirmations > 1)
{
ulong confirmCount;
while (true)
{
enforce(confirmCount < 500, "Timeout for waiting confirmations");
auto currentBlock = eth_blockNumber()[2 .. $].to!ulong(16);
if (currentBlock >= receipt.blockNumber + confirmations - 1)
break;
() @trusted { Thread.sleep(200.dur!"msecs"); }();
confirmCount++;
}
}

return receipt;
}

///
Expand Down