lncli: add a convenience command for paying an invoice

Fixes #324.
This commit is contained in:
rajeshnair2k 2017-10-27 18:39:54 -04:00 committed by Olaoluwa Osuntokun
parent a13ad0a339
commit 0e07699550
2 changed files with 43 additions and 4 deletions

View File

@ -834,16 +834,13 @@ var sendPaymentCommand = cli.Command{
},
cli.StringFlag{
Name: "pay_req",
Usage: "a bech32 encoded payment request to fulfill",
Usage: "a zpay32 encoded payment request to fulfill",
},
},
Action: sendPayment,
}
func sendPayment(ctx *cli.Context) error {
client, cleanUp := getClient(ctx)
defer cleanUp()
// Show command help if no arguments provieded
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
cli.ShowCommandHelp(ctx, "sendpayment")
@ -922,6 +919,13 @@ func sendPayment(ctx *cli.Context) error {
}
}
return sendPaymentRequest(ctx, req)
}
func sendPaymentRequest(ctx *cli.Context, req *lnrpc.SendRequest) error {
client, cleanUp := getClient(ctx)
defer cleanUp()
paymentStream, err := client.SendPayment(context.Background())
if err != nil {
return err
@ -951,6 +955,40 @@ func sendPayment(ctx *cli.Context) error {
return nil
}
var payInvoiceCommand = cli.Command{
Name: "payinvoice",
Usage: "pay an invoice over lightning",
ArgsUsage: "pay_req",
Flags: []cli.Flag{
cli.StringFlag{
Name: "pay_req",
Usage: "a zpay32 encoded payment request to fulfill",
},
},
Action: payInvoice,
}
func payInvoice(ctx *cli.Context) error {
args := ctx.Args()
var payReq string
switch {
case ctx.IsSet("pay_req"):
payReq = ctx.String("pay_req")
case args.Present():
payReq = args.First()
default:
return fmt.Errorf("pay_req argument missing")
}
req := &lnrpc.SendRequest{
PaymentRequest: payReq,
}
return sendPaymentRequest(ctx, req)
}
var addInvoiceCommand = cli.Command{
Name: "addinvoice",
Usage: "add a new invoice.",

View File

@ -171,6 +171,7 @@ func main() {
getInfoCommand,
pendingChannelsCommand,
sendPaymentCommand,
payInvoiceCommand,
addInvoiceCommand,
lookupInvoiceCommand,
listInvoicesCommand,