/
client.go
74 lines (62 loc) · 2.12 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package client
import (
"context"
userPb "github.com/textileio/powergate/v2/api/gen/powergate/user/v1"
"google.golang.org/grpc"
)
// Client provides the client api.
type Client struct {
powC userPb.UserServiceClient
conn *grpc.ClientConn
}
// NewClient starts the client.
func NewClient(target string, opts ...grpc.DialOption) (*Client, error) {
conn, err := grpc.Dial(target, opts...)
if err != nil {
return nil, err
}
return &Client{
powC: userPb.NewUserServiceClient(conn),
conn: conn,
}, nil
}
func (c *Client) Addresses(ctx context.Context) (*userPb.AddressesResponse, error) {
return c.powC.Addresses(ctx, &userPb.AddressesRequest{})
}
func (c *Client) Balance(ctx context.Context, addr string) (*userPb.BalanceResponse, error) {
req := &userPb.BalanceRequest{
Address: addr,
}
return c.powC.Balance(ctx, req)
}
func (c *Client) SignMessage(ctx context.Context, address string, message []byte) (*userPb.SignMessageResponse, error) {
req := &userPb.SignMessageRequest{
Address: address,
Message: message,
}
return c.powC.SignMessage(ctx, req)
}
func (c *Client) VerifyMessage(ctx context.Context, address string, message, signature []byte) (*userPb.VerifyMessageResponse, error) {
r := &userPb.VerifyMessageRequest{Address: address, Message: message, Signature: signature}
return c.powC.VerifyMessage(ctx, r)
}
func (c *Client) CidInfo(ctx context.Context, cid string) (*userPb.CidInfoResponse, error) {
req := &userPb.CidInfoRequest{Cid: cid}
return c.powC.CidInfo(ctx, req)
}
func (c *Client) StorageDealRecords(ctx context.Context, config *userPb.DealRecordsConfig) (*userPb.StorageDealRecordsResponse, error) {
req := &userPb.StorageDealRecordsRequest{
Config: config,
}
return c.powC.StorageDealRecords(ctx, req)
}
func (c *Client) RetrievalDealRecords(ctx context.Context, config *userPb.DealRecordsConfig) (*userPb.RetrievalDealRecordsResponse, error) {
req := &userPb.RetrievalDealRecordsRequest{
Config: config,
}
return c.powC.RetrievalDealRecords(ctx, req)
}
// Close closes the client's grpc connection and cancels any active requests.
func (c *Client) Close() error {
return c.conn.Close()
}