-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.go
58 lines (48 loc) 路 1.47 KB
/
client.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
package rewards
import (
"context"
"github.com/coinbase/staking-client-library-go/client/options"
innerClient "github.com/coinbase/staking-client-library-go/gen/client/coinbase/staking/rewards/v1"
"google.golang.org/grpc"
)
const (
// ServiceEndpoint is the endpoint the client will use.
serviceEndpoint = "https://api.developer.coinbase.com/staking/rewards"
)
// Client is the client to use to access StakingService APIs.
type Client struct {
client *innerClient.RewardClient
}
// NewRewardsServiceClient returns a RewardsServiceClient based on the given inputs.
func NewRewardsServiceClient(
ctx context.Context,
stakingOpts ...options.StakingClientOption,
) (*Client, error) {
config, err := options.GetConfig("rewards-reporting", serviceEndpoint, stakingOpts...)
if err != nil {
return nil, err
}
clientOptions, err := options.GetClientOptions(config)
if err != nil {
return nil, err
}
innerClient, err := innerClient.NewRewardRESTClient(ctx, clientOptions...)
if err != nil {
return nil, err
}
return &Client{
client: innerClient,
}, nil
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (s *Client) Close() error {
return s.client.Close()
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (s *Client) Connection() *grpc.ClientConn {
return s.client.Connection()
}