multi: fix go vet warnings throughout code base

This commit is contained in:
Olaoluwa Osuntokun 2017-02-09 15:28:32 -08:00
parent 55e693aa09
commit 384fe61e73
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
12 changed files with 52 additions and 81 deletions

View File

@ -174,7 +174,7 @@ out:
breachTXID := &breachInfo.commitHash
confChan, err := b.notifier.RegisterConfirmationsNtfn(breachTXID, 1)
if err != nil {
brarLog.Errorf("unable to register for conf for txid: ",
brarLog.Errorf("unable to register for conf for txid: %v",
breachTXID)
continue
}

View File

@ -592,7 +592,9 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint) (*chainntnfs.S
}
}
return &chainntnfs.SpendEvent{ntfn.spendChan}, nil
return &chainntnfs.SpendEvent{
Spend: ntfn.spendChan,
}, nil
}
// confirmationNotification represents a client's intent to receive a

View File

@ -40,7 +40,12 @@ func getTestTxId(miner *rpctest.Harness) (*chainhash.Hash, error) {
return nil, err
}
outputs := []*wire.TxOut{&wire.TxOut{2e8, script}}
outputs := []*wire.TxOut{
&wire.TxOut{
Value: 2e8,
PkScript: script,
},
}
return miner.SendOutputs(outputs, 10)
}

View File

@ -94,8 +94,6 @@ func assertChannelOpen(t *testing.T, miner *rpctest.Harness, numConfs uint32,
t.Fatalf("channel never opened")
return nil
}
return nil
}
// bobNode represents the other party involved as a node within LN. Bob is our
@ -210,7 +208,10 @@ func newBobNode(miner *rpctest.Harness, amt btcutil.Amount) (*bobNode, error) {
}
// Give bobNode one 7 BTC output for use in creating channels.
output := &wire.TxOut{7e8, bobAddrScript}
output := &wire.TxOut{
Value: 7e8,
PkScript: bobAddrScript,
}
mainTxid, err := miner.SendOutputs([]*wire.TxOut{output}, 10)
if err != nil {
return nil, err
@ -284,7 +285,10 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet, numOut
addrs = append(addrs, walletAddr)
output := &wire.TxOut{satoshiPerOutput, script}
output := &wire.TxOut{
Value: satoshiPerOutput,
PkScript: script,
}
if _, err := miner.SendOutputs([]*wire.TxOut{output}, 10); err != nil {
return err
}
@ -949,7 +953,10 @@ func testListTransactionDetails(miner *rpctest.Harness, wallet *lnwallet.Lightni
t.Fatalf("unable to create output script: %v", err)
}
output := &wire.TxOut{outputAmt, script}
output := &wire.TxOut{
Value: outputAmt,
PkScript: script,
}
txid, err := miner.SendOutputs([]*wire.TxOut{output}, 10)
if err != nil {
t.Fatalf("unable to send coinbase: %v", err)
@ -1044,7 +1051,7 @@ func testListTransactionDetails(miner *rpctest.Harness, wallet *lnwallet.Lightni
}
}
if !burnTxFound {
t.Fatalf("tx burning btc not found")
t.Fatal("tx burning btc not found")
}
}
@ -1056,7 +1063,7 @@ func testTransactionSubscriptions(miner *rpctest.Harness, w *lnwallet.LightningW
// implementation of the WalletController.
txClient, err := w.SubscribeTransactions()
if err != nil {
t.Fatalf("unable to generate tx subscription: %v")
t.Fatalf("unable to generate tx subscription: %v", err)
}
defer txClient.Cancel()
@ -1097,7 +1104,10 @@ func testTransactionSubscriptions(miner *rpctest.Harness, w *lnwallet.LightningW
t.Fatalf("unable to create output script: %v", err)
}
output := &wire.TxOut{outputAmt, script}
output := &wire.TxOut{
Value: outputAmt,
PkScript: script,
}
if _, err := miner.SendOutputs([]*wire.TxOut{output}, 10); err != nil {
t.Fatalf("unable to send coinbase: %v", err)
}

View File

@ -65,10 +65,16 @@ func TestCommitmentSpendValidation(t *testing.T) {
// transaction which sweeps the funds to a random address.
targetOutput, err := commitScriptUnencumbered(aliceKeyPub)
if err != nil {
t.Fatalf("unable to create target output: %v")
t.Fatalf("unable to create target output: %v", err)
}
sweepTx := wire.NewMsgTx(2)
sweepTx.AddTxIn(wire.NewTxIn(&wire.OutPoint{commitmentTx.TxHash(), 0}, nil, nil))
sweepTx.AddTxIn(wire.NewTxIn(&wire.OutPoint{
Hash: commitmentTx.TxHash(),
Index: 0,
},
nil,
nil),
)
sweepTx.AddTxOut(&wire.TxOut{
PkScript: targetOutput,
Value: 0.5 * 10e8,
@ -77,7 +83,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
// First, we'll test spending with Alice's key after the timeout.
delayScript, err := commitScriptToSelf(csvTimeout, aliceKeyPub, revokePubKey)
if err != nil {
t.Fatalf("unable to generate alice delay script: %v")
t.Fatalf("unable to generate alice delay script: %v", err)
}
sweepTx.TxIn[0].Sequence = lockTimeToSequence(false, csvTimeout)
signDesc := &SignDescriptor{
@ -92,7 +98,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
aliceWitnessSpend, err := CommitSpendTimeout(aliceSelfOutputSigner,
signDesc, sweepTx)
if err != nil {
t.Fatalf("unable to generate delay commit spend witness :%v")
t.Fatalf("unable to generate delay commit spend witness: %v", err)
}
sweepTx.TxIn[0].Witness = aliceWitnessSpend
vm, err := txscript.NewEngine(delayOutput.PkScript,
@ -378,8 +384,8 @@ func TestHTLCSenderSpendValidation(t *testing.T) {
t.Fatalf("spend test case #%v succeed, spend should be invalid: %v", i, err)
}
debugBuf.WriteString(fmt.Sprintf("Stack: ", vm.GetStack()))
debugBuf.WriteString(fmt.Sprintf("AltStack: ", vm.GetAltStack()))
debugBuf.WriteString(fmt.Sprintf("Stack: %v", vm.GetStack()))
debugBuf.WriteString(fmt.Sprintf("AltStack: %v", vm.GetAltStack()))
}
}
}
@ -551,8 +557,8 @@ func TestHTLCReceiverSpendValidation(t *testing.T) {
t.Fatalf("spend test case #%v succeed, spend should be invalid: %v", i, err)
}
debugBuf.WriteString(fmt.Sprintf("Stack: ", vm.GetStack()))
debugBuf.WriteString(fmt.Sprintf("AltStack: ", vm.GetAltStack()))
debugBuf.WriteString(fmt.Sprintf("Stack: %v", vm.GetStack()))
debugBuf.WriteString(fmt.Sprintf("AltStack: %v", vm.GetAltStack()))
}
}
}

