2022-06-28 16:39:19 +00:00
|
|
|
package actors
|
|
|
|
|
|
|
|
import (
|
2022-06-29 16:54:14 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2022-06-28 16:39:19 +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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetActorCodeID looks up a builtin actor's code CID by actor version and canonical actor name.
|
2022-09-06 15:49:29 +00:00
|
|
|
func GetActorCodeID(av actorstypes.Version, name string) (cid.Cid, bool) {
|
2022-06-28 16:39:19 +00:00
|
|
|
|
|
|
|
// Actors V8 and above
|
2022-09-06 15:49:29 +00:00
|
|
|
if av >= actorstypes.Version8 {
|
2022-06-29 05:37:56 +00:00
|
|
|
if cids, ok := GetActorCodeIDsFromManifest(av); ok {
|
|
|
|
c, ok := cids[name]
|
|
|
|
return c, ok
|
2022-06-28 16:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actors V7 and lower
|
|
|
|
switch name {
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.AccountKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.AccountActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.AccountActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.CronKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.CronActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.CronActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.InitKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.InitActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.InitActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MarketKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.StorageMarketActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.StorageMarketActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MinerKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.StorageMinerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.StorageMinerActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MultisigKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.MultisigActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.MultisigActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.PaychKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.PaymentChannelActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.PaymentChannelActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.PowerKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.StoragePowerActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.StoragePowerActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.RewardKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.RewardActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.RewardActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.SystemKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.SystemActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.SystemActorCodeID, true
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.VerifregKey:
|
2022-06-28 16:39:19 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin0.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin2.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin3.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin4.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin5.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin6.VerifiedRegistryActorCodeID, true
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2022-06-28 16:39:19 +00:00
|
|
|
return builtin7.VerifiedRegistryActorCodeID, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cid.Undef, false
|
|
|
|
}
|
|
|
|
|
2022-06-29 05:37:56 +00:00
|
|
|
// GetActorCodeIDs looks up all builtin actor's code CIDs by actor version.
|
2022-09-06 15:49:29 +00:00
|
|
|
func GetActorCodeIDs(av actorstypes.Version) (map[string]cid.Cid, error) {
|
2022-06-28 16:39:19 +00:00
|
|
|
cids, ok := GetActorCodeIDsFromManifest(av)
|
|
|
|
if ok {
|
|
|
|
return cids, nil
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
actorsKeys := manifest.GetBuiltinActorsKeys(av)
|
2022-06-28 16:39:19 +00:00
|
|
|
synthCids := make(map[string]cid.Cid)
|
|
|
|
|
|
|
|
for _, key := range actorsKeys {
|
|
|
|
c, ok := GetActorCodeID(av, key)
|
|
|
|
if !ok {
|
|
|
|
return nil, xerrors.Errorf("could not find builtin actor cids for Actors version %d", av)
|
|
|
|
}
|
2022-06-29 18:43:49 +00:00
|
|
|
synthCids[key] = c
|
2022-06-28 16:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return synthCids, nil
|
|
|
|
}
|