Skip to content

Commit 6d45bae

Browse files
authored
make contract usable by 3rd tools (#93)
1 parent 1099c4a commit 6d45bae

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

contract/contract.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ type FlowContract struct {
2424

2525
type TxRetryOption struct {
2626
Timeout time.Duration
27-
maxNonGasRetries int
28-
maxGasPrice *big.Int
27+
MaxNonGasRetries int
28+
MaxGasPrice *big.Int
2929
}
3030

31-
var specifiedBlockError = "Specified block header does not exist"
32-
var defaultTimeout = 30 * time.Second
33-
var defaultMaxNonGasRetries = 10
31+
var SpecifiedBlockError = "Specified block header does not exist"
32+
var DefaultTimeout = 30 * time.Second
33+
var DefaultMaxNonGasRetries = 10
3434

35-
func isRetriableSubmitLogEntryError(msg string) bool {
36-
return strings.Contains(msg, specifiedBlockError) || strings.Contains(msg, "mempool") || strings.Contains(msg, "timeout")
35+
func IsRetriableSubmitLogEntryError(msg string) bool {
36+
return strings.Contains(msg, SpecifiedBlockError) || strings.Contains(msg, "mempool") || strings.Contains(msg, "timeout")
3737
}
3838

3939
func NewFlowContract(flowAddress common.Address, clientWithSigner *web3go.Client) (*FlowContract, error) {
@@ -114,8 +114,8 @@ func TransactWithGasAdjustment(
114114
// Set timeout and max non-gas retries from retryOpts if provided.
115115
if retryOpts == nil {
116116
retryOpts = &TxRetryOption{
117-
Timeout: defaultTimeout,
118-
maxNonGasRetries: defaultMaxNonGasRetries,
117+
Timeout: DefaultTimeout,
118+
MaxNonGasRetries: DefaultMaxNonGasRetries,
119119
}
120120
}
121121

@@ -144,26 +144,26 @@ func TransactWithGasAdjustment(
144144

145145
errStr := strings.ToLower(err.Error())
146146

147-
if !isRetriableSubmitLogEntryError(errStr) {
147+
if !IsRetriableSubmitLogEntryError(errStr) {
148148
return nil, fmt.Errorf("failed to send transaction: %w", err)
149149
}
150150

151151
if strings.Contains(errStr, "mempool") || strings.Contains(errStr, "timeout") {
152-
if retryOpts.maxGasPrice == nil {
152+
if retryOpts.MaxGasPrice == nil {
153153
return nil, fmt.Errorf("mempool full and no max gas price is set, failed to send transaction: %w", err)
154154
} else {
155155
newGasPrice := new(big.Int).Mul(opts.GasPrice, big.NewInt(11))
156156
newGasPrice.Div(newGasPrice, big.NewInt(10))
157-
if newGasPrice.Cmp(retryOpts.maxGasPrice) > 0 {
158-
opts.GasPrice = new(big.Int).Set(retryOpts.maxGasPrice)
157+
if newGasPrice.Cmp(retryOpts.MaxGasPrice) > 0 {
158+
opts.GasPrice = new(big.Int).Set(retryOpts.MaxGasPrice)
159159
} else {
160160
opts.GasPrice = newGasPrice
161161
}
162162
logrus.WithError(err).Infof("Increasing gas price to %v due to mempool/timeout error", opts.GasPrice)
163163
}
164164
} else {
165165
nRetries++
166-
if nRetries >= retryOpts.maxNonGasRetries {
166+
if nRetries >= retryOpts.MaxNonGasRetries {
167167
return nil, fmt.Errorf("failed to send transaction after %d retries: %w", nRetries, err)
168168
}
169169
logrus.WithError(err).Infof("Retrying with same gas price %v, attempt %d", opts.GasPrice, nRetries)

0 commit comments

Comments
 (0)