/
client.go
36 lines (30 loc) 路 1.04 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
package client
import (
"context"
"fmt"
"github.com/coinbase/staking-client-library-go/client/options"
orchestrationClient "github.com/coinbase/staking-client-library-go/client/orchestration/v1"
rewardsClient "github.com/coinbase/staking-client-library-go/client/rewards/v1"
)
type StakingClient struct {
Orchestration *orchestrationClient.OrchestrationServiceClient
Rewards *rewardsClient.RewardsServiceClient
}
// New returns a StakingClient based on the given inputs.
func New(
ctx context.Context,
stakingOpts ...options.StakingClientOption,
) (*StakingClient, error) {
orchestrationClient, err := orchestrationClient.NewOrchestrationServiceClient(ctx, stakingOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create orchestration client: %w", err)
}
rewardsClient, err := rewardsClient.NewRewardsServiceClient(ctx, stakingOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create rewards client: %w", err)
}
return &StakingClient{
Orchestration: orchestrationClient,
Rewards: rewardsClient,
}, nil
}