2020-02-11 20:48:03 +00:00
|
|
|
package genesis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-23 00:14:54 +00:00
|
|
|
|
2020-02-25 20:54:58 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-07-23 00:14:54 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
2020-02-11 20:48:03 +00:00
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
2020-02-11 20:48:03 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-07-23 02:05:11 +00:00
|
|
|
bstore "github.com/filecoin-project/lotus/lib/blockstore"
|
2020-02-11 20:48:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
2020-07-23 00:14:54 +00:00
|
|
|
store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs))
|
2020-07-28 16:16:46 +00:00
|
|
|
emptyMap, err := adt.MakeEmptyMap(store).Root()
|
2020-02-11 20:48:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-28 16:16:46 +00:00
|
|
|
multiMap, err := adt.AsMultimap(store, emptyMap)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-02-11 20:48:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 16:16:46 +00:00
|
|
|
emptyMultiMap, err := multiMap.Root()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
sms := power0.ConstructState(emptyMap, emptyMultiMap)
|
2020-07-28 16:16:46 +00:00
|
|
|
|
2020-07-23 00:14:54 +00:00
|
|
|
stcid, err := store.Put(store.Context(), sms)
|
2020-02-11 20:48:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Actor{
|
2020-02-25 20:54:58 +00:00
|
|
|
Code: builtin.StoragePowerActorCodeID,
|
2020-02-11 20:48:03 +00:00
|
|
|
Head: stcid,
|
|
|
|
Nonce: 0,
|
|
|
|
Balance: types.NewInt(0),
|
|
|
|
}, nil
|
|
|
|
}
|