generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathxpub_api.go
57 lines (47 loc) · 1.09 KB
/
xpub_api.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
package xpubs
import (
"context"
"fmt"
"net/url"
"github.com/bitcoin-sv/spv-wallet-go-client/commands"
"github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/go-resty/resty/v2"
)
const (
route = "api/v1/users/current"
api = "User XPubs API"
)
type API struct {
url *url.URL
httpClient *resty.Client
}
func (a *API) XPub(ctx context.Context) (*response.Xpub, error) {
var result response.Xpub
_, err := a.httpClient.
R().
SetContext(ctx).
SetResult(&result).
Get(a.url.String())
if err != nil {
return nil, fmt.Errorf("HTTP response failure: %w", err)
}
return &result, nil
}
func (a *API) UpdateXPubMetadata(ctx context.Context, cmd *commands.UpdateXPubMetadata) (*response.Xpub, error) {
var result response.Xpub
_, err := a.httpClient.R().
SetContext(ctx).
SetResult(&result).
SetBody(cmd).
Patch(a.url.String())
if err != nil {
return nil, fmt.Errorf("HTTP response failure: %w", err)
}
return &result, nil
}
func NewAPI(url *url.URL, httpClient *resty.Client) *API {
return &API{
url: url.JoinPath(route),
httpClient: httpClient,
}
}