-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
63 lines (51 loc) · 1.35 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package client
import (
"time"
"github.com/glitternetwork/glitter-sdk-go/msg"
)
const DefaultChainEndpoint = "https://api.xian.glitter.link"
type Option interface {
apply(o *clientOptions)
}
// WithTimeout create client with http timeout
func WithTimeout(duration time.Duration) Option {
return fnOption(func(o *clientOptions) {
o.httpTimeout = duration
})
}
// WithChainEndpoint create client with custom chain endpoint
func WithChainEndpoint(endpoint string) Option {
return fnOption(func(o *clientOptions) {
o.endpoint = endpoint
})
}
// WithGasFeeConfig create client with custom gas fee config
func WithGasFeeConfig(gasPrice msg.DecCoin, gasAdjustment msg.Dec) Option {
return fnOption(func(o *clientOptions) {
o.gasPrice = gasPrice
o.gasAdjustment = gasAdjustment
})
}
type fnOption func(o *clientOptions)
func (f fnOption) apply(o *clientOptions) {
f(o)
}
type clientOptions struct {
endpoint string
gasPrice msg.DecCoin
gasAdjustment msg.Dec
httpTimeout time.Duration
}
var defaultClientOptions = clientOptions{
endpoint: DefaultChainEndpoint,
gasPrice: msg.NewDecCoinFromDec("agli", mustParseDecFromStr("1")),
gasAdjustment: mustParseDecFromStr("2.5"),
httpTimeout: time.Second * 10,
}
func mustParseDecFromStr(s string) msg.Dec {
dec, err := msg.NewDecFromStr(s)
if err != nil {
panic(err)
}
return dec
}