forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
97 lines (86 loc) · 3.42 KB
/
config.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package config
import (
"context"
"fmt"
"github.com/hyperledger/burrow/config/source"
"github.com/hyperledger/burrow/consensus/tendermint"
"github.com/hyperledger/burrow/core"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/execution"
"github.com/hyperledger/burrow/genesis"
"github.com/hyperledger/burrow/keys"
"github.com/hyperledger/burrow/logging/lifecycle"
logging_config "github.com/hyperledger/burrow/logging/logconfig"
"github.com/hyperledger/burrow/rpc"
)
const DefaultBurrowConfigTOMLFileName = "burrow.toml"
const DefaultBurrowConfigEnvironmentVariable = "BURROW_CONFIG_JSON"
const DefaultGenesisDocJSONFileName = "genesis.json"
type BurrowConfig struct {
// Set on startup
ValidatorAddress *crypto.Address `json:",omitempty" toml:",omitempty"`
ValidatorPassphrase *string `json:",omitempty" toml:",omitempty"`
// From config file
GenesisDoc *genesis.GenesisDoc `json:",omitempty" toml:",omitempty"`
Tendermint *tendermint.BurrowTendermintConfig `json:",omitempty" toml:",omitempty"`
Execution *execution.ExecutionConfig `json:",omitempty" toml:",omitempty"`
Keys *keys.KeysConfig `json:",omitempty" toml:",omitempty"`
RPC *rpc.RPCConfig `json:",omitempty" toml:",omitempty"`
Logging *logging_config.LoggingConfig `json:",omitempty" toml:",omitempty"`
}
func DefaultBurrowConfig() *BurrowConfig {
return &BurrowConfig{
Tendermint: tendermint.DefaultBurrowTendermintConfig(),
Keys: keys.DefaultKeysConfig(),
RPC: rpc.DefaultRPCConfig(),
Execution: execution.DefaultExecutionConfig(),
Logging: logging_config.DefaultNodeLoggingConfig(),
}
}
func (conf *BurrowConfig) Kernel(ctx context.Context, restoreDump string) (*core.Kernel, error) {
if conf.GenesisDoc == nil {
return nil, fmt.Errorf("no GenesisDoc defined in config, cannot make Kernel")
}
if conf.ValidatorAddress == nil {
return nil, fmt.Errorf("no validator address provided, cannot make Kernel")
}
logger, err := lifecycle.NewLoggerFromLoggingConfig(conf.Logging)
if err != nil {
return nil, fmt.Errorf("could not generate logger from logging config: %v", err)
}
var keyClient keys.KeyClient
var keyStore *keys.KeyStore
if conf.Keys.RemoteAddress != "" {
keyClient, err = keys.NewRemoteKeyClient(conf.Keys.RemoteAddress, logger)
if err != nil {
return nil, err
}
} else {
keyStore = keys.NewKeyStore(conf.Keys.KeysDirectory, conf.Keys.AllowBadFilePermissions)
keyClient = keys.NewLocalKeyClient(keyStore, logger)
}
val, err := keys.AddressableSigner(keyClient, *conf.ValidatorAddress)
if err != nil {
return nil, fmt.Errorf("could not get validator addressable from keys client: %v", err)
}
signer, err := keys.AddressableSigner(keyClient, val.GetAddress())
if err != nil {
return nil, err
}
privValidator := tendermint.NewPrivValidatorMemory(val, signer)
var exeOptions []execution.ExecutionOption
if conf.Execution != nil {
exeOptions, err = conf.Execution.ExecutionOptions()
if err != nil {
return nil, err
}
}
return core.NewKernel(ctx, keyClient, privValidator, conf.GenesisDoc, conf.Tendermint.TendermintConfig(), conf.RPC,
conf.Keys, keyStore, exeOptions, conf.Tendermint.DefaultAuthorizedPeersProvider(), restoreDump, logger)
}
func (conf *BurrowConfig) JSONString() string {
return source.JSONString(conf)
}
func (conf *BurrowConfig) TOMLString() string {
return source.TOMLString(conf)
}