lotus/miner/testminer.go

37 lines
744 B
Go
Raw Normal View History

2019-09-23 15:27:30 +00:00
package miner
import (
"context"
2019-11-25 04:45:13 +00:00
"github.com/filecoin-project/go-address"
2019-11-25 04:45:13 +00:00
"github.com/filecoin-project/lotus/api"
2019-11-30 23:17:50 +00:00
"github.com/filecoin-project/lotus/chain/gen"
2019-09-23 15:27:30 +00:00
)
2019-11-30 23:17:50 +00:00
func NewTestMiner(nextCh <-chan struct{}, addr address.Address) func(api.FullNode, gen.ElectionPoStProver) *Miner {
return func(api api.FullNode, epp gen.ElectionPoStProver) *Miner {
m := &Miner{
2019-10-09 04:38:59 +00:00
api: api,
waitFunc: chanWaiter(nextCh),
2019-11-30 23:17:50 +00:00
epp: epp,
2019-09-23 15:27:30 +00:00
}
2019-11-30 23:17:50 +00:00
if err := m.Register(addr); err != nil {
panic(err)
}
return m
2019-09-23 15:27:30 +00:00
}
}
2019-12-03 20:00:04 +00:00
func chanWaiter(next <-chan struct{}) func(ctx context.Context, _ uint64) error {
return func(ctx context.Context, _ uint64) error {
2019-09-23 15:27:30 +00:00
select {
case <-ctx.Done():
2019-10-09 04:38:59 +00:00
return ctx.Err()
2019-09-23 15:27:30 +00:00
case <-next:
}
2019-10-09 04:38:59 +00:00
return nil
2019-09-23 15:27:30 +00:00
}
}