Commit c5917bc1 authored by Kevin Atkinson's avatar Kevin Atkinson

Make blocks.Block an interface.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 0a178a49
......@@ -52,13 +52,13 @@ func (n *dagService) Add(nd *Node) (key.Key, error) {
return "", err
}
b := new(blocks.Block)
b.Data = d
b.Multihash, err = nd.Multihash()
mh, err := nd.Multihash()
if err != nil {
return "", err
}
b, _ := blocks.NewBlockWithHash(d, mh)
return n.Blocks.AddBlock(b)
}
......@@ -82,7 +82,7 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
return nil, fmt.Errorf("Failed to get block for %s: %v", k.B58String(), err)
}
res, err := DecodeProtobuf(b.Data)
res, err := DecodeProtobuf(b.Data())
if err != nil {
return nil, fmt.Errorf("Failed to decode Protocol Buffers: %v", err)
}
......@@ -135,7 +135,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []key.Key) <-chan *NodeO
}
return
}
nd, err := DecodeProtobuf(b.Data)
nd, err := DecodeProtobuf(b.Data())
if err != nil {
out <- &NodeOption{Err: err}
return
......@@ -316,7 +316,7 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
type Batch struct {
ds *dagService
blocks []*blocks.Block
blocks []blocks.Block
size int
MaxSize int
}
......@@ -327,17 +327,17 @@ func (t *Batch) Add(nd *Node) (key.Key, error) {
return "", err
}
b := new(blocks.Block)
b.Data = d
b.Multihash, err = nd.Multihash()
mh, err := nd.Multihash()
if err != nil {
return "", err
}
k := key.Key(b.Multihash)
b, _ := blocks.NewBlockWithHash(d, mh)
k := key.Key(mh)
t.blocks = append(t.blocks, b)
t.size += len(b.Data)
t.size += len(b.Data())
if t.size > t.MaxSize {
return k, t.Commit()
}
......
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