/
deals.go
80 lines (68 loc) · 2.69 KB
/
deals.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
75
76
77
78
79
80
package client
import (
"context"
userPb "github.com/textileio/powergate/v2/api/gen/powergate/user/v1"
)
// Deals provides access to Powergate deals APIs.
type Deals struct {
client userPb.UserServiceClient
}
// DealRecordsOption updates a ListDealRecordsConfig.
type DealRecordsOption func(*userPb.DealRecordsConfig)
// WithFromAddrs limits the results deals initiated from the provided wallet addresses.
// If WithDataCids is also provided, this is an AND operation.
func WithFromAddrs(addrs ...string) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.FromAddrs = addrs
}
}
// WithDataCids limits the results to deals for the provided data cids.
// If WithFromAddrs is also provided, this is an AND operation.
func WithDataCids(cids ...string) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.DataCids = cids
}
}
// WithIncludePending specifies whether or not to include pending deals in the results. Default is false.
// Ignored for ListRetrievalDealRecords.
func WithIncludePending(includePending bool) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.IncludePending = includePending
}
}
// WithIncludeFinal specifies whether or not to include final deals in the results. Default is false.
// Ignored for ListRetrievalDealRecords.
func WithIncludeFinal(includeFinal bool) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.IncludeFinal = includeFinal
}
}
// WithIncludeFailed specifies if failed records will be included in the output.
func WithIncludeFailed(includeFailed bool) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.IncludeFailed = includeFailed
}
}
// WithAscending specifies to sort the results in ascending order. Default is descending order.
// Records are sorted by timestamp.
func WithAscending(ascending bool) DealRecordsOption {
return func(c *userPb.DealRecordsConfig) {
c.Ascending = ascending
}
}
// StorageDealRecords returns a list of storage deals for the user according to the provided options.
func (d *Deals) StorageDealRecords(ctx context.Context, opts ...DealRecordsOption) (*userPb.StorageDealRecordsResponse, error) {
conf := &userPb.DealRecordsConfig{}
for _, opt := range opts {
opt(conf)
}
return d.client.StorageDealRecords(ctx, &userPb.StorageDealRecordsRequest{Config: conf})
}
// RetrievalDealRecords returns a list of retrieval deals for the user according to the provided options.
func (d *Deals) RetrievalDealRecords(ctx context.Context, opts ...DealRecordsOption) (*userPb.RetrievalDealRecordsResponse, error) {
conf := &userPb.DealRecordsConfig{}
for _, opt := range opts {
opt(conf)
}
return d.client.RetrievalDealRecords(ctx, &userPb.RetrievalDealRecordsRequest{Config: conf})
}