block get returned.
Juan Batiz-Benet committed
Jul 5, 2014 at 15:38 UTC
015398846f27efe1d3d4399050e19e4e1e392ad2
3 files changed
+9
-14
block/block.go
deleted
-10
@@ -1,10 +0,0 @@
1
-package block
2
-
3
-import (
4
- "github.com/jbenet/go-multihash"
5
-)
6
-
7
-type Block struct {
8
- Multihash []byte
9
- Data []byte
10
-}
blocks/blocks.go
+4
-3
@@ -39,9 +39,10 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) {
39
return &BlockService{Datastore: d}, nil
40
}
41
42
-func (s *BlockService) AddBlock(b *Block) error {
43
- dsk := ds.NewKey(string(b.Key()))
44
- return s.Datastore.Put(dsk, b.Data)
42
+func (s *BlockService) AddBlock(b *Block) (u.Key, error) {
43
+ k := b.Key()
44
+ dsk := ds.NewKey(string(k))
45
+ return k, s.Datastore.Put(dsk, b.Data)
46
}
47
48
func (s *BlockService) GetBlock(k u.Key) (*Block, error) {
blocks/blocks_test.go
+5
-1
@@ -37,12 +37,16 @@ func TestBlocks(t *testing.T) {
37
t.Error("Block key and data multihash key not equal")
38
}
39
40
- err = bs.AddBlock(b)
40
+ k, err := bs.AddBlock(b)
41
if err != nil {
42
t.Error("failed to add block to BlockService", err)
43
return
44
}
45
46
+ if k != b.Key() {
47
+ t.Error("returned key is not equal to block key", err)
48
+ }
49
+
50
b2, err := bs.GetBlock(b.Key())
51
if err != nil {
52
t.Error("failed to retrieve block from BlockService", err)