lotus/chain/gen/genesis/f04_power.go

47 lines
1.0 KiB
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"context"
2020-02-25 20:54:58 +00:00
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/util/adt"
2020-02-11 20:48:03 +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"
bstore "github.com/filecoin-project/lotus/lib/blockstore"
2020-02-11 20:48:03 +00:00
)
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
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
}
sms := power0.ConstructState(emptyMap, emptyMultiMap)
2020-07-28 16:16:46 +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
}