Merge pull request #5253 from cfromknecht/amp-invoice
Support paying AMP invoices via SendPaymentV2
This commit is contained in:
30 files changed
+1528
-1023
No files matched your search
@@ -66,6 +66,11 @@ var addInvoiceCommand = cli.Command{
|
||||
"private channels in order to assist the " +
|
||||
"payer in reaching you",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "amp",
|
||||
Usage: "creates an AMP invoice. If true, preimage " +
|
||||
"should not be set.",
|
||||
},
|
||||
},
|
||||
Action: actionDecorator(addInvoice),
|
||||
}
|
||||
@@ -119,6 +124,7 @@ func addInvoice(ctx *cli.Context) error {
|
||||
FallbackAddr: ctx.String("fallback_addr"),
|
||||
Expiry: ctx.Int64("expiry"),
|
||||
Private: ctx.Bool("private"),
|
||||
IsAmp: ctx.Bool("amp"),
|
||||
}
|
||||
|
||||
resp, err := client.AddInvoice(ctxc, invoice)
|
||||
|
||||
+15
-4
@@ -87,6 +87,12 @@ var (
|
||||
"payment splitting is required to attempt a payment, " +
|
||||
"specified in milli-satoshis",
|
||||
}
|
||||
|
||||
ampFlag = cli.BoolFlag{
|
||||
Name: "amp",
|
||||
Usage: "if set to true, then AMP will be used to complete the " +
|
||||
"payment",
|
||||
}
|
||||
)
|
||||
|
||||
// paymentFlags returns common flags for sendpayment and payinvoice.
|
||||
@@ -131,7 +137,7 @@ func paymentFlags() []cli.Flag {
|
||||
Usage: "allow sending a circular payment to self",
|
||||
},
|
||||
dataFlag, inflightUpdatesFlag, maxPartsFlag, jsonFlag,
|
||||
maxShardSizeSatFlag, maxShardSizeMsatFlag,
|
||||
maxShardSizeSatFlag, maxShardSizeMsatFlag, ampFlag,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,11 +293,16 @@ func sendPayment(ctx *cli.Context) error {
|
||||
Dest: destNode,
|
||||
Amt: amount,
|
||||
DestCustomRecords: make(map[uint64][]byte),
|
||||
Amp: ctx.Bool(ampFlag.Name),
|
||||
}
|
||||
|
||||
var rHash []byte
|
||||
|
||||
if ctx.Bool("keysend") {
|
||||
switch {
|
||||
case ctx.Bool("keysend") && ctx.Bool(ampFlag.Name):
|
||||
return errors.New("either keysend or amp may be set, but not both")
|
||||
|
||||
case ctx.Bool("keysend"):
|
||||
if ctx.IsSet("payment_hash") {
|
||||
return errors.New("cannot set payment hash when using " +
|
||||
"keysend")
|
||||
@@ -308,7 +319,7 @@ func sendPayment(ctx *cli.Context) error {
|
||||
|
||||
hash := preimage.Hash()
|
||||
rHash = hash[:]
|
||||
} else {
|
||||
case !ctx.Bool(ampFlag.Name):
|
||||
switch {
|
||||
case ctx.IsSet("payment_hash"):
|
||||
rHash, err = hex.DecodeString(ctx.String("payment_hash"))
|
||||
@@ -323,7 +334,7 @@ func sendPayment(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rHash) != 32 {
|
||||
if !req.Amp && len(rHash) != 32 {
|
||||
return fmt.Errorf("payment hash must be exactly 32 "+
|
||||
"bytes, is instead %v", len(rHash))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user