mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 06:47:51 +08:00
block get returned.
This commit is contained in:
parent
a5241b767b
commit
015398846f
@ -1,10 +0,0 @@
|
||||
package block
|
||||
|
||||
import (
|
||||
"github.com/jbenet/go-multihash"
|
||||
)
|
||||
|
||||
type Block struct {
|
||||
Multihash []byte
|
||||
Data []byte
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user