Skip to content

Commit

Permalink
multi: fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Sep 28, 2021
1 parent 97c3fdf commit 12d7d04
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 39 deletions.
10 changes: 5 additions & 5 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

// ErrUnknownAddressType describes an error where an address can not
// decoded as a specific address type due to the string encoding
// begining with an identifier byte unknown to any standard or
// beginning with an identifier byte unknown to any standard or
// registered (via chaincfg.Register) network.
ErrUnknownAddressType = errors.New("unknown address type")

Expand Down Expand Up @@ -265,7 +265,7 @@ func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHa
// newAddressPubKeyHash is the internal API to create a pubkey hash address
// with a known leading identifier byte for a network, rather than looking
// it up through its parameters. This is useful when creating a new address
// structure from a string encoding where the identifer byte is already
// structure from a string encoding where the identifier byte is already
// known.
func newAddressPubKeyHash(pkHash []byte, netID byte) (*AddressPubKeyHash, error) {
// Check for a valid pubkey hash length.
Expand Down Expand Up @@ -304,7 +304,7 @@ func (a *AddressPubKeyHash) String() string {
}

// Hash160 returns the underlying array of the pubkey hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map
// when an array is more appropriate than a slice (for example, when used as map
// keys).
func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte {
return &a.hash
Expand Down Expand Up @@ -332,7 +332,7 @@ func NewAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*Add
// newAddressScriptHashFromHash is the internal API to create a script hash
// address with a known leading identifier byte for a network, rather than
// looking it up through its parameters. This is useful when creating a new
// address structure from a string encoding where the identifer byte is already
// address structure from a string encoding where the identifier byte is already
// known.
func newAddressScriptHashFromHash(scriptHash []byte, netID byte) (*AddressScriptHash, error) {
// Check for a valid script hash length.
Expand Down Expand Up @@ -371,7 +371,7 @@ func (a *AddressScriptHash) String() string {
}

// Hash160 returns the underlying array of the script hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map
// when an array is more appropriate than a slice (for example, when used as map
// keys).
func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte {
return &a.hash
Expand Down
2 changes: 1 addition & 1 deletion address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func TestAddresses(t *testing.T) {
// Encode again and compare against the original.
encoded := decoded.EncodeAddress()
if test.encoded != encoded {
t.Errorf("%v: decoding and encoding produced different addressess: %v != %v",
t.Errorf("%v: decoding and encoding produced different addresses: %v != %v",
test.name, test.encoded, encoded)
return
}
Expand Down
2 changes: 1 addition & 1 deletion base58/base58check.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func checksum(input []byte) (cksum [4]byte) {
func CheckEncode(input []byte, version byte) string {
b := make([]byte, 0, 1+len(input)+4)
b = append(b, version)
b = append(b, input[:]...)
b = append(b, input...)
cksum := checksum(b)
b = append(b, cksum[:]...)
return Encode(b)
Expand Down
11 changes: 7 additions & 4 deletions base58/base58check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ func TestBase58Check(t *testing.T) {

// test decoding
res, version, err := base58.CheckDecode(test.out)
if err != nil {
switch {
case err != nil:
t.Errorf("CheckDecode test #%d failed with err: %v", x, err)
} else if version != test.version {

case version != test.version:
t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version)
} else if string(res) != test.in {

case string(res) != test.in:
t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in)
}
}
Expand All @@ -56,7 +59,7 @@ func TestBase58Check(t *testing.T) {
// bytes are missing).
testString := ""
for len := 0; len < 4; len++ {
testString = testString + "x"
testString += "x"
_, _, err = base58.CheckDecode(testString)
if err != base58.ErrInvalidFormat {
t.Error("Checkdecode test failed, expected ErrInvalidFormat")
Expand Down
6 changes: 3 additions & 3 deletions bech32/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)
for _, b := range data {

// Discard unused bits.
b = b << (8 - fromBits)
b <<= 8 - fromBits

// How many bits remaining to extract from the input data.
remFromBits := fromBits
Expand All @@ -383,7 +383,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)

// Discard the bits we just extracted and get ready for
// next iteration.
b = b << toExtract
b <<= toExtract
remFromBits -= toExtract
filledBits += toExtract

Expand All @@ -399,7 +399,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)

// We pad any unfinished group if specified.
if pad && filledBits > 0 {
nextByte = nextByte << (toBits - filledBits)
nextByte <<= toBits - filledBits
regrouped = append(regrouped, nextByte)
filledBits = 0
nextByte = 0
Expand Down
2 changes: 1 addition & 1 deletion bloom/merkleblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock,
Flags: make([]byte, (len(mBlock.bits)+7)/8),
}
for _, hash := range mBlock.finalHashes {
msgMerkleBlock.AddTxHash(hash)
_ = msgMerkleBlock.AddTxHash(hash)
}
for i := uint32(0); i < uint32(len(mBlock.bits)); i++ {
msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8)
Expand Down
2 changes: 1 addition & 1 deletion certgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri

addIP := func(ipAddr net.IP) {
for _, ip := range ipAddresses {
if bytes.Equal(ip, ipAddr) {
if ip.Equal(ipAddr) {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion coinset/coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumCon

func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin {
h := sha256.New()
h.Write([]byte(fmt.Sprintf("%d", index)))
_, _ = h.Write([]byte(fmt.Sprintf("%d", index)))
hash, _ := chainhash.NewHash(h.Sum(nil))
c := &TestCoin{
TxHash: hash,
Expand Down
4 changes: 2 additions & 2 deletions gcs/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func RandomKey() ([gcs.KeySize]byte, error) {
}

// Copy the byte slice to a [gcs.KeySize]byte array and return it.
copy(key[:], randKey[:])
copy(key[:], randKey)
return key, nil
}

// DeriveKey is a utility function that derives a key from a chainhash.Hash by
// truncating the bytes of the hash to the appopriate key size.
func DeriveKey(keyHash *chainhash.Hash) [gcs.KeySize]byte {
var key [gcs.KeySize]byte
copy(key[:], keyHash.CloneBytes()[:])
copy(key[:], keyHash.CloneBytes())
return key
}

Expand Down
3 changes: 0 additions & 3 deletions gcs/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
)

var (
// No need to allocate an err variable in every test
err error

// List of values for building a filter
contents = [][]byte{
[]byte("Alex"),
Expand Down
6 changes: 3 additions & 3 deletions gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Filter struct {
// BuildGCSFilter builds a new GCS filter with the collision probability of
// `1/(2**P)`, key `key`, and including every `[]byte` in `data` as a member of
// the set.
func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filter, error) {
func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filter, error) { // nolint:gocritic
// Some initial parameter checks: make sure we have data from which to
// build the filter, and make sure our parameters will fit the hash
// function we're using.
Expand Down Expand Up @@ -174,7 +174,7 @@ func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filte

// FromBytes deserializes a GCS filter from a known N, P, and serialized filter
// as returned by Bytes().
func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) {
func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) { // nolint:gocritic
// Basic sanity check.
if P > 32 {
return nil, ErrPTooBig
Expand All @@ -200,7 +200,7 @@ func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) {

// FromNBytes deserializes a GCS filter from a known P, and serialized N and
// filter as returned by NBytes().
func FromNBytes(P uint8, M uint64, d []byte) (*Filter, error) {
func FromNBytes(P uint8, M uint64, d []byte) (*Filter, error) { // nolint:gocritic
buffer := bytes.NewBuffer(d)
N, err := wire.ReadVarInt(buffer, varIntProtoVer)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion gcs/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
// Filters are conserved between tests but we must define with an
// interface which functions we're testing because the gcsFilter type
// isn't exported
filter, filter2, filter3, filter4, filter5 *gcs.Filter
filter, filter2, filter3 *gcs.Filter

// We need to use the same key for building and querying the filters
key [gcs.KeySize]byte
Expand Down Expand Up @@ -328,6 +328,8 @@ func TestGCSFilterMatchAnySuite(t *testing.T) {
}

for _, test := range funcs {
test := test

t.Run(test.name, func(t *testing.T) {
contentsCopy := make([][]byte, len(contents2))
copy(contentsCopy, contents2)
Expand Down
11 changes: 7 additions & 4 deletions gcs/gcsbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func genRandFilterElements(numElements uint) ([][]byte, error) {

var (
generatedFilter *gcs.Filter
filterErr error
)

// BenchmarkGCSFilterBuild benchmarks building a filter.
Expand Down Expand Up @@ -101,7 +100,7 @@ func BenchmarkGCSFilterMatch(b *testing.B) {

var localMatch bool
for i := 0; i < b.N; i++ {
localMatch, err = filter.Match(key, []byte("Nate"))
_, err = filter.Match(key, []byte("Nate"))
if err != nil {
b.Fatalf("unable to match filter: %v", err)
}
Expand All @@ -115,8 +114,6 @@ func BenchmarkGCSFilterMatch(b *testing.B) {
}

var (
randElems1, _ = genRandFilterElements(1)
randElems10, _ = genRandFilterElements(10)
randElems100, _ = genRandFilterElements(100)
randElems1000, _ = genRandFilterElements(1000)
randElems10000, _ = genRandFilterElements(10000)
Expand Down Expand Up @@ -164,6 +161,8 @@ var matchAnyBenchmarks = []struct {
// BenchmarkGCSFilterMatchAny benchmarks the sort-and-zip MatchAny impl.
func BenchmarkGCSFilterZipMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks {
test := test

b.Run(test.name, func(b *testing.B) {
b.ReportAllocs()

Expand All @@ -188,6 +187,8 @@ func BenchmarkGCSFilterZipMatchAny(b *testing.B) {
// BenchmarkGCSFilterMatchAny benchmarks the hash-join MatchAny impl.
func BenchmarkGCSFilterHashMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks {
test := test

b.Run(test.name, func(b *testing.B) {
b.ReportAllocs()

Expand All @@ -212,6 +213,8 @@ func BenchmarkGCSFilterHashMatchAny(b *testing.B) {
// BenchmarkGCSFilterMatchAny benchmarks the hybrid MatchAny impl.
func BenchmarkGCSFilterMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks {
test := test

b.Run(test.name, func(b *testing.B) {
b.ReportAllocs()

Expand Down
2 changes: 1 addition & 1 deletion hash160.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// Calculate the hash of hasher over buf.
func calcHash(buf []byte, hasher hash.Hash) []byte {
hasher.Write(buf)
_, _ = hasher.Write(buf)
return hasher.Sum(nil)
}

Expand Down
8 changes: 4 additions & 4 deletions hdkeychain/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func BenchmarkDeriveHardened(b *testing.B) {
b.StartTimer()

for i := 0; i < b.N; i++ {
masterKey.Derive(hdkeychain.HardenedKeyStart)
_, _ = masterKey.Derive(hdkeychain.HardenedKeyStart)
}
}

Expand All @@ -41,7 +41,7 @@ func BenchmarkDeriveNormal(b *testing.B) {
b.StartTimer()

for i := 0; i < b.N; i++ {
masterKey.Derive(0)
_, _ = masterKey.Derive(0)
}
}

Expand All @@ -56,15 +56,15 @@ func BenchmarkPrivToPub(b *testing.B) {
b.StartTimer()

for i := 0; i < b.N; i++ {
masterKey.Neuter()
_, _ = masterKey.Neuter()
}
}

// BenchmarkDeserialize benchmarks how long it takes to deserialize a private
// extended key.
func BenchmarkDeserialize(b *testing.B) {
for i := 0; i < b.N; i++ {
hdkeychain.NewKeyFromString(bip0032MasterPriv1)
_, _ = hdkeychain.NewKeyFromString(bip0032MasterPriv1)
}
}

Expand Down
6 changes: 3 additions & 3 deletions hdkeychain/extendedkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (k *ExtendedKey) Derive(i uint32) (*ExtendedKey, error) {
// data:
// I = HMAC-SHA512(Key = chainCode, Data = data)
hmac512 := hmac.New(sha512.New, k.chainCode)
hmac512.Write(data)
_, _ = hmac512.Write(data)
ilr := hmac512.Sum(nil)

// Split "I" into two 32-byte sequences Il and Ir where:
Expand Down Expand Up @@ -380,7 +380,7 @@ func (k *ExtendedKey) DeriveNonStandard(i uint32) (*ExtendedKey, error) {
binary.BigEndian.PutUint32(data[keyLen:], i)

hmac512 := hmac.New(sha512.New, k.chainCode)
hmac512.Write(data)
_, _ = hmac512.Write(data)
ilr := hmac512.Sum(nil)

il := ilr[:len(ilr)/2]
Expand Down Expand Up @@ -610,7 +610,7 @@ func NewMaster(seed []byte, net *chaincfg.Params) (*ExtendedKey, error) {
// First take the HMAC-SHA512 of the master key and the seed data:
// I = HMAC-SHA512(Key = "Bitcoin seed", Data = S)
hmac512 := hmac.New(sha512.New, masterKey)
hmac512.Write(seed)
_, _ = hmac512.Write(seed)
lr := hmac512.Sum(nil)

// Split "I" into two 32-byte sequences Il and Ir where:
Expand Down
2 changes: 1 addition & 1 deletion hdkeychain/extendedkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ func TestZero(t *testing.T) {
wantAddr := "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
addr, err := key.Address(&chaincfg.MainNetParams)
if err != nil {
t.Errorf("Addres s #%d (%s): unexpected error: %v", i,
t.Errorf("Address #%d (%s): unexpected error: %v", i,
testName, err)
return false
}
Expand Down
4 changes: 4 additions & 0 deletions wif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func TestEncodeDecodeWIF(t *testing.T) {
}

for _, validCase := range validEncodeCases {
validCase := validCase

t.Run(validCase.name, func(t *testing.T) {
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), validCase.privateKey)
wif, err := NewWIF(priv, validCase.net, validCase.compress)
Expand Down Expand Up @@ -122,6 +124,8 @@ func TestEncodeDecodeWIF(t *testing.T) {
}

for _, invalidCase := range invalidDecodeCases {
invalidCase := invalidCase

t.Run(invalidCase.name, func(t *testing.T) {
decodedWif, err := DecodeWIF(invalidCase.wif)
if decodedWif != nil {
Expand Down

0 comments on commit 12d7d04

Please sign in to comment.