github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/chunks/handle_check_hashes.go (about) 1 // Copyright 2021 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 5 package chunksPkg 6 7 import ( 8 "fmt" 9 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 12 ) 13 14 // CheckHashes looks at all the hashes in both the locally cached manifest and the manifest retrieved from 15 // the smart contract and simply checks the lengths of the bloom and index IPFS hashes. 16 func (opts *ChunksOptions) CheckHashes(cacheMan *manifest.Manifest, contractMan *manifest.Manifest, report *types.ReportCheck) error { 17 if err := opts.checkHashes("cache", cacheMan, report); err != nil { 18 return err 19 } 20 21 if err := opts.checkHashes("contract", contractMan, report); err != nil { 22 return err 23 } 24 25 return nil 26 } 27 28 func (opts *ChunksOptions) checkHashes(which string, man *manifest.Manifest, report *types.ReportCheck) error { 29 for _, chunk := range man.Chunks { 30 report.VisitedCnt++ 31 report.CheckedCnt++ 32 if len(chunk.BloomHash) != 46 { 33 msg := fmt.Sprintf("%s: Invalid BloomHash (%s) in %s", chunk.Range, chunk.BloomHash, which) 34 if len(chunk.BloomHash) == 0 { 35 msg = fmt.Sprintf("%s: Empty BloomHash in %s", chunk.Range, which) 36 } 37 report.MsgStrings = append(report.MsgStrings, msg) 38 } else { 39 report.PassedCnt++ 40 } 41 42 report.VisitedCnt++ 43 report.CheckedCnt++ 44 if len(chunk.IndexHash) != 46 { 45 msg := fmt.Sprintf("%s: Invalid IndexHash (%s) in %s", chunk.Range, chunk.IndexHash, which) 46 if len(chunk.IndexHash) == 0 { 47 msg = fmt.Sprintf("%s: Empty IndexHash in %s", chunk.Range, which) 48 } 49 report.MsgStrings = append(report.MsgStrings, msg) 50 } else { 51 report.PassedCnt++ 52 } 53 } 54 55 return nil 56 }