2019-11-05 03:42:13 +00:00
|
|
|
package sectorbuilder
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TempSectorbuilder(sectorSize uint64) (*SectorBuilder, func(), error) {
|
|
|
|
dir, err := ioutil.TempDir("", "sbtest")
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata := filepath.Join(dir, "meta")
|
|
|
|
sealed := filepath.Join(dir, "sealed")
|
|
|
|
staging := filepath.Join(dir, "staging")
|
2019-11-05 17:53:19 +00:00
|
|
|
cache := filepath.Join(dir, "cache")
|
2019-11-05 03:42:13 +00:00
|
|
|
|
2019-11-05 17:53:19 +00:00
|
|
|
sb, err := New(&Config{
|
2019-11-05 03:42:13 +00:00
|
|
|
SectorSize: sectorSize,
|
|
|
|
SealedDir: sealed,
|
|
|
|
StagedDir: staging,
|
|
|
|
MetadataDir: metadata,
|
2019-11-05 17:53:19 +00:00
|
|
|
CacheDir: cache,
|
|
|
|
|
|
|
|
WorkerThreads: 2,
|
2019-11-05 18:40:51 +00:00
|
|
|
Miner: addr,
|
2019-11-05 03:42:13 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb, func() {
|
|
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
|
|
log.Warn("failed to clean up temp sectorbuilder: ", err)
|
|
|
|
}
|
|
|
|
}, nil
|
|
|
|
}
|