lotus/chain/gen/genesis/t04_power.go
2020-07-28 18:16:56 +02:00

47 lines
1.0 KiB
Go

package genesis
import (
"context"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/types"
bstore "github.com/filecoin-project/lotus/lib/blockstore"
)
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs))
emptyMap, err := adt.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
multiMap, err := adt.AsMultimap(store, emptyMap)
if err != nil {
return nil, err
}
emptyMultiMap, err := multiMap.Root()
if err != nil {
return nil, err
}
sms := power.ConstructState(emptyMap, emptyMultiMap)
stcid, err := store.Put(store.Context(), sms)
if err != nil {
return nil, err
}
return &types.Actor{
Code: builtin.StoragePowerActorCodeID,
Head: stcid,
Nonce: 0,
Balance: types.NewInt(0),
}, nil
}