lotus/chain/actors/builtin/builtin.go

312 lines
6.1 KiB
Go
Raw Normal View History

package builtin
import (
"fmt"
"github.com/ipfs/go-cid"
2022-09-07 23:30:55 +00:00
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing"
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/go-state-types/manifest"
2022-09-07 23:30:55 +00:00
"github.com/filecoin-project/go-state-types/proof"
2022-04-07 18:46:23 +00:00
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
2022-09-06 15:49:29 +00:00
2022-04-04 11:25:03 +00:00
"github.com/filecoin-project/lotus/chain/actors"
)
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")
2020-10-06 21:47:03 +00:00
var RootVerifierAddress = makeAddress("t080")
2020-09-29 04:24:38 +00:00
2020-10-08 01:09:33 +00:00
var (
2022-05-16 23:43:06 +00:00
ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch
2020-10-08 01:09:33 +00:00
)
const (
2022-05-16 23:43:06 +00:00
EpochDurationSeconds = builtin.EpochDurationSeconds
EpochsInDay = builtin.EpochsInDay
SecondsInDay = builtin.SecondsInDay
2020-10-08 01:09:33 +00:00
)
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
2021-01-18 23:15:18 +00:00
// 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:25:03 +00:00
}
2022-03-01 03:57:40 +00:00
2022-04-04 11:25:03 +00:00
switch {
2022-04-07 18:46:23 +00:00
case builtin0.IsBuiltinActor(c):
return builtin0.ActorNameByCode(c)
case builtin2.IsBuiltinActor(c):
return builtin2.ActorNameByCode(c)
case builtin3.IsBuiltinActor(c):
return builtin3.ActorNameByCode(c)
case builtin4.IsBuiltinActor(c):
return builtin4.ActorNameByCode(c)
case builtin5.IsBuiltinActor(c):
return builtin5.ActorNameByCode(c)
case builtin6.IsBuiltinActor(c):
return builtin6.ActorNameByCode(c)
case builtin7.IsBuiltinActor(c):
return builtin7.ActorNameByCode(c)
default:
return "<unknown>"
}
}
func IsBuiltinActor(c cid.Cid) bool {
2022-04-04 11:25:03 +00:00
_, _, ok := actors.GetActorMetaByCode(c)
2022-04-07 18:46:23 +00:00
if ok {
return true
}
if builtin0.IsBuiltinActor(c) {
return true
}
if builtin2.IsBuiltinActor(c) {
return true
}
if builtin3.IsBuiltinActor(c) {
return true
}
if builtin4.IsBuiltinActor(c) {
return true
}
if builtin5.IsBuiltinActor(c) {
return true
}
if builtin6.IsBuiltinActor(c) {
return true
}
if builtin7.IsBuiltinActor(c) {
return true
}
2022-04-20 21:34:28 +00:00
return false
}
2020-09-29 04:24:38 +00:00
func IsAccountActor(c cid.Cid) bool {
2022-04-04 11:25:03 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
2022-04-07 18:46:23 +00:00
if ok {
return name == "account"
}
if c == builtin0.AccountActorCodeID {
return true
}
if c == builtin2.AccountActorCodeID {
return true
}
if c == builtin3.AccountActorCodeID {
return true
}
if c == builtin4.AccountActorCodeID {
return true
}
if c == builtin5.AccountActorCodeID {
return true
}
if c == builtin6.AccountActorCodeID {
return true
}
if c == builtin7.AccountActorCodeID {
return true
}
2022-04-20 21:34:28 +00:00
return false
}
2020-09-29 04:24:38 +00:00
func IsStorageMinerActor(c cid.Cid) bool {
2022-04-04 11:25:03 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
2022-04-07 18:46:23 +00:00
if ok {
return name == manifest.MinerKey
2022-04-07 18:46:23 +00:00
}
if c == builtin0.StorageMinerActorCodeID {
return true
}
if c == builtin2.StorageMinerActorCodeID {
return true
}
if c == builtin3.StorageMinerActorCodeID {
return true
}
if c == builtin4.StorageMinerActorCodeID {
return true
}
if c == builtin5.StorageMinerActorCodeID {
return true
}
if c == builtin6.StorageMinerActorCodeID {
return true
}
if c == builtin7.StorageMinerActorCodeID {
return true
}
2022-04-20 21:34:28 +00:00
return false
}
2020-09-29 04:24:38 +00:00
func IsMultisigActor(c cid.Cid) bool {
2022-04-04 11:25:03 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
2022-04-07 18:46:23 +00:00
if ok {
return name == manifest.MultisigKey
2022-04-07 18:46:23 +00:00
}
if c == builtin0.MultisigActorCodeID {
return true
}
if c == builtin2.MultisigActorCodeID {
return true
}
if c == builtin3.MultisigActorCodeID {
return true
}
if c == builtin4.MultisigActorCodeID {
return true
}
if c == builtin5.MultisigActorCodeID {
return true
}
if c == builtin6.MultisigActorCodeID {
return true
}
if c == builtin7.MultisigActorCodeID {
return true
}
2022-04-20 21:34:28 +00:00
return false
}
2020-09-29 04:24:38 +00:00
func IsPaymentChannelActor(c cid.Cid) bool {
2022-04-04 11:25:03 +00:00
name, _, ok := actors.GetActorMetaByCode(c)
2022-04-07 18:46:23 +00:00
if ok {
return name == "paymentchannel"
}
if c == builtin0.PaymentChannelActorCodeID {
return true
}
if c == builtin2.PaymentChannelActorCodeID {
return true
}
if c == builtin3.PaymentChannelActorCodeID {
return true
}
if c == builtin4.PaymentChannelActorCodeID {
return true
}
if c == builtin5.PaymentChannelActorCodeID {
return true
}
if c == builtin6.PaymentChannelActorCodeID {
return true
}
if c == builtin7.PaymentChannelActorCodeID {
return true
}
2022-04-20 21:34:28 +00:00
return false
}
2023-01-10 03:23:55 +00:00
func IsPlaceholderActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
2023-01-10 03:23:55 +00:00
return name == manifest.PlaceholderKey
}
return false
}
func IsEvmActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == manifest.EvmKey
}
return false
}
func IsEthAccountActor(c cid.Cid) bool {
name, _, ok := actors.GetActorMetaByCode(c)
if ok {
return name == manifest.EthAccountKey
}
return false
}
func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
panic(err)
}
return ret
}