Skip to content

Commit beaa4d9

Browse files
committed
add opts for maxRetries and retryDelay in rpc client
1 parent 62ea18a commit beaa4d9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

xrpl/rpc/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ func WithHTTPClient(cl HTTPClient) ConfigOpt {
4343
}
4444
}
4545

46+
// WithMaxRetries returns a ConfigOpt that sets the maximum number of retries.
47+
func WithMaxRetries(maxRetries int) ConfigOpt {
48+
return func(c *Config) {
49+
c.maxRetries = maxRetries
50+
}
51+
}
52+
53+
// WithRetryDelay returns a ConfigOpt that sets the delay between retry attempts.
54+
func WithRetryDelay(retryDelay time.Duration) ConfigOpt {
55+
return func(c *Config) {
56+
c.retryDelay = retryDelay
57+
}
58+
}
59+
4660
// WithMaxFeeXRP returns a ConfigOpt that sets the maximum fee in XRP.
4761
func WithMaxFeeXRP(maxFeeXRP float32) ConfigOpt {
4862
return func(c *Config) {

xrpl/rpc/config_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ func TestWithTimeout(t *testing.T) {
8585

8686
require.Equal(t, timeOut, cfg.timeout)
8787
}
88+
89+
func TestWithMaxRetries(t *testing.T) {
90+
maxRetries := 5
91+
cfg, _ := NewClientConfig("http://s1.ripple.com:51234", WithMaxRetries(maxRetries))
92+
93+
require.Equal(t, maxRetries, cfg.maxRetries)
94+
}
95+
96+
func TestWithRetryDelay(t *testing.T) {
97+
retryDelay := 2 * time.Second
98+
cfg, _ := NewClientConfig("http://s1.ripple.com:51234", WithRetryDelay(retryDelay))
99+
100+
require.Equal(t, retryDelay, cfg.retryDelay)
101+
}

0 commit comments

Comments
 (0)