lncli+lnrpc: add payment address to sendpayment

This commit is contained in:
yyforyongyu 2021-03-15 16:30:25 +08:00
parent fa4155c126
commit 2dac77200b
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
5 changed files with 815 additions and 763 deletions

View file

@ -147,14 +147,17 @@ var sendPaymentCommand = cli.Command{
If payment isn't manually specified, then only a payment request needs
to be passed using the --pay_req argument.
If the payment *is* manually specified, then all four alternative
arguments need to be specified in order to complete the payment:
* --dest=N
* --amt=A
* --final_cltv_delta=T
* --payment_hash=H
If the payment *is* manually specified, then the following arguments
need to be specified in order to complete the payment:
For invoice with keysend,
--dest=N --amt=A --final_cltv_delta=T --keysend
For invoice without payment address:
--dest=N --amt=A --payment_hash=H --final_cltv_delta=T
For invoice with payment address:
--dest=N --amt=A --payment_hash=H --final_cltv_delta=T --pay_addr=H
`,
ArgsUsage: "dest amt payment_hash final_cltv_delta | --pay_req=[payment request]",
ArgsUsage: "dest amt payment_hash final_cltv_delta pay_addr | --pay_req=[payment request]",
Flags: append(paymentFlags(),
cli.StringFlag{
Name: "dest, d",
@ -173,6 +176,10 @@ var sendPaymentCommand = cli.Command{
Name: "final_cltv_delta",
Usage: "the number of blocks the last hop has to reveal the preimage",
},
cli.StringFlag{
Name: "pay_addr",
Usage: "the payment address of the generated invoice",
},
cli.BoolFlag{
Name: "keysend",
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
@ -330,9 +337,28 @@ func sendPayment(ctx *cli.Context) error {
if err != nil {
return err
}
args = args.Tail()
req.FinalCltvDelta = int32(delta)
}
var payAddr []byte
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 {
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
return sendPaymentRequest(ctx, req)
}

File diff suppressed because it is too large Load diff

View file

@ -708,6 +708,11 @@ message SendRequest {
fallback.
*/
repeated FeatureBit dest_features = 15;
/*
The payment address of the generated invoice.
*/
bytes payment_addr = 16;
}
message SendResponse {

View file

@ -5503,6 +5503,11 @@
"$ref": "#/definitions/lnrpcFeatureBit"
},
"description": "Features assumed to be supported by the final node. All transitive feature\ndependencies must also be set properly. For a given feature bit pair, either\noptional or remote may be set, but not both. If this field is nil or empty,\nthe router will try to load destination features from the graph as a\nfallback."
},
"payment_addr": {
"type": "string",
"format": "byte",
"description": "The payment address of the generated invoice."
}
}
},

View file

@ -4216,6 +4216,12 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
return payIntent, err
}
// Payment address may not be needed by legacy invoices.
if len(rpcPayReq.PaymentAddr) != 0 && len(rpcPayReq.PaymentAddr) != 32 {
return payIntent, errors.New("invalid payment address length")
}
copy(payIntent.paymentAddr[:], rpcPayReq.PaymentAddr)
// Otherwise, If the payment request field was not specified
// (and a custom route wasn't specified), construct the payment
// from the other fields.