lotus/lotuspond/front/src/chain/methodgen.go

78 lines
1.5 KiB
Go
Raw Normal View History

2020-04-24 00:04:12 +00:00
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/multiformats/go-multihash"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/stmgr"
2020-04-24 00:04:12 +00:00
)
func main() {
if _, err := os.Stat("code.json"); err != nil {
panic(err) // note: must run in lotuspond/front/src/chain
}
// TODO: ActorUpgrade: this is going to be a problem.
2020-04-24 00:04:12 +00:00
names := map[string]string{
"system": "fil/1/system",
"init": "fil/1/init",
"cron": "fil/1/cron",
"account": "fil/1/account",
"power": "fil/1/storagepower",
"miner": "fil/1/storageminer",
"market": "fil/1/storagemarket",
"paych": "fil/1/paymentchannel",
"multisig": "fil/1/multisig",
"reward": "fil/1/reward",
"verifreg": "fil/1/verifiedregistry",
}
{
b, err := json.MarshalIndent(names, "", " ")
if err != nil {
panic(err)
}
if err := ioutil.WriteFile("code.json", b, 0664); err != nil {
panic(err)
}
}
out := map[string][]string{}
for c, methods := range stmgr.MethodsMap {
2020-04-24 00:04:12 +00:00
cmh, err := multihash.Decode(c.Hash())
if err != nil {
panic(err)
}
name := string(cmh.Digest)
remaining := len(methods)
2020-04-24 00:04:12 +00:00
// iterate over actor methods in order.
for i := abi.MethodNum(0); remaining > 0; i++ {
m, ok := methods[i]
if !ok {
continue
}
out[name] = append(out[name], m.Name)
remaining--
2020-04-24 00:04:12 +00:00
}
}
{
b, err := json.MarshalIndent(out, "", " ")
if err != nil {
panic(err)
}
if err := ioutil.WriteFile("methods.json", b, 0664); err != nil {
panic(err)
}
}
}