cmd/lncli: rename parseArgs to extractPathArgs, return error
This commit is contained in:
parent
ebc9550a1b
commit
dadf13e2a3
@ -69,7 +69,10 @@ func getClient(ctx *cli.Context) (lnrpc.LightningClient, func()) {
|
|||||||
|
|
||||||
func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
|
func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
|
||||||
// First, we'll parse the args from the command.
|
// First, we'll parse the args from the command.
|
||||||
tlsCertPath, macPath := parseArgs(ctx)
|
tlsCertPath, macPath, err := extractPathArgs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Load the specified TLS certificate and build transport credentials
|
// Load the specified TLS certificate and build transport credentials
|
||||||
// with it.
|
// with it.
|
||||||
@ -89,11 +92,13 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
|
|||||||
// Load the specified macaroon file.
|
// Load the specified macaroon file.
|
||||||
macBytes, err := ioutil.ReadFile(macPath)
|
macBytes, err := ioutil.ReadFile(macPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(fmt.Errorf("unable to read macaroon path (check "+
|
||||||
|
"the network setting!): %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
mac := &macaroon.Macaroon{}
|
mac := &macaroon.Macaroon{}
|
||||||
if err = mac.UnmarshalBinary(macBytes); err != nil {
|
if err = mac.UnmarshalBinary(macBytes); err != nil {
|
||||||
fatal(err)
|
fatal(fmt.Errorf("unable to decode macaroon: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
macConstraints := []macaroons.Constraint{
|
macConstraints := []macaroons.Constraint{
|
||||||
@ -136,14 +141,15 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
|
|||||||
)
|
)
|
||||||
conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...)
|
conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(fmt.Errorf("unable to connect to RPC server: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseArgs parses the TLS certificate and macaroon paths from the command.
|
// extractPathArgs parses the TLS certificate and macaroon paths from the
|
||||||
func parseArgs(ctx *cli.Context) (string, string) {
|
// command.
|
||||||
|
func extractPathArgs(ctx *cli.Context) (string, string, error) {
|
||||||
// We'll start off by parsing the active chain and network. These are
|
// We'll start off by parsing the active chain and network. These are
|
||||||
// needed to determine the correct path to the macaroon when not
|
// needed to determine the correct path to the macaroon when not
|
||||||
// specified.
|
// specified.
|
||||||
@ -151,16 +157,14 @@ func parseArgs(ctx *cli.Context) (string, string) {
|
|||||||
switch chain {
|
switch chain {
|
||||||
case "bitcoin", "litecoin":
|
case "bitcoin", "litecoin":
|
||||||
default:
|
default:
|
||||||
err := fmt.Errorf("unknown chain: %v", chain)
|
return "", "", fmt.Errorf("unknown chain: %v", chain)
|
||||||
fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network := strings.ToLower(ctx.GlobalString("network"))
|
network := strings.ToLower(ctx.GlobalString("network"))
|
||||||
switch network {
|
switch network {
|
||||||
case "mainnet", "testnet", "regtest", "simnet":
|
case "mainnet", "testnet", "regtest", "simnet":
|
||||||
default:
|
default:
|
||||||
err := fmt.Errorf("unknown network: %v", network)
|
return "", "", fmt.Errorf("unknown network: %v", network)
|
||||||
fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll now fetch the lnddir so we can make a decision on how to
|
// We'll now fetch the lnddir so we can make a decision on how to
|
||||||
@ -195,7 +199,7 @@ func parseArgs(ctx *cli.Context) (string, string) {
|
|||||||
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
|
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tlsCertPath, macPath
|
return tlsCertPath, macPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user