Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoicesrpc: specify private hops for addinvoice, addholdinvoice #3022

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2595,12 +2595,17 @@ var addInvoiceCommand = cli.Command{
"specified an expiry of 3600 seconds (1 hour) " +
"is implied.",
},
cli.BoolTFlag{
cli.BoolFlag{
Name: "private",
Usage: "encode routing hints in the invoice with " +
"private channels in order to assist the " +
"payer in reaching you",
},
cli.StringFlag{
Name: "private_channels",
Usage: "a comma-separated list of private channel ids " +
"to use as hop hints",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the simpler format --private_hops 100,200,300?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

},
},
Action: actionDecorator(addInvoice),
}
Expand Down Expand Up @@ -2651,6 +2656,20 @@ func addInvoice(ctx *cli.Context) error {
return fmt.Errorf("unable to parse receipt: %v", err)
}

var privateChans []uint64
if ctx.IsSet("private_channels") {
// Parse the private channels into an array of uint64
privChanStrings := ctx.String("private_channels")
for _, chanString := range strings.Split(privChanStrings, ",") {
privChan, err := strconv.Atoi(chanString)
if err != nil {
return fmt.Errorf("unable to parse private channel: %v", err)
}

privateChans = append(privateChans, uint64(privChan))
}
}

invoice := &lnrpc.Invoice{
Memo: ctx.String("memo"),
Receipt: receipt,
Expand All @@ -2660,6 +2679,7 @@ func addInvoice(ctx *cli.Context) error {
FallbackAddr: ctx.String("fallback_addr"),
Expiry: ctx.Int64("expiry"),
Private: ctx.Bool("private"),
PrivateChannels: privateChans,
}

resp, err := client.AddInvoice(context.Background(), invoice)
Expand Down
23 changes: 22 additions & 1 deletion cmd/lncli/invoicesrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"encoding/hex"
"fmt"
"strings"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well blitz this unnecessary newline while you're here?

"strconv"

Expand Down Expand Up @@ -179,12 +180,17 @@ var addHoldInvoiceCommand = cli.Command{
"specified, an expiry of 3600 seconds (1 hour) " +
"is implied.",
},
cli.BoolTFlag{
cli.BoolFlag{
Name: "private",
Usage: "encode routing hints in the invoice with " +
"private channels in order to assist the " +
"payer in reaching you",
},
cli.StringFlag{
Name: "private_channels",
Usage: "a comma-separated list of private channel ids " +
"to use as hop hints",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can do some reuse here. See commands.go, paymentFlags().

},
Action: actionDecorator(addHoldInvoice),
}
Expand Down Expand Up @@ -232,6 +238,20 @@ func addHoldInvoice(ctx *cli.Context) error {
return fmt.Errorf("unable to parse description_hash: %v", err)
}

var privateChans []uint64
if ctx.IsSet("private_channels") {
// Parse the private channels into an array of uint64
privChanStrings := ctx.String("private_channels")
for _, chanString := range strings.Split(privChanStrings, ",") {
privChan, err := strconv.Atoi(chanString)
if err != nil {
return fmt.Errorf("unable to parse private channel: %v", err)
}

privateChans = append(privateChans, uint64(privChan))
}
}

invoice := &invoicesrpc.AddHoldInvoiceRequest{
Memo: ctx.String("memo"),
Hash: hash,
Expand All @@ -240,6 +260,7 @@ func addHoldInvoice(ctx *cli.Context) error {
FallbackAddr: ctx.String("fallback_addr"),
Expiry: ctx.Int64("expiry"),
Private: ctx.Bool("private"),
PrivateChannels: privateChans,
}

resp, err := client.AddHoldInvoice(context.Background(), invoice)
Expand Down