From 4e6f53ac3360c4e90fdb419e7073e4316b2a49f7 Mon Sep 17 00:00:00 2001 From: Javier Peletier Date: Wed, 12 Dec 2018 16:22:17 +0100 Subject: swarm/storage: simplify ChunkValidator interface (#18285) --- swarm/storage/types.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'swarm/storage/types.go') diff --git a/swarm/storage/types.go b/swarm/storage/types.go index 42557766e..e5c5f89a0 100644 --- a/swarm/storage/types.go +++ b/swarm/storage/types.go @@ -327,7 +327,7 @@ func (c ChunkData) Data() []byte { } type ChunkValidator interface { - Validate(addr Address, data []byte) bool + Validate(chunk Chunk) bool } // Provides method for validation of content address in chunks @@ -344,7 +344,8 @@ func NewContentAddressValidator(hasher SwarmHasher) *ContentAddressValidator { } // Validate that the given key is a valid content address for the given data -func (v *ContentAddressValidator) Validate(addr Address, data []byte) bool { +func (v *ContentAddressValidator) Validate(chunk Chunk) bool { + data := chunk.Data() if l := len(data); l < 9 || l > ch.DefaultSize+8 { // log.Error("invalid chunk size", "chunk", addr.Hex(), "size", l) return false @@ -355,7 +356,7 @@ func (v *ContentAddressValidator) Validate(addr Address, data []byte) bool { hasher.Write(data[8:]) hash := hasher.Sum(nil) - return bytes.Equal(hash, addr[:]) + return bytes.Equal(hash, chunk.Address()) } type ChunkStore interface { -- cgit v1.2.3