From 9b4ac77d400b1162b472aac334219cf459dd59f5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 14 Jan 2017 18:12:20 -0800 Subject: [PATCH] rpcserver: allow channels to be opened using --node_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a slight bug in the interaction between the cli program and the rpcsever itself. With this commit it’s now again possible to create a channel with a peer that’s identified by its peerID, instead of only the pubkey. --- rpcserver.go | 18 ++++++++++++++---- server.go | 12 ++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 56b5877ce..2f062754d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -8,6 +8,7 @@ import ( "io" "math" "net" + "strings" "time" "sync" @@ -244,10 +245,19 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest, "state must be below the local funding amount") } - // TODO(roasbeef): make it optional - nodepubKey, err := btcec.ParsePubKey(in.NodePubkey, btcec.S256()) - if err != nil { - return err + var ( + nodepubKey *btcec.PublicKey + err error + ) + + // If the node key is set, the we'll parse the raw bytes into a pubkey + // object so we can easily manipulate it. If this isn't set, then we + // expected the TargetPeerId to be set accordingly. + if len(in.NodePubkey) != 0 { + nodepubKey, err = btcec.ParsePubKey(in.NodePubkey, btcec.S256()) + if err != nil { + return err + } } // Instruct the server to trigger the necessary events to attempt to diff --git a/server.go b/server.go index 78b7512b2..8b9271063 100644 --- a/server.go +++ b/server.go @@ -713,9 +713,17 @@ func (s *server) handleConnectPeer(msg *connectPeerMsg) { // request to the funding manager allowing it to initiate the channel funding // workflow. func (s *server) handleOpenChanReq(req *openChanReq) { - var targetPeer *peer + var ( + targetPeer *peer + pubStr string + ) - pubStr := string(req.targetPubkey.SerializeCompressed()) + // If the user is targeting the peer by public key, then we'll need to + // convert that into a string for our map. Otherwise, we expect them to + // target by peer ID instead. + if req.targetPubkey != nil { + pubStr = string(req.targetPubkey.SerializeCompressed()) + } // First attempt to locate the target peer to open a channel with, if // we're unable to locate the peer then this request will fail.