Skip to content

Commit

Permalink
lncli: add chan_point flag to closechannel command
Browse files Browse the repository at this point in the history
  • Loading branch information
mads krogh committed Jan 13, 2022
1 parent fd63301 commit 807bc06
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
defaultUtxoMinConf = 1
)

var errBadChanPoint = errors.New("expecting chan_point to be in format of: " +
"txid:index")

func getContext() context.Context {
shutdownInterceptor, err := signal.Intercept()
if err != nil {
Expand Down Expand Up @@ -719,6 +722,12 @@ var closeChannelCommand = cli.Command{
Usage: "the output index for the funding output of the funding " +
"transaction",
},
cli.StringFlag{
Name: "chan_point",
Usage: "(optional) the channel point. If set, " +
"funding_txid and output_index flags and " +
"positional arguments will be ignored",
},
cli.BoolFlag{
Name: "force",
Usage: "attempt an uncooperative closure",
Expand Down Expand Up @@ -1183,10 +1192,19 @@ func abandonChannel(ctx *cli.Context) error {
// line. Both named options as well as unnamed parameters are supported.
func parseChannelPoint(ctx *cli.Context) (*lnrpc.ChannelPoint, error) {
channelPoint := &lnrpc.ChannelPoint{}
var err error

args := ctx.Args()

switch {
case ctx.IsSet("chan_point"):
channelPoint, err = parseChanPoint(ctx.String("chan_point"))
if err != nil {
return nil, fmt.Errorf("unable to parse chan_point: "+
"%v", err)
}
return channelPoint, nil

case ctx.IsSet("funding_txid"):
channelPoint.FundingTxid = &lnrpc.ChannelPoint_FundingTxidStr{
FundingTxidStr: ctx.String("funding_txid"),
Expand Down Expand Up @@ -1984,9 +2002,8 @@ var updateChannelPolicyCommand = cli.Command{

func parseChanPoint(s string) (*lnrpc.ChannelPoint, error) {
split := strings.Split(s, ":")
if len(split) != 2 {
return nil, fmt.Errorf("expecting chan_point to be in format of: " +
"txid:index")
if len(split) != 2 || len(split[0]) == 0 || len(split[1]) == 0 {
return nil, errBadChanPoint
}

index, err := strconv.ParseInt(split[1], 10, 32)
Expand Down Expand Up @@ -2077,7 +2094,7 @@ func updateChannelPolicy(ctx *cli.Context) error {
if chanPointStr != "" {
chanPoint, err = parseChanPoint(chanPointStr)
if err != nil {
return fmt.Errorf("unable to parse chan point: %v", err)
return fmt.Errorf("unable to parse chan_point: %v", err)
}
}

Expand Down Expand Up @@ -2227,7 +2244,7 @@ func exportChanBackup(ctx *cli.Context) error {
if chanPointStr != "" {
chanPointRPC, err := parseChanPoint(chanPointStr)
if err != nil {
return err
return fmt.Errorf("unable to parse chan_point: %v", err)
}

chanBackup, err := client.ExportChannelBackup(
Expand Down

0 comments on commit 807bc06

Please sign in to comment.