cmd/lncli: accept zpay32 requests in sendpayment command

This commit is contained in:
Olaoluwa Osuntokun 2017-01-02 15:38:00 -08:00
parent 5a9be3f812
commit 9b50df704c
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -546,10 +546,9 @@ var SendPaymentCommand = cli.Command{
Name: "debug_send", Name: "debug_send",
Usage: "use the debug rHash when sending the HTLC", Usage: "use the debug rHash when sending the HTLC",
}, },
cli.BoolFlag{ cli.StringFlag{
Name: "fast, f", Name: "pay_req",
Usage: "skip the HTLC trickle logic, immediately creating a " + Usage: "a zbase32-check encoded payment request to fulfill",
"new commitment",
}, },
}, },
Action: sendPaymentCommand, Action: sendPaymentCommand,
@ -558,31 +557,37 @@ var SendPaymentCommand = cli.Command{
func sendPaymentCommand(ctx *cli.Context) error { func sendPaymentCommand(ctx *cli.Context) error {
client := getClient(ctx) client := getClient(ctx)
destNode, err := hex.DecodeString(ctx.String("dest")) var req *lnrpc.SendRequest
if err != nil { if ctx.String("pay_req") != "" {
return err req = &lnrpc.SendRequest{
} PaymentRequest: ctx.String("pay_req"),
if len(destNode) != 33 { }
return fmt.Errorf("dest node pubkey must be exactly 33 bytes, is "+ } else {
"instead: %v", len(destNode)) destNode, err := hex.DecodeString(ctx.String("dest"))
}
req := &lnrpc.SendRequest{
Dest: destNode,
Amt: int64(ctx.Int("amt")),
FastSend: ctx.Bool("fast"),
}
if !ctx.Bool("debug_send") {
rHash, err := hex.DecodeString(ctx.String("payment_hash"))
if err != nil { if err != nil {
return err return err
} }
if len(rHash) != 32 { if len(destNode) != 33 {
return fmt.Errorf("payment hash must be exactly 32 "+ return fmt.Errorf("dest node pubkey must be exactly 33 bytes, is "+
"bytes, is instead %v", len(rHash)) "instead: %v", len(destNode))
}
req = &lnrpc.SendRequest{
Dest: destNode,
Amt: int64(ctx.Int("amt")),
}
if !ctx.Bool("debug_send") {
rHash, err := hex.DecodeString(ctx.String("payment_hash"))
if err != nil {
return err
}
if len(rHash) != 32 {
return fmt.Errorf("payment hash must be exactly 32 "+
"bytes, is instead %v", len(rHash))
}
req.PaymentHash = rHash
} }
req.PaymentHash = rHash
} }
paymentStream, err := client.SendPayment(context.Background()) paymentStream, err := client.SendPayment(context.Background())