Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

WIP: Modify blockservice to work with Multihashes instead of CIDs. #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
exchange "github.com/ipfs/go-ipfs-exchange-interface"
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-verifcid"
mh "github.com/multiformats/go-multihash"
)

var log = logging.Logger("blockservice")
Expand Down Expand Up @@ -59,7 +60,7 @@ type BlockService interface {
AddBlocks(bs []blocks.Block) error

// DeleteBlock deletes the given block from the blockservice.
DeleteBlock(o cid.Cid) error
DeleteBlock(o mh.Multihash) error
}

type blockService struct {
Expand Down Expand Up @@ -138,7 +139,7 @@ func (s *blockService) AddBlock(o blocks.Block) error {
return err
}
if s.checkFirst {
if has, err := s.blockstore.Has(c); has || err != nil {
if has, err := s.blockstore.Has(c.Hash()); has || err != nil {
return err
}
}
Expand Down Expand Up @@ -169,7 +170,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
if s.checkFirst {
toput = make([]blocks.Block, 0, len(bs))
for _, b := range bs {
has, err := s.blockstore.Has(b.Cid())
has, err := s.blockstore.Has(b.Cid().Hash())
if err != nil {
return err
}
Expand Down Expand Up @@ -312,10 +313,11 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
}

// DeleteBlock deletes a block in the blockservice from the datastore
func (s *blockService) DeleteBlock(c cid.Cid) error {
err := s.blockstore.DeleteBlock(c)
func (s *blockService) DeleteBlock(k mh.Multihash) error {
err := s.blockstore.Delete(k)
if err == nil {
log.Event(context.TODO(), "BlockService.BlockDeleted", c)
// FIXME: mh not Loggable
//log.Event(context.TODO(), "BlockService.BlockDeleted", k)
}
return err
}
Expand Down