@@ -2,6 +2,7 @@ package local
2
2
3
3
import (
4
4
"encoding/base64"
5
+ "encoding/json"
5
6
"fmt"
6
7
"math/rand"
7
8
"net"
@@ -45,40 +46,32 @@ func writeFiles(networkID uint32, genesis []byte, nodeRootDir string, nodeConfig
45
46
}
46
47
files := []file {
47
48
{
48
- flagValue : filepath .Join (nodeRootDir , stakingKeyFileName ),
49
- path : filepath .Join (nodeRootDir , stakingKeyFileName ),
49
+ flagValue : filepath .Join (nodeRootDir , "staking" , stakingKeyFileName ),
50
+ path : filepath .Join (nodeRootDir , "staking" , stakingKeyFileName ),
50
51
pathKey : config .StakingTLSKeyPathKey ,
51
52
contents : []byte (nodeConfig .StakingKey ),
52
53
},
53
54
{
54
- flagValue : filepath .Join (nodeRootDir , stakingCertFileName ),
55
- path : filepath .Join (nodeRootDir , stakingCertFileName ),
55
+ flagValue : filepath .Join (nodeRootDir , "staking" , stakingCertFileName ),
56
+ path : filepath .Join (nodeRootDir , "staking" , stakingCertFileName ),
56
57
pathKey : config .StakingCertPathKey ,
57
58
contents : []byte (nodeConfig .StakingCert ),
58
59
},
59
60
{
60
- flagValue : filepath .Join (nodeRootDir , stakingSigningKeyFileName ),
61
- path : filepath .Join (nodeRootDir , stakingSigningKeyFileName ),
61
+ flagValue : filepath .Join (nodeRootDir , "staking" , stakingSigningKeyFileName ),
62
+ path : filepath .Join (nodeRootDir , "staking" , stakingSigningKeyFileName ),
62
63
pathKey : config .StakingSignerKeyPathKey ,
63
64
contents : decodedStakingSigningKey ,
64
65
},
65
66
}
66
67
if networkID != constants .LocalID {
67
68
files = append (files , file {
68
- flagValue : filepath .Join (nodeRootDir , genesisFileName ),
69
- path : filepath .Join (nodeRootDir , genesisFileName ),
69
+ flagValue : filepath .Join (nodeRootDir , "configs" , genesisFileName ),
70
+ path : filepath .Join (nodeRootDir , "configs" , genesisFileName ),
70
71
pathKey : config .GenesisFileKey ,
71
72
contents : genesis ,
72
73
})
73
74
}
74
- if len (nodeConfig .ConfigFile ) != 0 {
75
- files = append (files , file {
76
- flagValue : filepath .Join (nodeRootDir , configFileName ),
77
- path : filepath .Join (nodeRootDir , configFileName ),
78
- pathKey : config .ConfigFileKey ,
79
- contents : []byte (nodeConfig .ConfigFile ),
80
- })
81
- }
82
75
flags := map [string ]string {}
83
76
for _ , f := range files {
84
77
flags [f .pathKey ] = f .flagValue
@@ -122,6 +115,31 @@ func writeFiles(networkID uint32, genesis []byte, nodeRootDir string, nodeConfig
122
115
return flags , nil
123
116
}
124
117
118
+ func writeConfigFile (nodeRootDir string , nodeConfig * node.Config , flags map [string ]string ) (string , error ) {
119
+ if len (nodeConfig .ConfigFile ) != 0 {
120
+ newFlags := map [string ]interface {}{}
121
+ if err := json .Unmarshal ([]byte (nodeConfig .ConfigFile ), & newFlags ); err != nil {
122
+ return "" , err
123
+ }
124
+ for k , vI := range newFlags {
125
+ v , ok := vI .(string )
126
+ if ! ok {
127
+ return "" , fmt .Errorf ("expected string for key %q, found %T" , k , vI )
128
+ }
129
+ flags [k ] = v
130
+ }
131
+ }
132
+ configFileBytes , err := json .MarshalIndent (flags , "" , " " )
133
+ if err != nil {
134
+ return "" , err
135
+ }
136
+ configFilePath := filepath .Join (nodeRootDir , "configs" , configFileName )
137
+ if err := createFileAndWrite (configFilePath , configFileBytes ); err != nil {
138
+ return "" , err
139
+ }
140
+ return configFilePath , nil
141
+ }
142
+
125
143
// getConfigEntry returns an entry in the config file if it is found, otherwise returns the default value
126
144
func getConfigEntry (
127
145
nodeConfigFlags map [string ]interface {},
0 commit comments