From 7e09a70706d6c0f6a8ad956855f1f8d6e1fec221 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 22 Jun 2016 11:10:20 -0700 Subject: [PATCH] cmd/lncli: properly reverse user txid input This commit fixes a bug introduced within a prior commit. The prior commit failed to drollery reverse the txid string taken in as user input, therefore in order to properly close a channel, the user needed to manually reverse the txid themselves. With this change, `wire.NewShaHashFromStr` is used which properly reverses the string within the constructor. This allows the string reported not be directly used to the close an active channel. This commit also corrects a few logging messages. --- cmd/lncli/commands.go | 5 ++--- peer.go | 2 +- rpcserver.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 51d0bfe5..6e3bc69e 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "encoding/hex" "encoding/json" "fmt" "os" @@ -222,14 +221,14 @@ func closeChannel(ctx *cli.Context) { ctxb := context.Background() client := getClient(ctx) - txid, err := hex.DecodeString(ctx.String("funding_txid")) + txid, err := wire.NewShaHashFromStr(ctx.String("funding_txid")) if err != nil { fatal(err) } req := &lnrpc.CloseChannelRequest{ ChannelPoint: &lnrpc.ChannelPoint{ - FundingTxid: txid, + FundingTxid: txid[:], OutputIndex: uint32(ctx.Int("output_index")), }, } diff --git a/peer.go b/peer.go index 733a7f88..f7840aaf 100644 --- a/peer.go +++ b/peer.go @@ -488,7 +488,7 @@ func (p *peer) handleLocalClose(req *closeChanReq) { return } peerLog.Infof("Executing cooperative closure of "+ - "ChanPoint(%v) with %v, txid=%v", key, p.id, + "ChanPoint(%v) with peerID(%v), txid=%v", key, p.id, txid) // With our signature for the close tx generated, send the signature diff --git a/rpcserver.go b/rpcserver.go index 521d90bd..14c2aa52 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -171,7 +171,7 @@ func (r *rpcServer) OpenChannel(ctx context.Context, return nil, err } - rpcsLog.Tracef("Opened channel with peerid(%v), fundingtxid %v", + rpcsLog.Tracef("Opened channel with peerid(%v), ChannelPoint(%v)", in.TargetPeerId, resp) return &lnrpc.OpenChannelResponse{