From 33a0b57d72ec13d4d76d451895ef29ff5c400df7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Feb 2026 16:14:08 +0000 Subject: [PATCH] chore: use range-over-integer (Go 1.22+) Co-Authored-By: Claude Opus 4.6 --- chain/difficulty.go | 2 +- consensus/pow.go | 2 +- p2p/handshake.go | 2 +- p2p/relay.go | 2 +- tui/explorer_model.go | 2 +- types/address.go | 4 ++-- wallet/mnemonic.go | 2 +- wire/decoder.go | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/chain/difficulty.go b/chain/difficulty.go index 2f4dac9..2862346 100644 --- a/chain/difficulty.go +++ b/chain/difficulty.go @@ -48,7 +48,7 @@ func (c *Chain) NextDifficulty(height uint64, forks []config.HardFork) (uint64, timestamps := make([]uint64, count) cumulDiffs := make([]*big.Int, count) - for i := 0; i < count; i++ { + for i := range count { meta, err := c.getBlockMeta(startHeight + uint64(i)) if err != nil { // Fewer blocks than expected — use what we have. diff --git a/consensus/pow.go b/consensus/pow.go index 76053f6..16586fd 100644 --- a/consensus/pow.go +++ b/consensus/pow.go @@ -27,7 +27,7 @@ func CheckDifficulty(hash types.Hash, difficulty uint64) bool { // Convert hash to big.Int (little-endian as per CryptoNote convention). // Reverse to big-endian for big.Int. var be [32]byte - for i := 0; i < 32; i++ { + for i := range 32 { be[i] = hash[31-i] } hashInt := new(big.Int).SetBytes(be[:]) diff --git a/p2p/handshake.go b/p2p/handshake.go index c0737ff..a6f29cc 100644 --- a/p2p/handshake.go +++ b/p2p/handshake.go @@ -79,7 +79,7 @@ type PeerlistEntry struct { func DecodePeerlist(blob []byte) []PeerlistEntry { n := len(blob) / PeerlistEntrySize entries := make([]PeerlistEntry, n) - for i := 0; i < n; i++ { + for i := range n { off := i * PeerlistEntrySize entries[i] = PeerlistEntry{ IP: binary.LittleEndian.Uint32(blob[off : off+4]), diff --git a/p2p/relay.go b/p2p/relay.go index ed436ca..b184fde 100644 --- a/p2p/relay.go +++ b/p2p/relay.go @@ -252,7 +252,7 @@ func (r *ResponseChainEntry) Decode(data []byte) error { func splitHashes(blob []byte, size int) [][]byte { n := len(blob) / size out := make([][]byte, n) - for i := 0; i < n; i++ { + for i := range n { out[i] = blob[i*size : (i+1)*size] } return out diff --git a/tui/explorer_model.go b/tui/explorer_model.go index 5914fd8..fab64e7 100644 --- a/tui/explorer_model.go +++ b/tui/explorer_model.go @@ -362,7 +362,7 @@ func (m *ExplorerModel) loadBlocks() { } rows := make([]blockRow, count) - for i := 0; i < count; i++ { + for i := range count { h := height - 1 - uint64(i) blk, meta, err := m.chain.GetBlockByHeight(h) if err != nil { diff --git a/types/address.go b/types/address.go index cfe878a..d9a2f25 100644 --- a/types/address.go +++ b/types/address.go @@ -170,7 +170,7 @@ func base58Encode(data []byte) string { fullBlocks := len(data) / 8 lastBlockSize := len(data) % 8 - for i := 0; i < fullBlocks; i++ { + for i := range fullBlocks { block := data[i*8 : (i+1)*8] encoded := encodeBlock(block, 11) result = append(result, encoded...) @@ -227,7 +227,7 @@ func base58Decode(s string) ([]byte, error) { var result []byte - for i := 0; i < fullBlocks; i++ { + for i := range fullBlocks { blockStr := s[i*11 : (i+1)*11] decoded, err := decodeBlock(blockStr, 8) if err != nil { diff --git a/wallet/mnemonic.go b/wallet/mnemonic.go index 91856c0..2bc1fff 100644 --- a/wallet/mnemonic.go +++ b/wallet/mnemonic.go @@ -49,7 +49,7 @@ func MnemonicDecode(phrase string) ([32]byte, error) { n := uint32(numWords) - for i := 0; i < 8; i++ { + for i := range 8 { w1, ok1 := wordIndex[words[i*3]] w2, ok2 := wordIndex[words[i*3+1]] w3, ok3 := wordIndex[words[i*3+2]] diff --git a/wire/decoder.go b/wire/decoder.go index d9c824b..94b5987 100644 --- a/wire/decoder.go +++ b/wire/decoder.go @@ -55,7 +55,7 @@ func (d *Decoder) ReadVarint() uint64 { } var val uint64 var shift uint - for i := 0; i < MaxVarintLen; i++ { + for range MaxVarintLen { _, d.err = io.ReadFull(d.r, d.buf[:1]) if d.err != nil { return 0