2020-02-11 20:48:03 +00:00
|
|
|
package genesis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-05-26 10:33:08 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
2020-02-11 20:48:03 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
bstore "github.com/filecoin-project/lotus/blockstore"
|
2020-02-11 20:48:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2021-05-26 10:33:08 +00:00
|
|
|
func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) {
|
|
|
|
store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs))
|
|
|
|
|
|
|
|
a, err := adt.MakeEmptyArray(store).Root()
|
2020-02-11 20:48:03 +00:00
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, err
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
2021-05-26 10:33:08 +00:00
|
|
|
h, err := adt.MakeEmptyMap(store).Root()
|
2020-02-21 16:57:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 10:33:08 +00:00
|
|
|
sms := market.ConstructState(a, h, h)
|
|
|
|
|
|
|
|
stcid, err := store.Put(store.Context(), sms)
|
2020-02-11 20:48:03 +00:00
|
|
|
if err != nil {
|
2020-02-12 00:58:55 +00:00
|
|
|
return nil, err
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
act := &types.Actor{
|
2021-05-26 10:33:08 +00:00
|
|
|
Code: builtin.StorageMarketActorCodeID,
|
|
|
|
Head: stcid,
|
|
|
|
Balance: types.NewInt(0),
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 00:58:55 +00:00
|
|
|
return act, nil
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|