Commit d691c1b1 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Jeromy

refactor(util) move block generator

@whyrusleeping @jbenet

Putting the block generator in a util dir until blocks.

Can't put it in util/testutil because the util/testutil/dag-generator
imports blockservice and blockservice uses the generator.

Tough problem. This'll do for now.

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parents
package blocksutil
import "github.com/jbenet/go-ipfs/blocks"
func NewBlockGenerator() BlockGenerator {
return BlockGenerator{}
}
type BlockGenerator struct {
seq int
}
func (bg *BlockGenerator) Next() *blocks.Block {
bg.seq++
return blocks.NewBlock([]byte(string(bg.seq)))
}
func (bg *BlockGenerator) Blocks(n int) []*blocks.Block {
blocks := make([]*blocks.Block, 0)
for i := 0; i < n; i++ {
b := bg.Next()
blocks = append(blocks, b)
}
return blocks
}
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