2020-01-13 20:47:27 +00:00
|
|
|
package sbmock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-02-10 19:16:36 +00:00
|
|
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-02-18 07:15:30 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
2020-01-13 20:47:27 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
|
|
|
"github.com/filecoin-project/lotus/genesis"
|
|
|
|
)
|
|
|
|
|
2020-02-18 07:15:30 +00:00
|
|
|
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, error) {
|
|
|
|
k, err := wallet.GenerateKey(crypto.SigTypeBLS)
|
2020-01-13 20:47:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-02-18 07:15:30 +00:00
|
|
|
genm := &genesis.Miner{
|
2020-01-13 20:47:27 +00:00
|
|
|
Owner: k.Address,
|
|
|
|
Worker: k.Address,
|
|
|
|
SectorSize: ssize,
|
|
|
|
Sectors: make([]*genesis.PreSeal, sectors),
|
2020-02-18 07:15:30 +00:00
|
|
|
//Key: k.KeyInfo,
|
2020-01-13 20:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range genm.Sectors {
|
|
|
|
preseal := &genesis.PreSeal{}
|
2020-02-10 19:16:36 +00:00
|
|
|
sdata := randB(uint64(abi.PaddedPieceSize(ssize).Unpadded()))
|
2020-01-13 20:47:27 +00:00
|
|
|
|
|
|
|
preseal.CommD = commD(sdata)
|
|
|
|
preseal.CommR = commDR(preseal.CommD[:])
|
2020-02-10 19:16:36 +00:00
|
|
|
preseal.SectorID = abi.SectorNumber(i + 1)
|
2020-01-13 20:47:27 +00:00
|
|
|
preseal.Deal = actors.StorageDealProposal{
|
2020-02-10 19:16:36 +00:00
|
|
|
PieceCID: commcid.PieceCommitmentV1ToCID(preseal.CommD[:]),
|
|
|
|
PieceSize: abi.PaddedPieceSize(ssize),
|
2020-01-13 20:47:27 +00:00
|
|
|
Client: maddr,
|
|
|
|
Provider: maddr,
|
2020-02-10 19:16:36 +00:00
|
|
|
StartEpoch: 1,
|
|
|
|
EndEpoch: math.MaxInt64,
|
2020-01-13 20:47:27 +00:00
|
|
|
StoragePricePerEpoch: types.NewInt(0),
|
2020-02-10 19:16:36 +00:00
|
|
|
ProviderCollateral: types.NewInt(0),
|
2020-01-13 20:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
genm.Sectors[i] = preseal
|
|
|
|
}
|
|
|
|
|
|
|
|
return genm, nil
|
2020-01-14 02:04:33 +00:00
|
|
|
}
|