cmd/lncli: always parse the pay_addr field for sendpayment
In this commit, we fix a bug that would cause attempts to re-use an AMP invoice to fail. Without this commit, we would only attempt to parse the payment addr if no invoice was specified, so a user manually specifying the pubkey of the detonation. The fix is straight forward: always parse the `pay_addr` field as the user may be attempting to re-use an AMP invoice w/o open coding each of the sections.
This commit is contained in:
1 file changed
+39
-15
+39
-15
@@ -235,6 +235,31 @@ func confirmPayReq(resp *lnrpc.PayReq, amt, feeLimit int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePayAddr(ctx *cli.Context) ([]byte, error) {
|
||||||
|
var (
|
||||||
|
payAddr []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
switch {
|
||||||
|
case ctx.IsSet("pay_addr"):
|
||||||
|
payAddr, err = hex.DecodeString(ctx.String("pay_addr"))
|
||||||
|
case ctx.Args().Present():
|
||||||
|
payAddr, err = hex.DecodeString(ctx.Args().First())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// payAddr may be not required if it's a legacy invoice.
|
||||||
|
if len(payAddr) != 0 && len(payAddr) != 32 {
|
||||||
|
return nil, fmt.Errorf("payment addr must be exactly 32 "+
|
||||||
|
"bytes, is instead %v", len(payAddr))
|
||||||
|
}
|
||||||
|
|
||||||
|
return payAddr, nil
|
||||||
|
}
|
||||||
|
|
||||||
func sendPayment(ctx *cli.Context) error {
|
func sendPayment(ctx *cli.Context) error {
|
||||||
// Show command help if no arguments provided
|
// Show command help if no arguments provided
|
||||||
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
|
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
|
||||||
@@ -242,6 +267,8 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args := ctx.Args()
|
||||||
|
|
||||||
// If a payment request was provided, we can exit early since all of the
|
// If a payment request was provided, we can exit early since all of the
|
||||||
// details of the payment are encoded within the request.
|
// details of the payment are encoded within the request.
|
||||||
if ctx.IsSet("pay_req") {
|
if ctx.IsSet("pay_req") {
|
||||||
@@ -250,6 +277,16 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
Amt: ctx.Int64("amt"),
|
Amt: ctx.Int64("amt"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We'll attempt to parse a payment address as well, given that
|
||||||
|
// if the user is using an AMP invoice, then they may be trying
|
||||||
|
// to specify that value manually.
|
||||||
|
payAddr, err := parsePayAddr(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.PaymentAddr = payAddr
|
||||||
|
|
||||||
return sendPaymentRequest(ctx, req)
|
return sendPaymentRequest(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,8 +296,6 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
args := ctx.Args()
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet("dest"):
|
case ctx.IsSet("dest"):
|
||||||
destNode, err = hex.DecodeString(ctx.String("dest"))
|
destNode, err = hex.DecodeString(ctx.String("dest"))
|
||||||
@@ -352,22 +387,11 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
req.FinalCltvDelta = int32(delta)
|
req.FinalCltvDelta = int32(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
var payAddr []byte
|
payAddr, err := parsePayAddr(ctx)
|
||||||
switch {
|
|
||||||
case ctx.IsSet("pay_addr"):
|
|
||||||
payAddr, err = hex.DecodeString(ctx.String("pay_addr"))
|
|
||||||
case args.Present():
|
|
||||||
payAddr, err = hex.DecodeString(args.First())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// payAddr may be not required if it's a legacy invoice.
|
|
||||||
if len(payAddr) != 0 && len(payAddr) != 32 {
|
|
||||||
return fmt.Errorf("payment addr must be exactly 32 "+
|
|
||||||
"bytes, is instead %v", len(payAddr))
|
|
||||||
}
|
|
||||||
req.PaymentAddr = payAddr
|
req.PaymentAddr = payAddr
|
||||||
|
|
||||||
return sendPaymentRequest(ctx, req)
|
return sendPaymentRequest(ctx, req)
|
||||||
|
|||||||
Reference in new issue
Block a user