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

182 lines
4.1 KiB
Plaintext
Raw Normal View History

package builtin
import (
"fmt"
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
2022-04-20 21:34:28 +00:00
{{range .versions}}
2022-09-06 15:49:29 +00:00
{{if (le . 7)}}
2022-04-20 21:34:28 +00:00
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
2022-09-06 15:49:29 +00:00
{{end}}
2022-04-20 21:34:28 +00:00
{{end}}
"github.com/filecoin-project/go-state-types/abi"
2022-04-20 21:34:28 +00:00
"github.com/filecoin-project/go-state-types/proof"
2022-05-16 23:43:06 +00:00
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/manifest"
2022-04-04 11:23:13 +00:00
"github.com/filecoin-project/lotus/chain/actors"
2022-09-07 23:30:55 +00:00
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
2022-04-20 21:34:28 +00:00
smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing"
)
2022-05-16 23:43:06 +00:00
var SystemActorAddr = builtin.SystemActorAddr
var BurntFundsActorAddr = builtin.BurntFundsActorAddr
var CronActorAddr = builtin.CronActorAddr
var SaftAddress = makeAddress("t0122")
var ReserveAddress = makeAddress("t090")
var RootVerifierAddress = makeAddress("t080")
var (
2022-05-16 23:43:06 +00:00
ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch
)
const (
2022-05-16 23:43:06 +00:00
EpochDurationSeconds = builtin.EpochDurationSeconds
EpochsInDay = builtin.EpochsInDay
SecondsInDay = builtin.SecondsInDay
)
const (
2022-05-16 23:43:06 +00:00
MethodSend = builtin.MethodSend
MethodConstructor = builtin.MethodConstructor
)
// These are all just type aliases across actor versions. In the future, that might change
// and we might need to do something fancier.
2022-04-20 21:34:28 +00:00
type SectorInfo = proof.SectorInfo
type ExtendedSectorInfo = proof.ExtendedSectorInfo
type PoStProof = proof.PoStProof
type FilterEstimate = smoothingtypes.FilterEstimate
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
2022-09-07 23:30:55 +00:00
return minertypes.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
}
func ActorNameByCode(c cid.Cid) string {
if name, version, ok := actors.GetActorMetaByCode(c); ok {
return fmt.Sprintf("fil/%d/%s", version, name)
2022-04-04 11:23:13 +00:00
}
switch {
2022-05-15 19:26:52 +00:00
{{range .versions}}
2022-09-06 15:49:29 +00:00
{{if (le . 7)}}
2022-05-16 23:43:06 +00:00
case builtin{{.}}.IsBuiltinActor(c):
return builtin{{.}}.ActorNameByCode(c)
2022-09-06 15:49:29 +00:00
{{end}}
2022-05-15 19:26:52 +00:00
{{end}}
default:
return "<unknown>"
}
}
func IsBuiltinActor(c cid.Cid) bool {
2022-04-04 11:23:13 +00:00
_, _, ok := actors.GetActorMetaByCode(c)
if ok {
return true
}
{{range .versions}}
2022-04-20 21:34:28 +00:00
{{if (le . 7)}}
if builtin{{.}}.IsBuiltinActor(c) {
return true
}
{{end}}
{{end}}
return false
}
func IsAccountActor(c cid.Cid) bool {
2022-04-04 11:23:13 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "account"
}
{{range .versions}}
2022-04-20 21:34:28 +00:00
{{if (le . 7)}}
if c == builtin{{.}}.AccountActorCodeID {
return true
}
{{end}}
{{end}}
return false
}
func IsStorageMinerActor(c cid.Cid) bool {
2022-04-04 11:23:13 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == manifest.MinerKey
2022-04-04 11:23:13 +00:00
}
{{range .versions}}
2022-04-20 21:34:28 +00:00
{{if (le . 7)}}
if c == builtin{{.}}.StorageMinerActorCodeID {
return true
}
{{end}}
{{end}}
return false
}
func IsMultisigActor(c cid.Cid) bool {
2022-04-04 11:23:13 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == manifest.MultisigKey
2022-04-04 11:23:13 +00:00
}
{{range .versions}}
2022-04-20 21:34:28 +00:00
{{if (le . 7)}}
if c == builtin{{.}}.MultisigActorCodeID {
return true
}
{{end}}
{{end}}
return false
}
func IsPaymentChannelActor(c cid.Cid) bool {
2022-04-04 11:23:13 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "paymentchannel"
}
{{range .versions}}
2022-04-20 21:34:28 +00:00
{{if (le . 7)}}
if c == builtin{{.}}.PaymentChannelActorCodeID {
return true
}
{{end}}
{{end}}
return false
}
func IsEmbryoActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "embryo"
}
return false
}
func IsEthAccountActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == "ethaccount"
}
return false
}
func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
panic(err)
}
return ret
}