github.com/0xsequence/ethkit@v1.25.0/ethutil/validate_logs_with_block.go (about) 1 package ethutil 2 3 import ( 4 "bytes" 5 6 "github.com/0xsequence/ethkit/go-ethereum/core/types" 7 ) 8 9 // ValidateLogsWithBlockHeader validates that the logs comes from given block. 10 // If the list of logs is not complete or the logs are not from the block, it 11 // will return false. 12 func ValidateLogsWithBlockHeader(logs []types.Log, header *types.Header) bool { 13 return bytes.Compare(logsToBloom(logs).Bytes(), header.Bloom.Bytes()) == 0 14 } 15 16 func logsToBloom(logs []types.Log) types.Bloom { 17 var logBloom types.Bloom 18 for _, log := range logs { 19 logBloom.Add(log.Address.Bytes()) 20 for _, b := range log.Topics { 21 logBloom.Add(b[:]) 22 } 23 } 24 return logBloom 25 }