cmd/lncli: accept --lighting_id parameter for openchannel
This commit is contained in:
parent
6c83f53206
commit
c604730b7d
@ -182,14 +182,19 @@ func connectPeer(ctx *cli.Context) error {
|
|||||||
var OpenChannelCommand = cli.Command{
|
var OpenChannelCommand = cli.Command{
|
||||||
Name: "openchannel",
|
Name: "openchannel",
|
||||||
Description: "Attempt to open a new channel to an existing peer, " +
|
Description: "Attempt to open a new channel to an existing peer, " +
|
||||||
"blocking until the channel is 'open'. Once the channel is " +
|
"optionally blocking until the channel is 'open'. Once the " +
|
||||||
"open, a channelPoint (txid:vout) of the funding output is " +
|
"channel is open, a channelPoint (txid:vout) of the funding " +
|
||||||
"returned.",
|
"output is returned. NOTE: peer_id and lightning_id are " +
|
||||||
|
"mutually exclusive, only one should be used, not both.",
|
||||||
Usage: "openchannel --peer_id=X --local_amt=N --remote_amt=N --num_confs=N",
|
Usage: "openchannel --peer_id=X --local_amt=N --remote_amt=N --num_confs=N",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "peer_id",
|
Name: "peer_id",
|
||||||
Usage: "the id of the peer to open a channel with",
|
Usage: "the relative id of the peer to open a channel with",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lightning_id",
|
||||||
|
Usage: "the lightning id of the target peer",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "local_amt",
|
Name: "local_amt",
|
||||||
@ -217,13 +222,27 @@ func openChannel(ctx *cli.Context) error {
|
|||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
client := getClient(ctx)
|
client := getClient(ctx)
|
||||||
|
|
||||||
|
if ctx.Int("peer_id") != 0 && ctx.String("lightning_id") != "" {
|
||||||
|
return fmt.Errorf("both peer_id and lightning_id cannot be set " +
|
||||||
|
"at the same time, only one can be specified")
|
||||||
|
}
|
||||||
|
|
||||||
req := &lnrpc.OpenChannelRequest{
|
req := &lnrpc.OpenChannelRequest{
|
||||||
TargetPeerId: int32(ctx.Int("peer_id")),
|
|
||||||
LocalFundingAmount: int64(ctx.Int("local_amt")),
|
LocalFundingAmount: int64(ctx.Int("local_amt")),
|
||||||
RemoteFundingAmount: int64(ctx.Int("remote_amt")),
|
RemoteFundingAmount: int64(ctx.Int("remote_amt")),
|
||||||
NumConfs: uint32(ctx.Int("num_confs")),
|
NumConfs: uint32(ctx.Int("num_confs")),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Int("peer_id") != 0 {
|
||||||
|
req.TargetPeerId = int32(ctx.Int("peer_id"))
|
||||||
|
} else {
|
||||||
|
lnID, err := hex.DecodeString(ctx.String("lightning_id"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to decode lightning id: %v", err)
|
||||||
|
}
|
||||||
|
req.TargetNode = lnID
|
||||||
|
}
|
||||||
|
|
||||||
stream, err := client.OpenChannel(ctxb, req)
|
stream, err := client.OpenChannel(ctxb, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user