forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
75 lines (62 loc) · 1.76 KB
/
settings.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
package node
import (
"encoding/hex"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
"github.com/celestiaorg/celestia-node/core"
"github.com/celestiaorg/celestia-node/node/fxutil"
"github.com/celestiaorg/celestia-node/node/p2p"
)
// Option for Node's Config.
type Option func(*Config, *settings) error
// WithP2PKey sets custom Ed25519 private key for p2p networking.
func WithP2PKey(key crypto.PrivKey) Option {
return func(cfg *Config, sets *settings) (_ error) {
sets.P2PKey = key
return
}
}
// WithP2PKeyStr sets custom hex encoded Ed25519 private key for p2p networking.
func WithP2PKeyStr(key string) Option {
return func(cfg *Config, sets *settings) (_ error) {
decKey, err := hex.DecodeString(key)
if err != nil {
return err
}
key, err := crypto.UnmarshalEd25519PrivateKey(decKey)
if err != nil {
return err
}
sets.P2PKey = key
return
}
}
// WithHost sets custom Host's data for p2p networking.
func WithHost(host host.Host) Option {
return func(cfg *Config, sets *settings) (_ error) {
sets.Host = host
return
}
}
// WithCoreClient sets custom client for core process
func WithCoreClient(client core.Client) Option {
return func(cfg *Config, sets *settings) (_ error) {
sets.CoreClient = client
return
}
}
// settings store all the non Config values that can be altered for Node with Options.
type settings struct {
P2PKey crypto.PrivKey
Host p2p.HostBase
CoreClient core.Client
}
// overrides collects all the custom Modules and Components set to be overridden for the Node.
// TODO(@Bidon15): Pass settings instead of overrides func. Issue #300
func (sets *settings) overrides() fxutil.Option {
return fxutil.OverrideSupply(
&sets.P2PKey,
&sets.Host,
&sets.CoreClient,
)
}