Commit c865ac08 authored by linj's avatar linj Committed by vipwzw

add fork config tool: 用配置文件格式 打印fork

parent 134189be
......@@ -25,6 +25,7 @@ default: depends build
build: depends
go build $(BUILD_FLAGS) -v -i -o $(APP)
go build $(BUILD_FLAGS) -v -i -o $(CLI) $(SRC_CLI)
go build $(BUILD_FLAGS) -v -i -o build/fork-config github.com/33cn/plugin/cli/fork_config/
@cp chain33.toml $(CHAIN33_PATH)/build/system-test-rpc.sh build/
@cp chain33.para.toml build/ci/paracross/
......
package main
import (
"flag"
"fmt"
"os"
"sort"
"strings"
_ "github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
_ "github.com/33cn/plugin/plugin"
)
var (
configPath = flag.String("f", "", "configfile")
)
func main() {
flag.Parse()
if *configPath == "" {
*configPath = "chain33.toml"
}
cfg, _ := types.InitCfg(*configPath)
types.Init(cfg.Title, cfg)
forks, err := types.CloneFork("chain33")
if err != nil {
fmt.Printf("clone fork failed: %v", err)
return
}
fmtForks(forks)
}
/*
两个规则:
key 有 ".", Part1.Part2 为 [fork.sub.Part1] Part2=value
key 没有 "." [fork.system] key=value
把相同段的fork打印到一起
[fork.system]
ForkChainParamV1= 0 # ForkBlockCheck=1560000
[fork.sub.ticket]
Enable=0 # manage.ForkManageExec=400000
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl=2270000 # store-kvmvccmavl.ForkKvmvccmavl=1870000
*/
func fmtForks(forks map[string]int64) {
systemFork := make(map[string]int64)
subFork := make(map[string]map[string]int64)
for k, v := range forks {
if strings.Contains(k, ".") {
str2 := strings.SplitN(k, ".", 2)
if len(str2) != 2 {
fmt.Fprintf(os.Stderr, "can't deal key=%s ", k)
continue
}
_, ok := subFork[str2[0]]
if !ok {
subFork[str2[0]] = make(map[string]int64)
}
subFork[str2[0]][str2[1]] = v
} else {
systemFork[k] = v
}
}
fmt.Println("[fork.system]")
for k, v := range systemFork {
fmt.Printf("%s=%d\n", k, v)
}
fmt.Println("")
plugins := make([]string, 0)
for plugin := range subFork {
plugins = append(plugins, plugin)
}
sort.Strings(plugins)
for _, plugin := range plugins {
fmt.Printf("[fork.sub.%s]\n", plugin)
forks := subFork[plugin]
for k, v := range forks {
fmt.Printf("%s=%d\n", k, v)
}
fmt.Println("")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment