Skip to content

Commit

Permalink
cmd: add lncli addinvoice and addholdinvoice support for passing in p…
Browse files Browse the repository at this point in the history
…rivate_channels array
  • Loading branch information
Crypt-iQ committed Nov 7, 2019
1 parent f420885 commit c40e926
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
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",
},
},
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"

"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",
},
},
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

0 comments on commit c40e926

Please sign in to comment.