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.
This commit is contained in:
Olaoluwa Osuntokun 2016-06-22 11:10:20 -07:00
parent 8066195d23
commit 7e09a70706
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 4 additions and 5 deletions

@ -2,7 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
@ -222,14 +221,14 @@ func closeChannel(ctx *cli.Context) {
ctxb := context.Background() ctxb := context.Background()
client := getClient(ctx) client := getClient(ctx)
txid, err := hex.DecodeString(ctx.String("funding_txid")) txid, err := wire.NewShaHashFromStr(ctx.String("funding_txid"))
if err != nil { if err != nil {
fatal(err) fatal(err)
} }
req := &lnrpc.CloseChannelRequest{ req := &lnrpc.CloseChannelRequest{
ChannelPoint: &lnrpc.ChannelPoint{ ChannelPoint: &lnrpc.ChannelPoint{
FundingTxid: txid, FundingTxid: txid[:],
OutputIndex: uint32(ctx.Int("output_index")), OutputIndex: uint32(ctx.Int("output_index")),
}, },
} }

@ -488,7 +488,7 @@ func (p *peer) handleLocalClose(req *closeChanReq) {
return return
} }
peerLog.Infof("Executing cooperative closure of "+ 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) txid)
// With our signature for the close tx generated, send the signature // With our signature for the close tx generated, send the signature

@ -171,7 +171,7 @@ func (r *rpcServer) OpenChannel(ctx context.Context,
return nil, err return nil, err
} }
rpcsLog.Tracef("Opened channel with peerid(%v), fundingtxid %v", rpcsLog.Tracef("Opened channel with peerid(%v), ChannelPoint(%v)",
in.TargetPeerId, resp) in.TargetPeerId, resp)
return &lnrpc.OpenChannelResponse{ return &lnrpc.OpenChannelResponse{