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