View File

@ -4,9 +4,7 @@ import (
"bytes"
"io"
"github.com/go-errors/errors"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
)
// ChannelAnnouncement message is used to announce the existence of a channel
@ -50,35 +48,6 @@ var _ Message = (*ChannelAnnouncement)(nil)
//
// This is part of the lnwire.Message interface.
func (a *ChannelAnnouncement) Validate() error {
// TODO(roasbeef): move validation to discovery service
return nil
var sigHash []byte
sigHash = chainhash.DoubleHashB(a.FirstNodeID.SerializeCompressed())
if !a.FirstBitcoinSig.Verify(sigHash, a.FirstBitcoinKey) {
return errors.New("can't verify first bitcoin signature")
}
sigHash = chainhash.DoubleHashB(a.SecondNodeID.SerializeCompressed())
if !a.SecondBitcoinSig.Verify(sigHash, a.SecondBitcoinKey) {
return errors.New("can't verify second bitcoin signature")
}
data, err := a.DataToSign()
if err != nil {
return err
}
dataHash := chainhash.DoubleHashB(data)
if !a.FirstNodeSig.Verify(dataHash, a.FirstNodeID) {
return errors.New("can't verify data in first node signature")
}
if !a.SecondNodeSig.Verify(dataHash, a.SecondNodeID) {
return errors.New("can't verify data in second node signature")
}
return nil
}

View File

@ -7,7 +7,6 @@ import (
"github.com/go-errors/errors"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
)
var (
@ -108,22 +107,6 @@ var _ Message = (*NodeAnnouncement)(nil)
func (a *NodeAnnouncement) Validate() error {
// TODO(roasbeef): move validation to discovery service
return nil
if err := a.Alias.Validate(); err != nil {
return err
}
data, err := a.DataToSign()
if err != nil {
return err
}
dataHash := chainhash.DoubleHashB(data)
if !a.Signature.Verify(dataHash, a.NodeID) {
return errors.New("can't check the node annoucement signature")
}
return nil
}
// Decode deserializes a serialized NodeAnnouncement stored in the

View File

@ -422,7 +422,9 @@ func (n *networkHarness) SetUp() error {
// Load up the wallets of the seeder nodes with 10 outputs of 1 BTC
// each.
ctxb := context.Background()
addrReq := &lnrpc.NewAddressRequest{lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH}
addrReq := &lnrpc.NewAddressRequest{
Type: lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH,
}
clients := []lnrpc.LightningClient{n.Alice, n.Bob}
for _, client := range clients {
for i := 0; i < 10; i++ {

View File

@ -1029,9 +1029,9 @@ func generateSphinxPacket(route *Route, paymentHash []byte) ([]byte, error) {
// mutating the curve parameters, which are unset in a higher
// level in order to avoid spamming the logs.
pub := btcec.PublicKey{
btcec.S256(),
hop.Channel.Node.PubKey.X,
hop.Channel.Node.PubKey.Y,
Curve: btcec.S256(),
X: hop.Channel.Node.PubKey.X,
Y: hop.Channel.Node.PubKey.Y,
}
nodes[i] = &pub
}

View File

@ -705,7 +705,9 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
rpcsLog.Debugf("[walletbalance] balance=%v", balance)
return &lnrpc.WalletBalanceResponse{balance.ToBTC()}, nil
return &lnrpc.WalletBalanceResponse{
Balance: balance.ToBTC(),
}, nil
}
// ChannelBalance returns the total available channel flow across all open
@ -969,8 +971,6 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer)
}()
}
}
return nil
}
// SendPaymentSync is the synchronous non-streaming version of SendPayment.
@ -1242,8 +1242,6 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
return nil
}
}
return nil
}
// SubscribeTransactions creates a uni-directional stream (server -> client) in
@ -1286,8 +1284,6 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
return nil
}
}
return nil
}
// GetTransactions returns a list of describing all the known transactions

View File

@ -385,8 +385,6 @@ func (s *server) sendToPeer(target *btcec.PublicKey, msgs ...lnwire.Message) err
case <-s.quit:
return errors.New("server shutting down")
}
return nil
}
// peerConnected is a function that handles initialization a newly connected

View File

@ -208,7 +208,7 @@ func TestAddSerializedKidsToList(t *testing.T) {
kidList, err := deserializeKidList(&b)
if err != nil {
t.Fatalf("unable to deserialize kid output list: ", err)
t.Fatalf("unable to deserialize kid output list: %v", err)
}
for i := 0; i < 3; i++ {