@@ -32,7 +32,7 @@ func (c *ChunkStore) Get(_ context.Context, addr swarm.Address) (swarm.Chunk, er
3232 c .mu .Lock ()
3333 defer c .mu .Unlock ()
3434
35- chunk , ok := c .chunks [addr . ByteString ( )]
35+ chunk , ok := c .chunks [c . key ( addr )]
3636 if ! ok {
3737 return nil , storage .ErrNotFound
3838 }
@@ -43,12 +43,12 @@ func (c *ChunkStore) Put(_ context.Context, ch swarm.Chunk) error {
4343 c .mu .Lock ()
4444 defer c .mu .Unlock ()
4545
46- chunkCount , ok := c .chunks [ch .Address (). ByteString ( )]
46+ chunkCount , ok := c .chunks [c . key ( ch .Address ())]
4747 if ! ok {
4848 chunkCount .chunk = swarm .NewChunk (ch .Address (), ch .Data ()).WithStamp (ch .Stamp ())
4949 }
5050 chunkCount .count ++
51- c .chunks [ch .Address (). ByteString ( )] = chunkCount
51+ c .chunks [c . key ( ch .Address ())] = chunkCount
5252
5353 return nil
5454}
@@ -57,7 +57,7 @@ func (c *ChunkStore) Has(_ context.Context, addr swarm.Address) (bool, error) {
5757 c .mu .Lock ()
5858 defer c .mu .Unlock ()
5959
60- _ , exists := c .chunks [addr . ByteString ( )]
60+ _ , exists := c .chunks [c . key ( addr )]
6161
6262 return exists , nil
6363}
@@ -66,12 +66,12 @@ func (c *ChunkStore) Delete(_ context.Context, addr swarm.Address) error {
6666 c .mu .Lock ()
6767 defer c .mu .Unlock ()
6868
69- chunkCount := c .chunks [addr . ByteString ( )]
69+ chunkCount := c .chunks [c . key ( addr )]
7070 chunkCount .count --
7171 if chunkCount .count <= 0 {
7272 delete (c .chunks , addr .ByteString ())
7373 } else {
74- c .chunks [addr . ByteString ( )] = chunkCount
74+ c .chunks [c . key ( addr )] = chunkCount
7575 }
7676
7777 return nil
@@ -81,12 +81,12 @@ func (c *ChunkStore) Replace(_ context.Context, ch swarm.Chunk, emplace bool) er
8181 c .mu .Lock ()
8282 defer c .mu .Unlock ()
8383
84- chunkCount := c .chunks [ch .Address (). ByteString ( )]
84+ chunkCount := c .chunks [c . key ( ch .Address ())]
8585 chunkCount .chunk = ch
8686 if emplace {
8787 chunkCount .count ++
8888 }
89- c .chunks [ch .Address (). ByteString ( )] = chunkCount
89+ c .chunks [c . key ( ch .Address ())] = chunkCount
9090
9191 return nil
9292}
@@ -111,3 +111,10 @@ func (c *ChunkStore) Iterate(_ context.Context, fn storage.IterateChunkFn) error
111111func (c * ChunkStore ) Close () error {
112112 return nil
113113}
114+
115+ func (c * ChunkStore ) key (addr swarm.Address ) string {
116+ if len (addr .Bytes ()) < swarm .HashSize {
117+ return addr .ByteString ()
118+ }
119+ return string (addr .Bytes ()[:swarm .HashSize ])
120+ }
0 commit comments