lnd: partially fix golint warnings
This commit is contained in:
1 parent
92dec2a902
commit
fd97a4bd19
38 files changed
+229
-233
No files matched your search
@@ -55,17 +55,17 @@ func (a *ChannelAnnouncement) Validate() error {
|
||||
// io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
return readElements(r,
|
||||
&c.FirstNodeSig,
|
||||
&c.SecondNodeSig,
|
||||
&c.ChannelID,
|
||||
&c.FirstBitcoinSig,
|
||||
&c.SecondBitcoinSig,
|
||||
&c.FirstNodeID,
|
||||
&c.SecondNodeID,
|
||||
&c.FirstBitcoinKey,
|
||||
&c.SecondBitcoinKey,
|
||||
&a.FirstNodeSig,
|
||||
&a.SecondNodeSig,
|
||||
&a.ChannelID,
|
||||
&a.FirstBitcoinSig,
|
||||
&a.SecondBitcoinSig,
|
||||
&a.FirstNodeID,
|
||||
&a.SecondNodeID,
|
||||
&a.FirstBitcoinKey,
|
||||
&a.SecondBitcoinKey,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,17 +73,17 @@ func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
// observing the protocol version specified.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
func (a *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
return writeElements(w,
|
||||
c.FirstNodeSig,
|
||||
c.SecondNodeSig,
|
||||
c.ChannelID,
|
||||
c.FirstBitcoinSig,
|
||||
c.SecondBitcoinSig,
|
||||
c.FirstNodeID,
|
||||
c.SecondNodeID,
|
||||
c.FirstBitcoinKey,
|
||||
c.SecondBitcoinKey,
|
||||
a.FirstNodeSig,
|
||||
a.SecondNodeSig,
|
||||
a.ChannelID,
|
||||
a.FirstBitcoinSig,
|
||||
a.SecondBitcoinSig,
|
||||
a.FirstNodeID,
|
||||
a.SecondNodeID,
|
||||
a.FirstBitcoinKey,
|
||||
a.SecondBitcoinKey,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
// wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelAnnouncement) Command() uint32 {
|
||||
func (a *ChannelAnnouncement) Command() uint32 {
|
||||
return CmdChannelAnnoucmentMessage
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (c *ChannelAnnouncement) Command() uint32 {
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
func (a *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
var length uint32
|
||||
|
||||
// FirstNodeSig - 64 bytes
|
||||
@@ -134,17 +134,17 @@ func (c *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
|
||||
// DataToSign is used to retrieve part of the announcement message which
|
||||
// should be signed.
|
||||
func (c *ChannelAnnouncement) DataToSign() ([]byte, error) {
|
||||
func (a *ChannelAnnouncement) DataToSign() ([]byte, error) {
|
||||
// We should not include the signatures itself.
|
||||
var w bytes.Buffer
|
||||
err := writeElements(&w,
|
||||
c.ChannelID,
|
||||
c.FirstBitcoinSig,
|
||||
c.SecondBitcoinSig,
|
||||
c.FirstNodeID,
|
||||
c.SecondNodeID,
|
||||
c.FirstBitcoinKey,
|
||||
c.SecondBitcoinKey,
|
||||
a.ChannelID,
|
||||
a.FirstBitcoinSig,
|
||||
a.SecondBitcoinSig,
|
||||
a.FirstNodeID,
|
||||
a.SecondNodeID,
|
||||
a.FirstBitcoinKey,
|
||||
a.SecondBitcoinKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -71,16 +71,16 @@ func (a *ChannelUpdateAnnouncement) Validate() error {
|
||||
// passed io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
func (a *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
return readElements(r,
|
||||
&c.Signature,
|
||||
&c.ChannelID,
|
||||
&c.Timestamp,
|
||||
&c.Flags,
|
||||
&c.TimeLockDelta,
|
||||
&c.HtlcMinimumMsat,
|
||||
&c.FeeBaseMsat,
|
||||
&c.FeeProportionalMillionths,
|
||||
&a.Signature,
|
||||
&a.ChannelID,
|
||||
&a.Timestamp,
|
||||
&a.Flags,
|
||||
&a.TimeLockDelta,
|
||||
&a.HtlcMinimumMsat,
|
||||
&a.FeeBaseMsat,
|
||||
&a.FeeProportionalMillionths,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -88,16 +88,16 @@ func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
// io.Writer observing the protocol version specified.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
func (a *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
return writeElements(w,
|
||||
c.Signature,
|
||||
c.ChannelID,
|
||||
c.Timestamp,
|
||||
c.Flags,
|
||||
c.TimeLockDelta,
|
||||
c.HtlcMinimumMsat,
|
||||
c.FeeBaseMsat,
|
||||
c.FeeProportionalMillionths,
|
||||
a.Signature,
|
||||
a.ChannelID,
|
||||
a.Timestamp,
|
||||
a.Flags,
|
||||
a.TimeLockDelta,
|
||||
a.HtlcMinimumMsat,
|
||||
a.FeeBaseMsat,
|
||||
a.FeeProportionalMillionths,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
// wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelUpdateAnnouncement) Command() uint32 {
|
||||
func (a *ChannelUpdateAnnouncement) Command() uint32 {
|
||||
return CmdChannelUpdateAnnoucmentMessage
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (c *ChannelUpdateAnnouncement) Command() uint32 {
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
func (a *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
var length uint32
|
||||
|
||||
// Signature - 64 bytes
|
||||
@@ -145,18 +145,18 @@ func (c *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
|
||||
// DataToSign is used to retrieve part of the announcement message which
|
||||
// should be signed.
|
||||
func (c *ChannelUpdateAnnouncement) DataToSign() ([]byte, error) {
|
||||
func (a *ChannelUpdateAnnouncement) DataToSign() ([]byte, error) {
|
||||
|
||||
// We should not include the signatures itself.
|
||||
var w bytes.Buffer
|
||||
err := writeElements(&w,
|
||||
c.ChannelID,
|
||||
c.Timestamp,
|
||||
c.Flags,
|
||||
c.TimeLockDelta,
|
||||
c.HtlcMinimumMsat,
|
||||
c.FeeBaseMsat,
|
||||
c.FeeProportionalMillionths,
|
||||
a.ChannelID,
|
||||
a.Timestamp,
|
||||
a.Flags,
|
||||
a.TimeLockDelta,
|
||||
a.HtlcMinimumMsat,
|
||||
a.FeeBaseMsat,
|
||||
a.FeeProportionalMillionths,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -101,7 +101,7 @@ func (c *CloseRequest) MaxPayloadLength(pver uint32) uint32 {
|
||||
func (c *CloseRequest) Validate() error {
|
||||
// Fee must be greater than 0.
|
||||
if c.Fee < 0 {
|
||||
return fmt.Errorf("Fee must be greater than zero.")
|
||||
return fmt.Errorf("fee must be greater than zero")
|
||||
}
|
||||
|
||||
// We're good!
|
||||
|
||||
+6
-7
@@ -205,12 +205,11 @@ func (f *FeatureVector) Encode(w io.Writer) error {
|
||||
// were present in both remote and local feature vectors. If remote/local node
|
||||
// doesn't have the feature and local/remote node require it than such vectors
|
||||
// are incompatible.
|
||||
func (local *FeatureVector) Compare(remote *FeatureVector) (*SharedFeatures,
|
||||
error) {
|
||||
shared := newSharedFeatures(local.Copy())
|
||||
func (f *FeatureVector) Compare(f2 *FeatureVector) (*SharedFeatures, error) {
|
||||
shared := newSharedFeatures(f.Copy())
|
||||
|
||||
for index, flag := range local.flags {
|
||||
if _, exist := remote.flags[index]; !exist {
|
||||
for index, flag := range f.flags {
|
||||
if _, exist := f2.flags[index]; !exist {
|
||||
switch flag {
|
||||
case RequiredFlag:
|
||||
return nil, errors.New("Remote node hasn't " +
|
||||
@@ -228,8 +227,8 @@ func (local *FeatureVector) Compare(remote *FeatureVector) (*SharedFeatures,
|
||||
shared.flags[index] = flag
|
||||
}
|
||||
|
||||
for index, flag := range remote.flags {
|
||||
if _, exist := local.flags[index]; !exist {
|
||||
for index, flag := range f2.flags {
|
||||
if _, exist := f.flags[index]; !exist {
|
||||
switch flag {
|
||||
case RequiredFlag:
|
||||
return nil, errors.New("Local node hasn't " +
|
||||
|
||||
+4
-4
@@ -128,7 +128,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
// Enforce a sane number for the maximum number of signatures.
|
||||
numSigs := len(e)
|
||||
if numSigs > 127 {
|
||||
return fmt.Errorf("Too many signatures!")
|
||||
return fmt.Errorf("too many signatures")
|
||||
}
|
||||
|
||||
// First write out the the number of elements in the slice as a
|
||||
@@ -186,7 +186,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
// Make sure it's P2PKH or P2SH size or less.
|
||||
scriptLength := len(e)
|
||||
if scriptLength > 25 {
|
||||
return fmt.Errorf("PkScript too long!")
|
||||
return fmt.Errorf("'PkScript' too long")
|
||||
}
|
||||
|
||||
if err := wire.WriteVarBytes(w, 0, e); err != nil {
|
||||
@@ -195,7 +195,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
case string:
|
||||
strlen := len(e)
|
||||
if strlen > MaxSliceLength {
|
||||
return fmt.Errorf("String too long!")
|
||||
return fmt.Errorf("string too long")
|
||||
}
|
||||
|
||||
if err := wire.WriteVarString(w, 0, e); err != nil {
|
||||
@@ -429,7 +429,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
if numSigs > 127 {
|
||||
return fmt.Errorf("Too many signatures!")
|
||||
return fmt.Errorf("too many signatures")
|
||||
}
|
||||
|
||||
// Read that number of signatures
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
// Code derived from https:// github.com/btcsuite/btcd/blob/master/wire/message.go
|
||||
package lnwire
|
||||
|
||||
// code derived from https://github .com/btcsuite/btcd/blob/master/wire/message.go
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
@@ -247,7 +248,7 @@ func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet)
|
||||
return totalBytes, err
|
||||
}
|
||||
|
||||
// ReadMessageN reads, validates, and parses the next bitcoin Message from r for
|
||||
// ReadMessage reads, validates, and parses the next bitcoin Message from r for
|
||||
// the provided protocol version and bitcoin network. It returns the number of
|
||||
// bytes read in addition to the parsed Message and raw bytes which comprise the
|
||||
// message. This function is the same as ReadMessage except it also returns the
|
||||
|
||||
+26
-26
@@ -127,15 +127,15 @@ func (a *NodeAnnouncement) Validate() error {
|
||||
// io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
return readElements(r,
|
||||
&c.Signature,
|
||||
&c.Timestamp,
|
||||
&c.Address,
|
||||
&c.NodeID,
|
||||
&c.RGBColor,
|
||||
&c.pad,
|
||||
&c.Alias,
|
||||
&a.Signature,
|
||||
&a.Timestamp,
|
||||
&a.Address,
|
||||
&a.NodeID,
|
||||
&a.RGBColor,
|
||||
&a.pad,
|
||||
&a.Alias,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -143,15 +143,15 @@ func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
// observing the protocol version specified.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
return writeElements(w,
|
||||
c.Signature,
|
||||
c.Timestamp,
|
||||
c.Address,
|
||||
c.NodeID,
|
||||
c.RGBColor,
|
||||
c.pad,
|
||||
c.Alias,
|
||||
a.Signature,
|
||||
a.Timestamp,
|
||||
a.Address,
|
||||
a.NodeID,
|
||||
a.RGBColor,
|
||||
a.pad,
|
||||
a.Alias,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
// wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *NodeAnnouncement) Command() uint32 {
|
||||
func (a *NodeAnnouncement) Command() uint32 {
|
||||
return CmdNodeAnnoucmentMessage
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func (c *NodeAnnouncement) Command() uint32 {
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
func (a *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
var length uint32
|
||||
|
||||
// Signature - 64 bytes
|
||||
@@ -198,18 +198,18 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
return length
|
||||
}
|
||||
|
||||
// dataToSign...
|
||||
func (c *NodeAnnouncement) DataToSign() ([]byte, error) {
|
||||
// DataToSign returns the part of the message that should be signed.
|
||||
func (a *NodeAnnouncement) DataToSign() ([]byte, error) {
|
||||
|
||||
// We should not include the signatures itself.
|
||||
var w bytes.Buffer
|
||||
err := writeElements(&w,
|
||||
c.Timestamp,
|
||||
c.Address,
|
||||
c.NodeID,
|
||||
c.RGBColor,
|
||||
c.pad,
|
||||
c.Alias,
|
||||
a.Timestamp,
|
||||
a.Address,
|
||||
a.NodeID,
|
||||
a.RGBColor,
|
||||
a.pad,
|
||||
a.Alias,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+5
-8
@@ -32,10 +32,9 @@ func serializeSigToWire(b *[64]byte, e *btcec.Signature) error {
|
||||
if (sLen > 33) || (sig[6+rLen] != 0x00) {
|
||||
return fmt.Errorf("S is over 32 bytes long " +
|
||||
"without padding")
|
||||
} else {
|
||||
sLen -= 1
|
||||
copy(b[64-sLen:], sig[7+rLen:])
|
||||
}
|
||||
sLen--
|
||||
copy(b[64-sLen:], sig[7+rLen:])
|
||||
} else {
|
||||
copy(b[64-sLen:], sig[6+rLen:])
|
||||
}
|
||||
@@ -45,10 +44,9 @@ func serializeSigToWire(b *[64]byte, e *btcec.Signature) error {
|
||||
if (rLen > 33) || (sig[4] != 0x00) {
|
||||
return fmt.Errorf("R is over 32 bytes long " +
|
||||
"without padding")
|
||||
} else {
|
||||
rLen -= 1
|
||||
copy(b[32-rLen:], sig[5:5+rLen])
|
||||
}
|
||||
rLen--
|
||||
copy(b[32-rLen:], sig[5:5+rLen])
|
||||
} else {
|
||||
copy(b[32-rLen:], sig[4:4+rLen])
|
||||
}
|
||||
@@ -96,9 +94,8 @@ func extractCanonicalPadding(b []byte) []byte {
|
||||
// If the MSB is set, we need zero padding.
|
||||
if b[i]&0x80 == 0x80 {
|
||||
return append([]byte{0x00}, b[i:]...)
|
||||
} else {
|
||||
return b[i:]
|
||||
}
|
||||
return b[i:]
|
||||
}
|
||||
}
|
||||
return []byte{0x00}
|
||||
|
||||
@@ -222,22 +222,23 @@ func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
|
||||
func (c *SingleFundingRequest) Validate() error {
|
||||
// Negative values is are allowed.
|
||||
if c.FeePerKb < 0 {
|
||||
return fmt.Errorf("MinFeePerKb cannot be negative")
|
||||
return fmt.Errorf("'MinFeePerKb' cannot be negative")
|
||||
}
|
||||
if c.FundingAmount < 0 {
|
||||
return fmt.Errorf("FundingAmount cannot be negative")
|
||||
return fmt.Errorf("'FundingAmount' cannot be negative")
|
||||
}
|
||||
|
||||
// The CSV delay MUST be non-zero.
|
||||
if c.CsvDelay == 0 {
|
||||
return fmt.Errorf("Commitment transaction must have non-zero " +
|
||||
"CSV delay")
|
||||
return fmt.Errorf("commitment transaction must have non-zero" +
|
||||
" CSV delay")
|
||||
}
|
||||
|
||||
// The channel derivation point must be non-nil, and have an odd
|
||||
// y-coordinate.
|
||||
if c.ChannelDerivationPoint == nil {
|
||||
return fmt.Errorf("The channel derivation point must be non-nil")
|
||||
return fmt.Errorf("the channel derivation point must be " +
|
||||
"non-nil")
|
||||
}
|
||||
//if c.ChannelDerivationPoint.Y.Bit(0) != 1 {
|
||||
//return fmt.Errorf("The channel derivation point must have an odd " +
|
||||
@@ -248,12 +249,12 @@ func (c *SingleFundingRequest) Validate() error {
|
||||
// templates.
|
||||
if !isValidPkScript(c.DeliveryPkScript) {
|
||||
// TODO(roasbeef): move into actual error
|
||||
return fmt.Errorf("Valid delivery public key scripts MUST be: " +
|
||||
"P2PKH, P2WKH, P2SH, or P2WSH.")
|
||||
return fmt.Errorf("valid delivery public key scripts MUST " +
|
||||
"be: P2PKH, P2WKH, P2SH, or P2WSH")
|
||||
}
|
||||
|
||||
if c.DustLimit <= 0 {
|
||||
return fmt.Errorf("Dust limit should be greater than zero.")
|
||||
return fmt.Errorf("DustLimit' should be greater than zero")
|
||||
}
|
||||
|
||||
if c.ConfirmationDepth == 0 {
|
||||
|
||||
@@ -78,8 +78,8 @@ func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
||||
// for field sanity.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (s *SingleFundingSignComplete) Validate() error {
|
||||
if s.CommitSignature == nil {
|
||||
func (c *SingleFundingSignComplete) Validate() error {
|
||||
if c.CommitSignature == nil {
|
||||
return fmt.Errorf("commitment signature must be non-nil")
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ func (c *UpdateAddHTLC) Validate() error {
|
||||
if c.Amount < 0 {
|
||||
// While fees can be negative, it's too confusing to allow
|
||||
// negative payments. Maybe for some wallets, but not this one!
|
||||
return fmt.Errorf("Amount paid cannot be negative.")
|
||||
return fmt.Errorf("amount paid cannot be negative")
|
||||
}
|
||||
// We're good!
|
||||
return nil
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
)
|
||||
|
||||
// FailReason specifies the precise reason that an upstream HTLC was cancelled.
|
||||
// FailCode specifies the precise reason that an upstream HTLC was cancelled.
|
||||
// Each UpdateFailHTLC message carries a FailCode which is to be passed back
|
||||
// unaltered to the source of the HTLC within the route.
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user