diff --git a/block/block.go b/block/block.go deleted file mode 100644 index da3e73d2b..000000000 --- a/block/block.go +++ /dev/null @@ -1,10 +0,0 @@ -package block - -import ( - "github.com/jbenet/go-multihash" -) - -type Block struct { - Multihash []byte - Data []byte -} diff --git a/blocks/blocks.go b/blocks/blocks.go index 284e555ff..8d5f64e05 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -39,9 +39,10 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) { return &BlockService{Datastore: d}, nil } -func (s *BlockService) AddBlock(b *Block) error { - dsk := ds.NewKey(string(b.Key())) - return s.Datastore.Put(dsk, b.Data) +func (s *BlockService) AddBlock(b *Block) (u.Key, error) { + k := b.Key() + dsk := ds.NewKey(string(k)) + return k, s.Datastore.Put(dsk, b.Data) } func (s *BlockService) GetBlock(k u.Key) (*Block, error) { diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 6ee6c3d36..ec3738330 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -37,12 +37,16 @@ func TestBlocks(t *testing.T) { t.Error("Block key and data multihash key not equal") } - err = bs.AddBlock(b) + k, err := bs.AddBlock(b) if err != nil { t.Error("failed to add block to BlockService", err) return } + if k != b.Key() { + t.Error("returned key is not equal to block key", err) + } + b2, err := bs.GetBlock(b.Key()) if err != nil { t.Error("failed to retrieve block from BlockService", err)