@@ -77,19 +77,31 @@ func (*UtilsStruct) CheckTransactionReceipt(client *ethclient.Client, _txHash st
77
77
}
78
78
79
79
func (* UtilsStruct ) WaitForBlockCompletion (client * ethclient.Client , hashToRead string ) error {
80
+ ctx , cancel := context .WithTimeout (context .Background (), core .BlockCompletionTimeout * time .Second )
81
+ defer cancel ()
82
+
80
83
for i := 0 ; i < core .BlockCompletionAttempts ; i ++ {
81
- log .Debug ("Checking if transaction is mined...." )
82
- transactionStatus := UtilsInterface .CheckTransactionReceipt (client , hashToRead )
83
- if transactionStatus == 0 {
84
- err := errors .New ("transaction mining unsuccessful" )
85
- log .Error (err )
86
- return err
87
- } else if transactionStatus == 1 {
88
- log .Info ("Transaction mined successfully" )
89
- return nil
84
+ select {
85
+ case <- ctx .Done ():
86
+ log .Error ("Timeout: WaitForBlockCompletion took too long" )
87
+ return errors .New ("timeout exceeded for transaction mining" )
88
+ default :
89
+ log .Debug ("Checking if transaction is mined...." )
90
+ transactionStatus := UtilsInterface .CheckTransactionReceipt (client , hashToRead )
91
+
92
+ if transactionStatus == 0 {
93
+ err := errors .New ("transaction mining unsuccessful" )
94
+ log .Error (err )
95
+ return err
96
+ } else if transactionStatus == 1 {
97
+ log .Info ("Transaction mined successfully" )
98
+ return nil
99
+ }
100
+
101
+ time .Sleep (core .BlockCompletionAttemptRetryDelay * time .Second )
90
102
}
91
- Time .Sleep (core .BlockCompletionAttemptRetryDelay * time .Second )
92
103
}
104
+
93
105
log .Info ("Max retries for WaitForBlockCompletion attempted!" )
94
106
return errors .New ("maximum attempts failed for transaction mining" )
95
107
}
0 commit comments