From 37849194f452e46ec1e0b6e53a4de140df8b1c46 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 30 Mar 2020 12:55:10 +0200 Subject: [PATCH] lncli: add trackpayment command --- cmd/lncli/cmd_pay.go | 52 ++++++++++++++++++++++++++++++++++++++++++++ cmd/lncli/main.go | 1 + 2 files changed, 53 insertions(+) diff --git a/cmd/lncli/cmd_pay.go b/cmd/lncli/cmd_pay.go index 55741bc1..3923bee7 100644 --- a/cmd/lncli/cmd_pay.go +++ b/cmd/lncli/cmd_pay.go @@ -408,6 +408,58 @@ func sendPaymentRequest(ctx *cli.Context, } } +var trackPaymentCommand = cli.Command{ + Name: "trackpayment", + Category: "Payments", + Usage: "Track progress of an existing payment.", + Description: ` + Pick up monitoring the progression of a previously initiated payment + specified by the hash argument. + `, + ArgsUsage: "hash", + Action: actionDecorator(trackPayment), +} + +func trackPayment(ctx *cli.Context) error { + args := ctx.Args() + + conn := getClientConn(ctx, false) + defer conn.Close() + + client := routerrpc.NewRouterClient(conn) + + if !args.Present() { + return fmt.Errorf("hash argument missing") + } + + hash, err := hex.DecodeString(args.First()) + if err != nil { + return err + } + + req := &routerrpc.TrackPaymentRequest{ + PaymentHash: hash, + } + + stream, err := client.TrackPayment(context.Background(), req) + if err != nil { + return err + } + + for { + status, err := stream.Recv() + if err != nil { + return err + } + + printRespJSON(status) + + if status.State != routerrpc.PaymentState_IN_FLIGHT { + return nil + } + } +} + var payInvoiceCommand = cli.Command{ Name: "payinvoice", Category: "Payments", diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index e8170c59..6f064080 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -300,6 +300,7 @@ func main() { verifyChanBackupCommand, restoreChanBackupCommand, bakeMacaroonCommand, + trackPaymentCommand, } // Add any extra commands determined by build flags.