Skip to content

Commit

Permalink
Merge pull request #3187 from ipfs/feat/cidv0
Browse files Browse the repository at this point in the history
Rework go-ipfs to use content IDs version 0
  • Loading branch information
whyrusleeping committed Sep 9, 2016
2 parents 3dc57fc + 22ebb79 commit 4aeb40b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
"fmt"

key "github.com/ipfs/go-ipfs/blocks/key"

mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
cid "gx/ipfs/QmfSc2xehWmWLnwwYR91Y8QF4xdASypTFVknutoKQS3GHp/go-cid"
)

var ErrWrongHash = errors.New("data did not match given hash!")

type Block interface {
Multihash() mh.Multihash
Data() []byte
RawData() []byte
Key() key.Key
String() string
Loggable() map[string]interface{}
Expand Down Expand Up @@ -49,10 +51,14 @@ func (b *BasicBlock) Multihash() mh.Multihash {
return b.multihash
}

func (b *BasicBlock) Data() []byte {
func (b *BasicBlock) RawData() []byte {
return b.data
}

func (b *BasicBlock) Cid() *cid.Cid {
return cid.NewCidV0(b.multihash)
}

// Key returns the block's Multihash as a Key value.
func (b *BasicBlock) Key() key.Key {
return key.Key(b.multihash)
Expand Down
2 changes: 1 addition & 1 deletion blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestData(t *testing.T) {
data := []byte("some data")
block := NewBlock(data)

if !bytes.Equal(block.Data(), data) {
if !bytes.Equal(block.RawData(), data) {
t.Error("data is wrong")
}
}
Expand Down

0 comments on commit 4aeb40b

Please sign in to comment.