@@ -7,6 +7,7 @@ import { ShelleyWallet } from "./crypto";
77import { uploadMetadataAndGetJsonHash } from "./metadata" ;
88import { WalletAndAnchorType } from "@types" ;
99import { Logger } from "@helpers/logger" ;
10+ import { functionWaitedAssert } from "./waitedLoop" ;
1011
1112/**
1213 * Polls the transaction status until it's resolved or times out.
@@ -16,43 +17,48 @@ export async function pollTransaction(
1617 txHash : string ,
1718 lockInfo ?: LockInterceptorInfo
1819) {
19- try {
20- Logger . info ( `Waiting for tx completion: ${ txHash } ` ) ;
21- await expect
22- . poll (
23- async ( ) => {
24- const response = await kuberService . getTransactionDetails ( txHash ) ;
25- const data = await response . json ( ) ;
26- return data . length ;
27- } ,
28- {
29- timeout : environments . txTimeOut ,
30- }
31- )
32- . toBeGreaterThan ( 0 ) ;
20+ await functionWaitedAssert (
21+ async ( ) => {
22+ try {
23+ Logger . info ( `Waiting for tx completion: ${ txHash } ` ) ;
24+ await expect
25+ . poll (
26+ async ( ) => {
27+ const response = await kuberService . getTransactionDetails ( txHash ) ;
28+ const data = await response . json ( ) ;
29+ return data . length ;
30+ } ,
31+ {
32+ timeout : environments . txTimeOut ,
33+ }
34+ )
35+ . toBeGreaterThan ( 0 ) ;
3336
34- Logger . success ( "Tx completed" ) ;
37+ Logger . success ( "Tx completed" ) ;
3538
36- if ( ! lockInfo ) return ;
39+ if ( ! lockInfo ) return ;
3740
38- await LockInterceptor . releaseLock (
39- lockInfo . initiator ,
40- lockInfo . lockId ,
41- `Task completed for:${ lockInfo . lockId } `
42- ) ;
43- } catch ( err ) {
44- if ( lockInfo ) {
45- const errorMessage = { lockInfo, error : JSON . stringify ( err ) } ;
46-
47- await LockInterceptor . releaseLock (
48- lockInfo . initiator ,
49- lockInfo . lockId ,
50- `Task failure: \n${ JSON . stringify ( errorMessage ) } `
51- ) ;
52- }
41+ await LockInterceptor . releaseLock (
42+ lockInfo . initiator ,
43+ lockInfo . lockId ,
44+ `Task completed for:${ lockInfo . lockId } `
45+ ) ;
46+ } catch ( err ) {
47+ if ( lockInfo ) {
48+ const errorMessage = { lockInfo, error : JSON . stringify ( err ) } ;
5349
54- throw err ;
55- }
50+ await LockInterceptor . releaseLock (
51+ lockInfo . initiator ,
52+ lockInfo . lockId ,
53+ `Task failure: \n${ JSON . stringify ( errorMessage ) } `
54+ ) ;
55+ }
56+ Logger . fail ( `Failed due to ${ err } ` ) ;
57+ throw err ;
58+ }
59+ } ,
60+ { timeout : environments . txTimeOut + 60_000 , name : "pollTransaction" }
61+ ) ;
5662}
5763
5864export async function waitForTxConfirmation (
0 commit comments