@@ -2,11 +2,13 @@ package utils
2
2
3
3
import (
4
4
"context"
5
+ "github.com/avast/retry-go"
5
6
"github.com/ethereum/go-ethereum"
6
7
"github.com/ethereum/go-ethereum/common"
7
8
"github.com/ethereum/go-ethereum/core/types"
8
9
"github.com/ethereum/go-ethereum/ethclient"
9
10
"math/big"
11
+ "razor/core"
10
12
)
11
13
12
14
func (* ClientStruct ) GetNonceAtWithRetry (client * ethclient.Client , accountAddress common.Address ) (uint64 , error ) {
@@ -27,19 +29,43 @@ func (*ClientStruct) GetLatestBlockWithRetry(client *ethclient.Client) (*types.H
27
29
}
28
30
29
31
func (* ClientStruct ) SuggestGasPriceWithRetry (client * ethclient.Client ) (* big.Int , error ) {
30
- returnedValues , err := InvokeFunctionWithRetryAttempts (ClientInterface , "SuggestGasPrice" , client , context .Background ())
32
+ var (
33
+ gasPrice * big.Int
34
+ err error
35
+ )
36
+ err = retry .Do (
37
+ func () error {
38
+ gasPrice , err = ClientInterface .SuggestGasPrice (client , context .Background ())
39
+ if err != nil {
40
+ log .Error ("Error in fetching gas price.... Retrying" )
41
+ return err
42
+ }
43
+ return nil
44
+ }, RetryInterface .RetryAttempts (core .MaxRetries ))
31
45
if err != nil {
32
46
return nil , err
33
47
}
34
- return returnedValues [ 0 ]. Interface ().( * big. Int ) , nil
48
+ return gasPrice , nil
35
49
}
36
50
37
51
func (* ClientStruct ) EstimateGasWithRetry (client * ethclient.Client , message ethereum.CallMsg ) (uint64 , error ) {
38
- returnedValues , err := InvokeFunctionWithRetryAttempts (ClientInterface , "EstimateGas" , client , context .Background (), message )
52
+ var (
53
+ gasLimit uint64
54
+ err error
55
+ )
56
+ err = retry .Do (
57
+ func () error {
58
+ gasLimit , err = ClientInterface .EstimateGas (client , context .Background (), message )
59
+ if err != nil {
60
+ log .Error ("Error in estimating gas limit.... Retrying" )
61
+ return err
62
+ }
63
+ return nil
64
+ }, RetryInterface .RetryAttempts (core .MaxRetries ))
39
65
if err != nil {
40
66
return 0 , err
41
67
}
42
- return returnedValues [ 0 ]. Interface ().( uint64 ) , nil
68
+ return gasLimit , nil
43
69
}
44
70
45
71
func (* ClientStruct ) FilterLogsWithRetry (client * ethclient.Client , query ethereum.FilterQuery ) ([]types.Log , error ) {
0 commit comments