-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokens_prices_options.go
64 lines (49 loc) · 1.63 KB
/
tokens_prices_options.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
64
package sqsclient
import (
"fmt"
"net/url"
"strings"
)
// TokenPricesOptions is the type for the options for the /tokens/prices endpoint.
type TokenPricesOptions struct {
// HumanDenoms is a flag to set the human denoms for the /tokens/prices endpoint.
HumanDenoms bool
// BaseDenoms is a list of base denoms to get the prices for.
BaseDenoms []string
}
// TokenPricesOption is the type for the options for the /tokens/prices endpoint.
type TokenPricesOption func(opts *TokenPricesOptions)
// WithHumanDenomsPrices is an option to set the human denoms for the /tokens/prices endpoint.
func WithHumanDenomsPrices() TokenPricesOption {
return func(opts *TokenPricesOptions) {
opts.HumanDenoms = true
}
}
// WithBaseDenoms is an option to set the base denoms for the /tokens/prices endpoint.
func WithBaseDenoms(denoms []string) TokenPricesOption {
return func(opts *TokenPricesOptions) {
opts.BaseDenoms = denoms
}
}
// WithBaseDenom is an option to set the base denom for the /tokens/prices endpoint.
func WithBaseDenom(denom string) TokenPricesOption {
return WithBaseDenoms([]string{denom})
}
// Validate validates the options for the /tokens/prices endpoint.
func (opts *TokenPricesOptions) Validate() error {
if len(opts.BaseDenoms) == 0 {
return fmt.Errorf("base denoms is required")
}
return nil
}
func (opts *TokenPricesOptions) CreateQueryParams() url.Values {
queryParams := url.Values{}
if opts.HumanDenoms {
queryParams.Add("humanDenoms", "true")
} else {
queryParams.Add("humanDenoms", "false")
}
queryParams.Add("base", strings.Join(opts.BaseDenoms, ","))
return queryParams
}
var _ Options = &TokenPricesOptions{}