lncli: add trackpayment command

This commit is contained in:
Joost Jager 2020-03-30 12:55:10 +02:00
parent acefb64207
commit 37849194f4
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 53 additions and 0 deletions

@ -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{ var payInvoiceCommand = cli.Command{
Name: "payinvoice", Name: "payinvoice",
Category: "Payments", Category: "Payments",

@ -300,6 +300,7 @@ func main() {
verifyChanBackupCommand, verifyChanBackupCommand,
restoreChanBackupCommand, restoreChanBackupCommand,
bakeMacaroonCommand, bakeMacaroonCommand,
trackPaymentCommand,
} }
// Add any extra commands determined by build flags. // Add any extra commands determined by build flags.