lotus/gen/main.go

70 lines
1.4 KiB
Go
Raw Normal View History

2019-08-21 17:15:28 +00:00
package main
import (
"fmt"
"os"
2019-08-22 01:29:19 +00:00
"github.com/filecoin-project/go-lotus/chain"
2019-08-21 17:15:28 +00:00
"github.com/filecoin-project/go-lotus/chain/types"
gen "github.com/whyrusleeping/cbor-gen"
)
func main() {
2019-08-22 01:29:19 +00:00
{
fi, err := os.Create("./chain/types/cbor_gen.go")
if err != nil {
fmt.Println("failed to open file: ", err)
os.Exit(1)
}
defer fi.Close()
2019-08-21 17:15:28 +00:00
2019-08-22 01:29:19 +00:00
if err := gen.PrintHeaderAndUtilityMethods(fi, "types"); err != nil {
fmt.Println("failed to write header: ", err)
os.Exit(1)
}
types := []interface{}{
types.BlockHeader{},
types.Ticket{},
types.Message{},
types.SignedMessage{},
types.MsgMeta{},
}
2019-08-21 17:15:28 +00:00
2019-08-22 01:29:19 +00:00
for _, t := range types {
if err := gen.GenTupleEncodersForType(t, fi); err != nil {
fmt.Println("failed to generate encoders: ", err)
os.Exit(1)
}
}
2019-08-21 17:15:28 +00:00
}
2019-08-22 01:29:19 +00:00
{
fi, err := os.Create("./chain/cbor_gen.go")
if err != nil {
fmt.Println("failed to open file: ", err)
os.Exit(1)
}
defer fi.Close()
if err := gen.PrintHeaderAndUtilityMethods(fi, "chain"); err != nil {
fmt.Println("failed to write header: ", err)
2019-08-21 17:15:28 +00:00
os.Exit(1)
}
2019-08-22 01:29:19 +00:00
types := []interface{}{
chain.BlockSyncRequest{},
chain.BlockSyncResponse{},
chain.BSTipSet{},
chain.BlockMsg{},
}
for _, t := range types {
if err := gen.GenTupleEncodersForType(t, fi); err != nil {
fmt.Println("failed to generate encoders: ", err)
os.Exit(1)
}
}
2019-08-21 17:15:28 +00:00
}
}