mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 23:42:20 +08:00

@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: Brian Tiger Chow <brian@perfmode.com>
26 lines
470 B
Go
26 lines
470 B
Go
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
|
|
}
|