2020-02-11 20:48:03 +00:00
|
|
|
package genesis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
|
|
|
bstore "github.com/ipfs/go-ipfs-blockstore"
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-02-12 00:58:55 +00:00
|
|
|
"github.com/filecoin-project/lotus/genesis"
|
2020-02-11 20:48:03 +00:00
|
|
|
)
|
|
|
|
|
2020-02-12 00:58:55 +00:00
|
|
|
func SetupStorageMarketActor(bs bstore.Blockstore, miners []genesis.Miner) (*types.Actor, error) {
|
2020-02-11 20:48:03 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
cst := cbor.NewCborStore(bs)
|
|
|
|
ast := store.ActorStore(context.TODO(), bs)
|
|
|
|
|
|
|
|
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
|
|
|
sdeals := make([]cbg.CBORMarshaler, len(deals))
|
|
|
|
for i, deal := range deals {
|
|
|
|
d := deal // copy
|
|
|
|
|
|
|
|
cdeals[i] = &d
|
|
|
|
sdeals[i] = &market.DealState{
|
|
|
|
SectorStartEpoch: 1,
|
|
|
|
LastUpdatedEpoch: -1,
|
|
|
|
SlashEpoch: -1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dealAmt, err := amt.FromArray(ctx, cst, cdeals)
|
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, xerrors.Errorf("amt build failed: %w", err)
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stateAmt, err := amt.FromArray(ctx, cst, sdeals)
|
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, xerrors.Errorf("amt build failed: %w", err)
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sms, err := market.ConstructState(ast)
|
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, err
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sms.Proposals = dealAmt
|
|
|
|
sms.States = stateAmt
|
|
|
|
|
|
|
|
stcid, err := cst.Put(context.TODO(), sms)
|
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, err
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: MARKET BALANCES!!!!!!111
|
|
|
|
|
|
|
|
act := &types.Actor{
|
|
|
|
Code: actors.StorageMarketCodeCid,
|
|
|
|
Head: stcid,
|
|
|
|
Balance: types.NewInt(0),
|
|
|
|
}
|
|
|
|
|
2020-02-12 00:58:55 +00:00
|
|
|
return act, nil
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|