@@ -11,6 +11,7 @@ import (
11
11
"syscall"
12
12
"time"
13
13
14
+ "github.com/btcsuite/btcd/rpcclient"
14
15
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
15
16
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
16
17
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -45,6 +46,10 @@ var rootCmd = &cobra.Command{
45
46
LogLevel : viper .GetUint64 ("log-level" ),
46
47
LogFile : viper .GetString ("log-file" ),
47
48
ZcashConfPath : viper .GetString ("zcash-conf-path" ),
49
+ RPCUser : viper .GetString ("rpcuser" ),
50
+ RPCPassword : viper .GetString ("rpcpassword" ),
51
+ RPCHost : viper .GetString ("rpchost" ),
52
+ RPCPort : viper .GetString ("rpcport" ),
48
53
NoTLSVeryInsecure : viper .GetBool ("no-tls-very-insecure" ),
49
54
GenCertVeryInsecure : viper .GetBool ("gen-cert-very-insecure" ),
50
55
DataDir : viper .GetString ("data-dir" ),
@@ -61,7 +66,7 @@ var rootCmd = &cobra.Command{
61
66
if ! fileExists (opts .LogFile ) {
62
67
os .OpenFile (opts .LogFile , os .O_RDWR | os .O_CREATE | os .O_EXCL , 0666 )
63
68
}
64
- if ! opts .Darkside {
69
+ if ! opts .Darkside && ( opts . RPCUser == "" || opts . RPCPassword == "" || opts . RPCHost == "" || opts . RPCPort == "" ) {
65
70
filesThatShouldExist = append (filesThatShouldExist , opts .ZcashConfPath )
66
71
}
67
72
if ! opts .NoTLSVeryInsecure && ! opts .GenCertVeryInsecure {
@@ -176,10 +181,16 @@ func startServer(opts *common.Options) error {
176
181
var blockHeight int
177
182
var chainName string
178
183
var branchID string
184
+ var rpcClient * rpcclient.Client
185
+ var err error
179
186
if opts .Darkside {
180
187
chainName = "darkside"
181
188
} else {
182
- rpcClient , err := frontend .NewZRPCFromConf (opts .ZcashConfPath )
189
+ if opts .RPCUser != "" && opts .RPCPassword != "" && opts .RPCHost != "" && opts .RPCPort != "" {
190
+ rpcClient , err = frontend .NewZRPCFromFlags (opts )
191
+ } else {
192
+ rpcClient , err = frontend .NewZRPCFromConf (opts .ZcashConfPath )
193
+ }
183
194
if err != nil {
184
195
common .Log .WithFields (logrus.Fields {
185
196
"error" : err ,
@@ -287,6 +298,10 @@ func init() {
287
298
rootCmd .Flags ().Int ("log-level" , int (logrus .InfoLevel ), "log level (logrus 1-7)" )
288
299
rootCmd .Flags ().String ("log-file" , "./server.log" , "log file to write to" )
289
300
rootCmd .Flags ().String ("zcash-conf-path" , "./zcash.conf" , "conf file to pull RPC creds from" )
301
+ rootCmd .Flags ().String ("rpcuser" , "" , "RPC user name" )
302
+ rootCmd .Flags ().String ("rpcpassword" , "" , "RPC password" )
303
+ rootCmd .Flags ().String ("rpchost" , "" , "RPC host" )
304
+ rootCmd .Flags ().String ("rpcport" , "" , "RPC host port" )
290
305
rootCmd .Flags ().Bool ("no-tls-very-insecure" , false , "run without the required TLS certificate, only for debugging, DO NOT use in production" )
291
306
rootCmd .Flags ().Bool ("gen-cert-very-insecure" , false , "run with self-signed TLS certificate, only for debugging, DO NOT use in production" )
292
307
rootCmd .Flags ().Bool ("redownload" , false , "re-fetch all blocks from zcashd; reinitialize local cache files" )
@@ -308,6 +323,10 @@ func init() {
308
323
viper .SetDefault ("log-file" , "./server.log" )
309
324
viper .BindPFlag ("zcash-conf-path" , rootCmd .Flags ().Lookup ("zcash-conf-path" ))
310
325
viper .SetDefault ("zcash-conf-path" , "./zcash.conf" )
326
+ viper .BindPFlag ("rpcuser" , rootCmd .Flags ().Lookup ("rpcuser" ))
327
+ viper .BindPFlag ("rpcpassword" , rootCmd .Flags ().Lookup ("rpcpassword" ))
328
+ viper .BindPFlag ("rpchost" , rootCmd .Flags ().Lookup ("rpchost" ))
329
+ viper .BindPFlag ("rpcport" , rootCmd .Flags ().Lookup ("rpcport" ))
311
330
viper .BindPFlag ("no-tls-very-insecure" , rootCmd .Flags ().Lookup ("no-tls-very-insecure" ))
312
331
viper .SetDefault ("no-tls-very-insecure" , false )
313
332
viper .BindPFlag ("gen-cert-very-insecure" , rootCmd .Flags ().Lookup ("gen-cert-very-insecure" ))
0 commit comments