@@ -32,7 +32,7 @@ func (c *ChunkStore) Get(_ context.Context, addr swarm.Address) (swarm.Chunk, er
32
32
c .mu .Lock ()
33
33
defer c .mu .Unlock ()
34
34
35
- chunk , ok := c .chunks [addr . ByteString ( )]
35
+ chunk , ok := c .chunks [c . key ( addr )]
36
36
if ! ok {
37
37
return nil , storage .ErrNotFound
38
38
}
@@ -43,12 +43,12 @@ func (c *ChunkStore) Put(_ context.Context, ch swarm.Chunk) error {
43
43
c .mu .Lock ()
44
44
defer c .mu .Unlock ()
45
45
46
- chunkCount , ok := c .chunks [ch .Address (). ByteString ( )]
46
+ chunkCount , ok := c .chunks [c . key ( ch .Address ())]
47
47
if ! ok {
48
48
chunkCount .chunk = swarm .NewChunk (ch .Address (), ch .Data ()).WithStamp (ch .Stamp ())
49
49
}
50
50
chunkCount .count ++
51
- c .chunks [ch .Address (). ByteString ( )] = chunkCount
51
+ c .chunks [c . key ( ch .Address ())] = chunkCount
52
52
53
53
return nil
54
54
}
@@ -57,7 +57,7 @@ func (c *ChunkStore) Has(_ context.Context, addr swarm.Address) (bool, error) {
57
57
c .mu .Lock ()
58
58
defer c .mu .Unlock ()
59
59
60
- _ , exists := c .chunks [addr . ByteString ( )]
60
+ _ , exists := c .chunks [c . key ( addr )]
61
61
62
62
return exists , nil
63
63
}
@@ -66,12 +66,12 @@ func (c *ChunkStore) Delete(_ context.Context, addr swarm.Address) error {
66
66
c .mu .Lock ()
67
67
defer c .mu .Unlock ()
68
68
69
- chunkCount := c .chunks [addr . ByteString ( )]
69
+ chunkCount := c .chunks [c . key ( addr )]
70
70
chunkCount .count --
71
71
if chunkCount .count <= 0 {
72
72
delete (c .chunks , addr .ByteString ())
73
73
} else {
74
- c .chunks [addr . ByteString ( )] = chunkCount
74
+ c .chunks [c . key ( addr )] = chunkCount
75
75
}
76
76
77
77
return nil
@@ -81,12 +81,12 @@ func (c *ChunkStore) Replace(_ context.Context, ch swarm.Chunk, emplace bool) er
81
81
c .mu .Lock ()
82
82
defer c .mu .Unlock ()
83
83
84
- chunkCount := c .chunks [ch .Address (). ByteString ( )]
84
+ chunkCount := c .chunks [c . key ( ch .Address ())]
85
85
chunkCount .chunk = ch
86
86
if emplace {
87
87
chunkCount .count ++
88
88
}
89
- c .chunks [ch .Address (). ByteString ( )] = chunkCount
89
+ c .chunks [c . key ( ch .Address ())] = chunkCount
90
90
91
91
return nil
92
92
}
@@ -111,3 +111,10 @@ func (c *ChunkStore) Iterate(_ context.Context, fn storage.IterateChunkFn) error
111
111
func (c * ChunkStore ) Close () error {
112
112
return nil
113
113
}
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