1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

use batching transaction interface from datastore

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-06-26 09:44:00 -07:00
parent f6f9cae4e4
commit 137c0ac4ac
39 changed files with 857 additions and 1546 deletions

View File

@ -77,6 +77,22 @@ func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
return k, nil
}
func (s *BlockService) AddBlocks(bs []*blocks.Block) ([]key.Key, error) {
err := s.Blockstore.PutMany(bs)
if err != nil {
return nil, err
}
var ks []key.Key
for _, b := range bs {
if err := s.worker.HasBlock(b); err != nil {
return nil, errors.New("blockservice is closed")
}
ks = append(ks, b.Key())
}
return ks, nil
}
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block, error) {