forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
111 lines (92 loc) · 3.02 KB
/
option.go
File metadata and controls
111 lines (92 loc) · 3.02 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package api
import (
"fmt"
"github.com/textileio/powergate/ffs"
)
// PushStorageConfigOption mutates a push configuration.
type PushStorageConfigOption func(o *PushStorageConfigConfig) error
// PushStorageConfigConfig contains options for pushing a Cid configuration.
type PushStorageConfigConfig struct {
Config ffs.StorageConfig
OverrideConfig bool
}
// WithStorageConfig overrides the Api default Cid configuration.
func WithStorageConfig(c ffs.StorageConfig) PushStorageConfigOption {
return func(o *PushStorageConfigConfig) error {
o.Config = c
return nil
}
}
// WithOverride allows a new push configuration to override an existing one.
// It's used as an extra security measure to avoid unwanted configuration changes.
func WithOverride(override bool) PushStorageConfigOption {
return func(o *PushStorageConfigConfig) error {
o.OverrideConfig = override
return nil
}
}
// Validate validates a PushStorageConfigConfig.
func (pc PushStorageConfigConfig) Validate() error {
if err := pc.Config.Validate(); err != nil {
return fmt.Errorf("invalid config: %s", err)
}
return nil
}
// NewAddressOption is a function that changes a NewAddressConfig.
type NewAddressOption func(config *NewAddressConfig)
// WithMakeDefault specifies if the new address should become the default.
func WithMakeDefault(makeDefault bool) NewAddressOption {
return func(c *NewAddressConfig) {
c.makeDefault = makeDefault
}
}
// WithAddressType specifies the type of address to create.
func WithAddressType(addressType string) NewAddressOption {
return func(c *NewAddressConfig) {
c.addressType = addressType
}
}
// GetLogsOption is a function that changes GetLogsConfig.
type GetLogsOption func(config *GetLogsConfig)
// WithJidFilter filters only log messages of a Cid related to
// the Job with id jid.
func WithJidFilter(jid ffs.JobID) GetLogsOption {
return func(c *GetLogsConfig) {
c.jid = jid
}
}
// WithHistory indicates that prior log history should be sent
// to the channel before getting realtime logs.
func WithHistory(enabled bool) GetLogsOption {
return func(c *GetLogsConfig) {
c.history = enabled
}
}
type importConfig struct {
validate bool
}
// ImportOption provides configurations for importing deal information.
type ImportOption func(*importConfig)
// WithValidateImport indicates to validate imported deal information
// to check for inconsistencies.
func WithValidateImport(enabled bool) ImportOption {
return func(c *importConfig) {
c.validate = enabled
}
}
// RetrievalOption provides a retrieval configuration setup.
type RetrievalOption func(*retrievalConfig)
// WithRetrievalWalletAddress indicates which wallet address to use
// for doing the deal retrieval.
func WithRetrievalWalletAddress(addr string) RetrievalOption {
return func(prc *retrievalConfig) {
prc.walletAddress = addr
}
}
// WithRetrievalMaxPrice indicates which is the maximum prices
// to pay for the retrieval.
func WithRetrievalMaxPrice(maxPrice uint64) RetrievalOption {
return func(prc *retrievalConfig) {
prc.maxPrice = maxPrice
}
}