forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
liquidity_pool_request.go
49 lines (39 loc) · 1.14 KB
/
liquidity_pool_request.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
package horizonclient
import (
"fmt"
"net/http"
"net/url"
"github.com/stellar/go/support/errors"
)
// LiquidityPoolRequest struct contains data for getting liquidity pool details from a horizon server.
type LiquidityPoolRequest struct {
LiquidityPoolID string
}
// BuildURL creates the endpoint to be queried based on the data in the LiquidityPoolRequest struct.
// If no data is set, it defaults to the build the URL for all assets
func (r LiquidityPoolRequest) BuildURL() (endpoint string, err error) {
nParams := countParams(r.LiquidityPoolID)
if nParams <= 0 {
err = errors.New("invalid request: no parameters")
}
if err != nil {
return endpoint, err
}
endpoint = fmt.Sprintf(
"liquidity_pools/%s",
r.LiquidityPoolID,
)
_, err = url.Parse(endpoint)
if err != nil {
err = errors.Wrap(err, "failed to parse endpoint")
}
return endpoint, err
}
// HTTPRequest returns the http request for the liquidity pool endpoint
func (r LiquidityPoolRequest) HTTPRequest(horizonURL string) (*http.Request, error) {
endpoint, err := r.BuildURL()
if err != nil {
return nil, err
}
return http.NewRequest("GET", horizonURL+endpoint, nil)
}