2022-09-06 15:49:29 +00:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
|
|
|
"github.com/ipfs/go-cid"
|
2022-10-19 17:11:44 +00:00
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/builtin"
|
2022-09-06 15:49:29 +00:00
|
|
|
{{range .versions}}
|
|
|
|
{{if (ge . 8)}}
|
|
|
|
account{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/account"
|
2022-09-09 20:42:55 +00:00
|
|
|
cron{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/cron"
|
|
|
|
_init{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/init"
|
|
|
|
multisig{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/multisig"
|
|
|
|
miner{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/miner"
|
|
|
|
market{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/market"
|
|
|
|
reward{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/reward"
|
|
|
|
paych{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/paych"
|
|
|
|
power{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/power"
|
|
|
|
system{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/system"
|
|
|
|
verifreg{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/verifreg"
|
2022-09-06 15:49:29 +00:00
|
|
|
{{end}}
|
2022-10-12 15:44:59 +00:00
|
|
|
{{if (ge . 9)}}
|
|
|
|
datacap{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/datacap"
|
|
|
|
{{end}}
|
2023-01-02 22:45:13 +00:00
|
|
|
{{if (ge . 10)}}
|
|
|
|
evm{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/evm"
|
|
|
|
eam{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/eam"
|
|
|
|
embryo{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/embryo"
|
|
|
|
ethaccount{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/ethaccount"
|
|
|
|
{{end}}
|
2022-09-06 15:49:29 +00:00
|
|
|
{{end}}
|
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
|
|
|
rtt "github.com/filecoin-project/go-state-types/rt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2022-12-13 16:49:22 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2022-09-06 15:49:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RegistryEntry struct {
|
|
|
|
state cbor.Er
|
|
|
|
code cid.Cid
|
2022-12-13 16:49:22 +00:00
|
|
|
methods map[abi.MethodNum]builtin.MethodMeta
|
2022-09-06 15:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r RegistryEntry) State() cbor.Er {
|
|
|
|
return r.state
|
|
|
|
}
|
|
|
|
|
2022-12-13 16:49:22 +00:00
|
|
|
func (r RegistryEntry) Exports() map[abi.MethodNum]builtin.MethodMeta {
|
2022-09-06 15:49:29 +00:00
|
|
|
return r.methods
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r RegistryEntry) Code() cid.Cid {
|
|
|
|
return r.code
|
|
|
|
}
|
|
|
|
|
2022-09-21 14:56:58 +00:00
|
|
|
func MakeRegistryLegacy(actors []rtt.VMActor) []RegistryEntry {
|
|
|
|
registry := make([]RegistryEntry, 0)
|
|
|
|
|
|
|
|
for _, actor := range actors {
|
2022-12-13 16:49:22 +00:00
|
|
|
methodMap := make(map[abi.MethodNum]builtin.MethodMeta)
|
2022-09-21 14:56:58 +00:00
|
|
|
for methodNum, method := range actor.Exports() {
|
2022-10-19 17:11:44 +00:00
|
|
|
if method != nil {
|
2022-12-13 16:49:22 +00:00
|
|
|
methodMap[abi.MethodNum(methodNum)] = makeMethodMeta(method)
|
2022-10-19 17:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-21 14:56:58 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: actor.Code(),
|
|
|
|
methods: methodMap,
|
|
|
|
state: actor.State(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return registry
|
|
|
|
}
|
|
|
|
|
2022-10-19 17:11:44 +00:00
|
|
|
func makeMethodMeta(method interface{}) builtin.MethodMeta {
|
|
|
|
ev := reflect.ValueOf(method)
|
|
|
|
// Extract the method names using reflection. These
|
|
|
|
// method names always match the field names in the
|
|
|
|
// `builtin.Method*` structs (tested in the specs-actors
|
|
|
|
// tests).
|
|
|
|
fnName := runtime.FuncForPC(ev.Pointer()).Name()
|
|
|
|
fnName = strings.TrimSuffix(fnName[strings.LastIndexByte(fnName, '.')+1:], "-fm")
|
|
|
|
return builtin.MethodMeta{
|
|
|
|
Name: fnName,
|
|
|
|
Method: method,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 14:56:58 +00:00
|
|
|
func MakeRegistry(av actorstypes.Version) []RegistryEntry {
|
2022-09-06 15:49:29 +00:00
|
|
|
if av < actorstypes.Version8 {
|
|
|
|
panic("expected version v8 and up only, use specs-actors for v0-7")
|
|
|
|
}
|
2022-09-21 14:56:58 +00:00
|
|
|
registry := make([]RegistryEntry, 0)
|
2022-09-06 15:49:29 +00:00
|
|
|
|
|
|
|
codeIDs, err := actors.GetActorCodeIDs(av)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch av {
|
|
|
|
{{range .versions}}
|
|
|
|
{{if (ge . 8)}}
|
|
|
|
case actorstypes.Version{{.}}:
|
|
|
|
for key, codeID := range codeIDs {
|
|
|
|
switch key {
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.AccountKey:
|
2022-09-06 15:49:29 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: account{{.}}.Methods,
|
|
|
|
state: new(account{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.CronKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: cron{{.}}.Methods,
|
|
|
|
state: new(cron{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.InitKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: _init{{.}}.Methods,
|
|
|
|
state: new(_init{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MarketKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: market{{.}}.Methods,
|
|
|
|
state: new(market{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MinerKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: miner{{.}}.Methods,
|
|
|
|
state: new(miner{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.MultisigKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: multisig{{.}}.Methods,
|
|
|
|
state: new(multisig{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.PaychKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: paych{{.}}.Methods,
|
|
|
|
state: new(paych{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.PowerKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: power{{.}}.Methods,
|
|
|
|
state: new(power{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.RewardKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: reward{{.}}.Methods,
|
|
|
|
state: new(reward{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.SystemKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: system{{.}}.Methods,
|
|
|
|
state: new(system{{.}}.State),
|
|
|
|
})
|
2022-12-13 23:02:34 +00:00
|
|
|
case manifest.VerifregKey:
|
2022-09-09 20:42:55 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: verifreg{{.}}.Methods,
|
|
|
|
state: new(verifreg{{.}}.State),
|
|
|
|
})
|
2022-12-15 00:02:43 +00:00
|
|
|
{{if (ge . 9)}}case manifest.DatacapKey:
|
2022-10-12 15:44:59 +00:00
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: datacap{{.}}.Methods,
|
|
|
|
state: new(datacap{{.}}.State),
|
|
|
|
}){{end}}
|
2023-01-02 22:45:13 +00:00
|
|
|
{{if (ge . 10)}}
|
|
|
|
case manifest.EvmKey:
|
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: evm{{.}}.Methods,
|
|
|
|
state: new(evm{{.}}.State),
|
|
|
|
})
|
|
|
|
case manifest.EamKey:
|
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: eam{{.}}.Methods,
|
|
|
|
state: nil,
|
|
|
|
})
|
|
|
|
case manifest.EmbryoKey:
|
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: embryo{{.}}.Methods,
|
|
|
|
state: nil,
|
|
|
|
})
|
|
|
|
case manifest.EthAccountKey:
|
|
|
|
registry = append(registry, RegistryEntry{
|
|
|
|
code: codeID,
|
|
|
|
methods: ethaccount{{.}}.Methods,
|
|
|
|
state: nil,
|
|
|
|
})
|
|
|
|
{{end}}
|
2022-09-06 15:49:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("expected version v8 and up only, use specs-actors for v0-7")
|
|
|
|
}
|
|
|
|
|
|
|
|
return registry
|
|
|
|
}
|