Commit 7e736763 authored by Jeromy's avatar Jeromy

address comments from PR

parent d1dd0be3
package blocks package blocks
import ( import (
"errors"
"fmt" "fmt"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
...@@ -18,6 +19,16 @@ func NewBlock(data []byte) *Block { ...@@ -18,6 +19,16 @@ func NewBlock(data []byte) *Block {
return &Block{Data: data, Multihash: u.Hash(data)} return &Block{Data: data, Multihash: u.Hash(data)}
} }
func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) {
if u.Debug {
chk := u.Hash(data)
if string(chk) != string(h) {
return nil, errors.New("Data did not match given hash!")
}
}
return &Block{Data: data, Multihash: h}, nil
}
// Key returns the block's Multihash as a Key value. // Key returns the block's Multihash as a Key value.
func (b *Block) Key() u.Key { func (b *Block) Key() u.Key {
return u.Key(b.Multihash) return u.Key(b.Multihash)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment