Skip to content

Commit 40be742

Browse files
Zzockerpetermetz
authored andcommitted
feat(connector-xdai): add interval to pollForTxReceipt
Signed-off-by: Pritam Singh <[email protected]>
1 parent d470540 commit 40be742

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/cactus-plugin-ledger-connector-xdai/src/main/json/openapi.json

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"type": "integer",
5656
"minimum": 0,
5757
"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."
58+
},
59+
"pollIntervalMs" : {
60+
"type": "integer",
61+
"minimum": 0,
62+
"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"
5863
}
5964
}
6065
},

packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/generated/openapi/typescript-axios/api.ts

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export interface ConsistencyStrategy {
4545
* @memberof ConsistencyStrategy
4646
*/
4747
blockConfirmations: number;
48+
/**
49+
* The amount of time (in milliseconds) connector will wait before making another confiramtion request to the network in case of previous confiramtion request fails
50+
* @type {number}
51+
* @memberof ConsistencyStrategy
52+
*/
53+
pollIntervalMs?: number;
4854
}
4955
/**
5056
*

packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/plugin-ledger-connector-xdai.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ export class PluginLedgerConnectorXdai
482482
consistencyStrategy: ConsistencyStrategy,
483483
): Promise<TransactionReceipt> {
484484
const fnTag = `${this.className}#pollForTxReceipt()`;
485+
if (consistencyStrategy.receiptType === ReceiptType.NodeTxPoolAck) {
486+
consistencyStrategy.blockConfirmations = 0;
487+
}
485488
let txReceipt;
486489
let timedOut = false;
487490
let tries = 0;
@@ -496,14 +499,18 @@ export class PluginLedgerConnectorXdai
496499
break;
497500
}
498501

502+
await new Promise((resolve) =>
503+
setTimeout(resolve, consistencyStrategy.pollIntervalMs),
504+
);
505+
499506
txReceipt = await this.web3.eth.getTransactionReceipt(txHash);
500507
if (!txReceipt) {
501508
continue;
502509
}
503510

504511
const latestBlockNo = await this.web3.eth.getBlockNumber();
505512
confirmationCount = latestBlockNo - txReceipt.blockNumber;
506-
} while (confirmationCount >= consistencyStrategy.blockConfirmations);
513+
} while (confirmationCount < consistencyStrategy.blockConfirmations);
507514

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

0 commit comments

Comments
 (0)