lotus/chain/actors/builtin/builtin.go.template

145 lines
4.0 KiB
Plaintext
Raw Normal View History

2021-05-06 04:17:35 +00:00
package builtin
import (
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing"
{{end}}
2021-05-06 04:17:35 +00:00
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
miner{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/miner"
proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof"
2021-05-06 04:17:35 +00:00
)
var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr
var BurntFundsActorAddr = builtin{{.latestVersion}}.BurntFundsActorAddr
var CronActorAddr = builtin{{.latestVersion}}.CronActorAddr
var SaftAddress = makeAddress("t0122")
var ReserveAddress = makeAddress("t090")
var RootVerifierAddress = makeAddress("t080")
var (
ExpectedLeadersPerEpoch = builtin{{.latestVersion}}.ExpectedLeadersPerEpoch
)
const (
EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds
EpochsInDay = builtin{{.latestVersion}}.EpochsInDay
SecondsInDay = builtin{{.latestVersion}}.SecondsInDay
2021-05-06 04:17:35 +00:00
)
const (
MethodSend = builtin{{.latestVersion}}.MethodSend
2021-05-06 04:17:35 +00:00
MethodConstructor = builtin{{.latestVersion}}.MethodConstructor
)
// These are all just type aliases across actor versions. In the future, that might change
// and we might need to do something fancier.
type SectorInfo = proof{{.latestVersion}}.SectorInfo
type PoStProof = proof{{.latestVersion}}.PoStProof
type FilterEstimate = smoothing0.FilterEstimate
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
return miner{{.latestVersion}}.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
}
{{range .versions}}
func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate {
2021-05-06 04:17:35 +00:00
{{if (eq . 0)}}
return (FilterEstimate)(v{{.}}) //nolint:unconvert
{{else}}
return (FilterEstimate)(v{{.}})
{{end}}
}
2021-05-06 04:17:35 +00:00
{{end}}
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader)
func RegisterActorState(code cid.Cid, loader ActorStateLoader) {
ActorStateLoaders[code] = loader
}
func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) {
loader, found := ActorStateLoaders[act.Code]
if !found {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
return loader(store, act.Head)
}
func ActorNameByCode(c cid.Cid) string {
switch {
{{range .versions}}
case builtin{{.}}.IsBuiltinActor(c):
return builtin{{.}}.ActorNameByCode(c)
{{end}}
2021-05-06 04:17:35 +00:00
default:
return "<unknown>"
}
}
func IsBuiltinActor(c cid.Cid) bool {
{{range .versions}}
if builtin{{.}}.IsBuiltinActor(c) {
return true
}
{{end}}
return false
2021-05-06 04:17:35 +00:00
}
func IsAccountActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.AccountActorCodeID {
return true
}
{{end}}
return false
2021-05-06 04:17:35 +00:00
}
func IsStorageMinerActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.StorageMinerActorCodeID {
return true
}
{{end}}
return false
2021-05-06 04:17:35 +00:00
}
func IsMultisigActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.MultisigActorCodeID {
return true
}
{{end}}
return false
2021-05-06 04:17:35 +00:00
}
func IsPaymentChannelActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.PaymentChannelActorCodeID {
return true
}
{{end}}
return false
2021-05-06 04:17:35 +00:00
}
func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
panic(err)
}
return ret
}