github.com/decred/dcrlnd@v0.7.6/cmd/dcrlncli/cmd_update_chan_status.go (about)

     1  package main
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/decred/dcrlnd/lnrpc/routerrpc"
     7  	"github.com/urfave/cli"
     8  )
     9  
    10  var updateChanStatusCommand = cli.Command{
    11  	Name:     "updatechanstatus",
    12  	Category: "Channels",
    13  	Usage:    "Set the status of an existing channel on the network.",
    14  	Description: `
    15  	Set the status of an existing channel on the network. The actions can
    16  	be "enable", "disable", or "auto". If the action changes the status, a
    17  	message will be broadcast over the network.
    18  
    19  	Note that enabling / disabling a channel using this command ONLY affects
    20  	what's advertised over the network. For example, disabling a channel
    21  	using this command does not close it.
    22  
    23  	If a channel is manually disabled, automatic / background requests to
    24  	re-enable the channel will be ignored. However, if a channel is
    25  	manually enabled, automatic / background requests to disable the
    26  	channel will succeed (such requests are usually made on channel close
    27  	or when the peer is down).
    28  
    29  	The "auto" action restores automatic channel state management. Per
    30  	the behavior described above, it's only needed to undo the effect of
    31  	a prior "disable" action, and will be a no-op otherwise.`,
    32  	ArgsUsage: "funding_txid [output_index] action",
    33  	Flags: []cli.Flag{
    34  		cli.StringFlag{
    35  			Name:  "funding_txid",
    36  			Usage: "the txid of the channel's funding transaction",
    37  		},
    38  		cli.IntFlag{
    39  			Name: "output_index",
    40  			Usage: "the output index for the funding output of the funding " +
    41  				"transaction",
    42  		},
    43  		cli.StringFlag{
    44  			Name: "action",
    45  			Usage: `the action to take: must be one of "enable", "disable", ` +
    46  				`or "auto"`,
    47  		},
    48  	},
    49  	Action: actionDecorator(updateChanStatus),
    50  }
    51  
    52  func updateChanStatus(ctx *cli.Context) error {
    53  	ctxc := getContext()
    54  	conn := getClientConn(ctx, false)
    55  	defer conn.Close()
    56  
    57  	if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
    58  		_ = cli.ShowCommandHelp(ctx, "updatechanstatus")
    59  		return nil
    60  	}
    61  
    62  	channelPoint, err := parseChannelPoint(ctx)
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	var action routerrpc.ChanStatusAction
    68  	switch ctx.String("action") {
    69  	case "enable":
    70  		action = routerrpc.ChanStatusAction_ENABLE
    71  	case "disable":
    72  		action = routerrpc.ChanStatusAction_DISABLE
    73  	case "auto":
    74  		action = routerrpc.ChanStatusAction_AUTO
    75  	default:
    76  		return errors.New(`action must be one of "enable", "disable", ` +
    77  			`or "auto"`)
    78  	}
    79  	req := &routerrpc.UpdateChanStatusRequest{
    80  		ChanPoint: channelPoint,
    81  		Action:    action,
    82  	}
    83  
    84  	client := routerrpc.NewRouterClient(conn)
    85  	resp, err := client.UpdateChanStatus(ctxc, req)
    86  	if err != nil {
    87  		return err
    88  	}
    89  
    90  	printRespJSON(resp)
    91  
    92  	return nil
    93  }