44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package genesis
|
|
|
|
import (
|
|
"context"
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
bstore "github.com/filecoin-project/lotus/blockstore"
|
|
"github.com/filecoin-project/lotus/build"
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
)
|
|
|
|
func SetupRewardActor(ctx context.Context, bs bstore.Blockstore, qaPower big.Int, av actors.Version) (*types.Actor, error) {
|
|
cst := cbor.NewCborStore(bs)
|
|
rst, err := reward.MakeState(adt.WrapStore(ctx, cst), av, qaPower)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
statecid, err := cst.Put(ctx, rst.GetState())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
actcid, ok := actors.GetActorCodeID(av, actors.RewardKey)
|
|
if !ok {
|
|
return nil, xerrors.Errorf("failed to get reward actor code ID for actors version %d", av)
|
|
}
|
|
|
|
act := &types.Actor{
|
|
Code: actcid,
|
|
Balance: types.BigInt{Int: build.InitialRewardBalance},
|
|
Head: statecid,
|
|
}
|
|
|
|
return act, nil
|
|
}
|