Skip to content

Commit

Permalink
lncli: add trackpayment command
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Mar 31, 2020
1 parent acefb64 commit 3784919
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cmd/lncli/cmd_pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/lncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func main() {
verifyChanBackupCommand,
restoreChanBackupCommand,
bakeMacaroonCommand,
trackPaymentCommand,
}

// Add any extra commands determined by build flags.
Expand Down

0 comments on commit 3784919

Please sign in to comment.