block get returned.

This commit is contained in:
Juan Batiz-Benet 2014-07-05 15:38:17 -07:00
parent a5241b767b
commit 015398846f
3 changed files with 9 additions and 14 deletions

View File

@ -1,10 +0,0 @@
package block
import (
"github.com/jbenet/go-multihash"
)
type Block struct {
Multihash []byte
Data []byte
}

View File

@ -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) {

View File

@ -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)