Skip to content

Commit

Permalink
feat(connector-xdai): add interval to pollForTxReceipt
Browse files Browse the repository at this point in the history
Signed-off-by: Pritam Singh <pkspritam16@gmail.com>
  • Loading branch information
Zzocker authored and petermetz committed Jun 28, 2021
1 parent d470540 commit 40be742
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"type": "integer",
"minimum": 0,
"description": "The number of blocks to wait to be confirmed in addition to the block containing the transaction in question. Note that if the receipt type is set to only wait for node transaction pool ACK and this parameter is set to anything, but zero then the API will not accept the request due to conflicting parameters."
},
"pollIntervalMs" : {
"type": "integer",
"minimum": 0,
"description": "The amount of time (in milliseconds) connector will wait before making another confiramtion request to the network in case of previous confiramtion request fails"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export interface ConsistencyStrategy {
* @memberof ConsistencyStrategy
*/
blockConfirmations: number;
/**
* The amount of time (in milliseconds) connector will wait before making another confiramtion request to the network in case of previous confiramtion request fails
* @type {number}
* @memberof ConsistencyStrategy
*/
pollIntervalMs?: number;
}
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ export class PluginLedgerConnectorXdai
consistencyStrategy: ConsistencyStrategy,
): Promise<TransactionReceipt> {
const fnTag = `${this.className}#pollForTxReceipt()`;
if (consistencyStrategy.receiptType === ReceiptType.NodeTxPoolAck) {
consistencyStrategy.blockConfirmations = 0;
}
let txReceipt;
let timedOut = false;
let tries = 0;
Expand All @@ -496,14 +499,18 @@ export class PluginLedgerConnectorXdai
break;
}

await new Promise((resolve) =>
setTimeout(resolve, consistencyStrategy.pollIntervalMs),
);

txReceipt = await this.web3.eth.getTransactionReceipt(txHash);
if (!txReceipt) {
continue;
}

const latestBlockNo = await this.web3.eth.getBlockNumber();
confirmationCount = latestBlockNo - txReceipt.blockNumber;
} while (confirmationCount >= consistencyStrategy.blockConfirmations);
} while (confirmationCount < consistencyStrategy.blockConfirmations);

if (!txReceipt) {
throw new Error(`${fnTag} Timed out ${timeoutMs}ms, polls=${tries}`);
Expand Down

0 comments on commit 40be742

Please sign in to comment.