From 2926988710ef4b6cfd6271ebfb0d5a66edb83cb9 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 12 Jul 2016 17:47:24 -0700 Subject: [PATCH] cmd/lncli: implement one-off HTLC payments --- cmd/lncli/commands.go | 61 +++++++++++++++++++++++++++++++++++++++++++ cmd/lncli/main.go | 1 + 2 files changed, 62 insertions(+) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index b32b0615..22117c6f 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/hex" "encoding/json" "fmt" "io" @@ -437,3 +438,63 @@ func pendingChannels(ctx *cli.Context) error { return nil } + +var SendPaymentCommand = cli.Command{ + Name: "sendpayment", + Description: "send a payment over lightning", + Usage: "sendpayment --dest=[node_id] --amt=[in_satoshis]", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "dest, d", + Usage: "lightning address of the payment recipient", + }, + cli.IntFlag{ // TODO(roasbeef): float64? + Name: "amt, a", + Usage: "number of satoshis to send", + }, + cli.StringFlag{ + Name: "payment_hash, r", + Usage: "the hash to use within the payment's HTLC", + }, + cli.BoolFlag{ + Name: "fast, f", + Usage: "skip the HTLC trickle logic, immediately creating a " + + "new commitment", + }, + }, + Action: sendPaymentCommand, +} + +func sendPaymentCommand(ctx *cli.Context) error { + client := getClient(ctx) + + destAddr, err := hex.DecodeString(ctx.String("dest")) + if err != nil { + return err + } + // TODO(roasbeef): remove debug payment hash + req := &lnrpc.SendRequest{ + Dest: destAddr, + Amt: int64(ctx.Int("amt")), + FastSend: ctx.Bool("fast"), + } + + paymentStream, err := client.SendPayment(context.Background()) + if err != nil { + return err + } + + if err := paymentStream.Send(req); err != nil { + return err + } + paymentStream.CloseSend() + + resp, err := paymentStream.Recv() + if err != nil { + return err + } + + printRespJson(resp) + + return nil +} diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 5bee7050..4ba2c6b1 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -59,6 +59,7 @@ func main() { ShellCommand, GetInfoCommand, PendingChannelsCommand, + SendPaymentCommand, } if err := app.Run(os.Args); err != nil {