From a8ee8baf5a3bb2213a358b11cb5f4bc4c09c6e82 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Sun, 3 Nov 2024 17:39:48 -0500 Subject: [PATCH 01/13] Added InitChain to code-gen --- src/dev_tools/goMaker/types/templates.go | 2 ++ src/dev_tools/goMaker/types/types_structure.go | 4 ++++ src/dev_tools/goMaker/types/utils.go | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dev_tools/goMaker/types/templates.go b/src/dev_tools/goMaker/types/templates.go index 16583056f4..8f8464f527 100644 --- a/src/dev_tools/goMaker/types/templates.go +++ b/src/dev_tools/goMaker/types/templates.go @@ -41,6 +41,7 @@ func getFuncMap() template.FuncMap { firstLower := func(s string) string { return FirstLower(s) } firstUpper := func(s string) string { return FirstUpper(s) } toLowerPlural := func(s string) string { return Lower(Plural(s)) } + or := func(a, b bool) bool { return a || b } return template.FuncMap{ "toSingular": toSingular, "toProper": toProper, @@ -50,5 +51,6 @@ func getFuncMap() template.FuncMap { "toLower": toLower, "firstLower": firstLower, "firstUpper": firstUpper, + "or": or, } } diff --git a/src/dev_tools/goMaker/types/types_structure.go b/src/dev_tools/goMaker/types/types_structure.go index 84632326fb..125b829e5e 100644 --- a/src/dev_tools/goMaker/types/types_structure.go +++ b/src/dev_tools/goMaker/types/types_structure.go @@ -291,6 +291,10 @@ func (s *Structure) NeedsChain() bool { return !strings.Contains(s.Attributes, "noChain") } +func (s *Structure) InitChain() bool { + return !s.NeedsChain() && strings.Contains(s.Attributes, "initChain") +} + func (s *Structure) NeedsFetch() bool { return !strings.Contains(s.Attributes, "noFetch") } diff --git a/src/dev_tools/goMaker/types/utils.go b/src/dev_tools/goMaker/types/utils.go index 55cdedb43e..1647646759 100644 --- a/src/dev_tools/goMaker/types/utils.go +++ b/src/dev_tools/goMaker/types/utils.go @@ -186,9 +186,10 @@ func FirstLower(s string) string { func Plural(s string) string { if strings.HasSuffix(s, "s") { return s - } - if strings.HasSuffix(s, "x") { + } else if strings.HasSuffix(s, "x") { return s + "es" + } else if strings.HasSuffix(s, "y") { + return s + "ies" } return s + "s" } From 44bddaa9d7a20347d1e9244118569843c9453ed5 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Wed, 6 Nov 2024 00:00:39 -0500 Subject: [PATCH 02/13] Enhances goMaker --- .../goMaker/types/types_structure.go | 67 +++++++++++++++---- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/src/dev_tools/goMaker/types/types_structure.go b/src/dev_tools/goMaker/types/types_structure.go index 125b829e5e..f5e640169b 100644 --- a/src/dev_tools/goMaker/types/types_structure.go +++ b/src/dev_tools/goMaker/types/types_structure.go @@ -242,14 +242,20 @@ func (s *Structure) ItemName() string { func (s *Structure) ItemType() string { pkg, typ := s.parseType("itemType") + if strings.HasPrefix(pkg, "types") { + return FirstUpper(typ) + } return FirstLower(pkg) + "." + FirstUpper(typ) } func (s *Structure) InputType() string { - if s.Class == "Manifest" { - return "coreTypes.Manifest" + pkg, typ := s.parseType("inputType") + if typ == "" { + return s.ItemType() + } else if strings.HasPrefix(pkg, "types") { + return FirstUpper(typ) } - return s.ItemType() + return FirstLower(pkg) + "." + FirstUpper(typ) } func (s *Structure) EmbedName() string { @@ -299,6 +305,14 @@ func (s *Structure) NeedsFetch() bool { return !strings.Contains(s.Attributes, "noFetch") } +func (s *Structure) NeedsType() bool { + return !strings.Contains(s.Attributes, "noType") +} + +func (s *Structure) NeedsPaging() bool { + return !strings.Contains(s.Attributes, "noPaging") +} + func (s *Structure) IsEditable() bool { return strings.Contains(s.Attributes, "editable") } @@ -330,6 +344,37 @@ func (s *Structure) SortsInstance() string { return ret } +func (s *Structure) UiHotKey() string { + keys := map[string]string{ + "project": "1", + "history": "2", + "monitors": "3", + "names": "4", + "abis": "5", + "indexes": "6", + "manifests": "7", + "status": "8", + "settings": "9", + "daemons": "0", + "session": "u", + "config": "v", + "wizard": "w", + } + return keys[s.UiRouteName()] +} + +func (s *Structure) IsHistory() bool { + return s.UiRouteName() == "history" +} + +func (s *Structure) IsProject() bool { + return s.UiRouteName() == "project" +} + +func (s *Structure) IsWizard() bool { + return s.UiRouteName() == "wizard" +} + func (s *Structure) UiRouteNum() uint64 { parts := strings.Split(s.UiRoute, "-") return base.MustParseUint64(parts[0]) @@ -340,22 +385,18 @@ func (s *Structure) UiRouteName() string { return parts[1] } -func (s *Structure) UiRouteStr() string { - ret := s.UiRouteName() +func (s *Structure) UiRouteRoute() string { + ret := Lower(s.UiRouteName()) if ret == "project" { return "" } return ret } -func (s *Structure) IsHistory() bool { - return s.UiRouteName() == "history" +func (s *Structure) UiRouteLabel() string { + return FirstUpper(s.UiRouteName()) } -func (s *Structure) IsProject() bool { - return s.UiRouteName() == "project" -} - -func (s *Structure) IsWizard() bool { - return s.UiRouteName() == "wizard" +func (s *Structure) UiRouteLower() string { + return Lower(s.UiRouteName()) } From 6118131bcec58a8de109b00dedbeaa8c34eae17e Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Wed, 6 Nov 2024 00:34:21 -0500 Subject: [PATCH 03/13] Remove typescript and markdown formatters because they are too slow --- src/dev_tools/goMaker/codeWriter/code_writer.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dev_tools/goMaker/codeWriter/code_writer.go b/src/dev_tools/goMaker/codeWriter/code_writer.go index 1007678fbb..d70aaf4dd0 100644 --- a/src/dev_tools/goMaker/codeWriter/code_writer.go +++ b/src/dev_tools/goMaker/codeWriter/code_writer.go @@ -155,12 +155,16 @@ func updateFile(tempFn, newCode string) (bool, error) { var parser string switch fileExt { case "md": - parser = "markdown" + // parser = "markdown" case "yaml", "yml": parser = "yaml" - case "js", "jsx": + case "js": + // parser = "babel" + case "jsx": parser = "babel" - case "ts", "tsx": + case "ts": + // parser = "typescript" + case "tsx": parser = "typescript" default: // do nothing From f0e4adfe811a8cd5189dee0f8e17551e8fb76896 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 09:37:41 -0500 Subject: [PATCH 04/13] Updates dev_tools --- .../goMaker/codeWriter/code_writer.go | 40 +++- src/dev_tools/goMaker/go.mod | 2 +- src/dev_tools/goMaker/go.sum | 4 +- .../goMaker/templates/cmd-line-options.csv | 2 +- src/dev_tools/goMaker/types/generate.go | 7 +- src/dev_tools/goMaker/types/templates.go | 11 + src/dev_tools/goMaker/types/types_codebase.go | 2 +- src/dev_tools/goMaker/types/types_member.go | 12 ++ .../goMaker/types/types_structure.go | 198 ++++++------------ src/dev_tools/goMaker/types/utils.go | 15 ++ src/dev_tools/indexManager/go.mod | 2 +- src/dev_tools/indexManager/go.sum | 4 +- src/dev_tools/sdkFuzzer/config.go | 6 +- src/dev_tools/sdkFuzzer/go.mod | 2 +- src/dev_tools/sdkFuzzer/go.sum | 4 +- src/dev_tools/testRunner/go.mod | 2 +- src/dev_tools/testRunner/go.sum | 4 +- 17 files changed, 158 insertions(+), 159 deletions(-) diff --git a/src/dev_tools/goMaker/codeWriter/code_writer.go b/src/dev_tools/goMaker/codeWriter/code_writer.go index d70aaf4dd0..91569678d3 100644 --- a/src/dev_tools/goMaker/codeWriter/code_writer.go +++ b/src/dev_tools/goMaker/codeWriter/code_writer.go @@ -142,15 +142,31 @@ func applyTemplate(tempFn string, existingCode map[int]string) (bool, error) { } func updateFile(tempFn, newCode string) (bool, error) { - formatted := newCode + lines := []string{} + for _, line := range strings.Split(newCode, "\n") { + if !strings.Contains(line, "//-- remove line --") { + lines = append(lines, line) + } + } + codeToWrite := strings.Join(lines, "\n") fileExt := strings.TrimPrefix(filepath.Ext(strings.TrimSuffix(tempFn, ".new")), ".") + origFn := strings.Replace(tempFn, ".new", "", 1) + outFn := tempFn + ".output" + errFn := tempFn + ".error" + tmpSrcFn := tempFn + ".src" + defer func() { + os.Remove(outFn) + os.Remove(errFn) + os.Remove(tmpSrcFn) + }() + if fileExt == "go" { - formattedBytes, err := format.Source([]byte(newCode)) + formattedBytes, err := format.Source([]byte(codeToWrite)) if err != nil { - return showErroredCode(newCode, err) + return showErroredCode(codeToWrite, err) } - formatted = string(formattedBytes) + codeToWrite = string(formattedBytes) } else if hasPrettier() { var parser string switch fileExt { @@ -170,18 +186,24 @@ func updateFile(tempFn, newCode string) (bool, error) { // do nothing } if parser != "" { - utils.System("prettier -w --parser " + parser + " " + tempFn + " >/dev/null") - formatted = file.AsciiFileToString(tempFn) + file.StringToAsciiFile(tmpSrcFn, codeToWrite) + cmd := fmt.Sprintf("prettier --parser %s %s > %s 2> %s", parser, tmpSrcFn, outFn, errFn) + utils.System(cmd) + errors := file.AsciiFileToString(errFn) + if len(errors) > 0 { + return showErroredCode(codeToWrite, fmt.Errorf("prettier errors: %s", errors)) + } + codeToWrite = file.AsciiFileToString(outFn) } } else { logger.Warn("Prettier not found, skipping formatting for", tempFn, ". Install Prettier with `npm install -g prettier`.") } - origFn := strings.Replace(tempFn, ".new", "", 1) - if string(formatted) == file.AsciiFileToString(origFn) { + // Compare the new formatted code to the existing file and only write if different + if string(codeToWrite) == file.AsciiFileToString(origFn) { return false, nil } else { - file.StringToAsciiFile(origFn, string(formatted)) // modified code is in the original file + file.StringToAsciiFile(origFn, string(codeToWrite)) // modified code is in the original file return true, nil } } diff --git a/src/dev_tools/goMaker/go.mod b/src/dev_tools/goMaker/go.mod index 30fc997e14..f9da6d04fe 100644 --- a/src/dev_tools/goMaker/go.mod +++ b/src/dev_tools/goMaker/go.mod @@ -4,7 +4,7 @@ module github.com/TrueBlocks/trueblocks-core/goMaker go 1.22 require ( - github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c + github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 github.com/gocarina/gocsv v0.0.0-20230123225133-763e25b40669 golang.org/x/text v0.16.0 ) diff --git a/src/dev_tools/goMaker/go.sum b/src/dev_tools/goMaker/go.sum index 6cf474ad07..19c2f59846 100644 --- a/src/dev_tools/goMaker/go.sum +++ b/src/dev_tools/goMaker/go.sum @@ -1,5 +1,5 @@ -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c h1:ovWX5iJMpegWJZVbj7JFZlseAqwfhvR3lwxyixLfqWY= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= diff --git a/src/dev_tools/goMaker/templates/cmd-line-options.csv b/src/dev_tools/goMaker/templates/cmd-line-options.csv index 3528f75575..500f30c8cf 100644 --- a/src/dev_tools/goMaker/templates/cmd-line-options.csv +++ b/src/dev_tools/goMaker/templates/cmd-line-options.csv @@ -237,7 +237,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,handler,option_ty 42000,apps,Admin,config,config,,,,visible|docs,,command,,,Manage config, [flags],default|,Report on and edit the configuration of the TrueBlocks system. 42020,apps,Admin,config,config,mode,,,visible|docs,3,positional,enum[show*|edit],,,,,either show or edit the configuration 42030,apps,Admin,config,config,paths,a,,visible|docs,1,switch,,cacheItem,,,,show the configuration paths for the system -42040,apps,Admin,config,config,session,s,,,2,switch,,session,,,,standin for ui code - no purpose +42040,apps,Admin,config,config,dump,d,,visible|docs,2,switch,,config,,,,dump the configuration to stdout # 43000,apps,Admin,status,cacheStatus,,,,visible|docs,,command,,,Get status on caches, [mode...] [flags],default|,Report on the state of the internal binary caches. 43020,apps,Admin,status,cacheStatus,modes,,,visible|docs,2,positional,list,status,,,,the (optional) name of the binary cache to report on, terse otherwise diff --git a/src/dev_tools/goMaker/types/generate.go b/src/dev_tools/goMaker/types/generate.go index 381c417fd6..a180184c30 100644 --- a/src/dev_tools/goMaker/types/generate.go +++ b/src/dev_tools/goMaker/types/generate.go @@ -89,7 +89,12 @@ func getGenerators() ([]Generator, error) { theMap := make(map[string][]string) vFunc := func(file string, vP any) (bool, error) { - if strings.HasSuffix(file, ".tmpl") { + isTemplate := strings.HasSuffix(file, ".tmpl") + filter := os.Getenv("TB_GENERATOR_FILTER") + if len(filter) > 0 && !strings.Contains(file, filter) { + return true, nil + } + if isTemplate { file = strings.ReplaceAll(file, generatorsPath, "") if strings.Contains(file, string(os.PathSeparator)) { parts := strings.Split(file, string(os.PathSeparator)) diff --git a/src/dev_tools/goMaker/types/templates.go b/src/dev_tools/goMaker/types/templates.go index 8f8464f527..440d23c2c7 100644 --- a/src/dev_tools/goMaker/types/templates.go +++ b/src/dev_tools/goMaker/types/templates.go @@ -3,6 +3,7 @@ package types import ( "bytes" "log" + "strings" "text/template" ) @@ -42,6 +43,14 @@ func getFuncMap() template.FuncMap { firstUpper := func(s string) string { return FirstUpper(s) } toLowerPlural := func(s string) string { return Lower(Plural(s)) } or := func(a, b bool) bool { return a || b } + replace := func(str, find, rep string) string { return strings.ReplaceAll(str, find, rep) } + cond := func(t bool, a, b any) any { + if t { + return a + } else { + return b + } + } return template.FuncMap{ "toSingular": toSingular, "toProper": toProper, @@ -52,5 +61,7 @@ func getFuncMap() template.FuncMap { "firstLower": firstLower, "firstUpper": firstUpper, "or": or, + "replace": replace, + "cond": cond, } } diff --git a/src/dev_tools/goMaker/types/types_codebase.go b/src/dev_tools/goMaker/types/types_codebase.go index 25726a0aa3..547a877860 100644 --- a/src/dev_tools/goMaker/types/types_codebase.go +++ b/src/dev_tools/goMaker/types/types_codebase.go @@ -153,7 +153,7 @@ func (cb *CodeBase) Validate() error { if m.DocOrder > 0 { order[m.DocOrder] = true } - if knownTypes[m.Type] { + if knownTypes[m.Type] || strings.Contains(m.Type, ".") { continue } diff --git a/src/dev_tools/goMaker/types/types_member.go b/src/dev_tools/goMaker/types/types_member.go index 9424b97333..d0671b23e9 100644 --- a/src/dev_tools/goMaker/types/types_member.go +++ b/src/dev_tools/goMaker/types/types_member.go @@ -70,6 +70,18 @@ func (m *Member) IsRemoved() bool { return strings.Contains(m.Attributes, "removed") } +func (m *Member) IsEmbed() bool { + return strings.Contains(m.Attributes, "embed") +} + +func (m *Member) IsItems() bool { + return m.Name == "items" +} + +func (m *Member) IsInit() bool { + return strings.Contains(m.Attributes, "init") +} + func (m *Member) IsNoTag() bool { return strings.Contains(m.Attributes, "notag") } diff --git a/src/dev_tools/goMaker/types/types_structure.go b/src/dev_tools/goMaker/types/types_structure.go index f5e640169b..0312035a02 100644 --- a/src/dev_tools/goMaker/types/types_structure.go +++ b/src/dev_tools/goMaker/types/types_structure.go @@ -26,6 +26,7 @@ type Structure struct { DisableGo bool `json:"disable_go,omitempty" toml:"disable_go"` DisableDocs bool `json:"disable_docs,omitempty" toml:"disable_docs"` Attributes string `json:"attributes,omitempty" toml:"attributes"` + Sorts string `json:"sorts,omitempty" toml:"sorts"` Members []Member `json:"members,omitempty" toml:"members"` Route string `json:"-" toml:"-"` Producers []string `json:"-" toml:"-"` @@ -101,7 +102,7 @@ func (s *Structure) HasSorts() bool { return true } } - return strings.Contains(s.Attributes, "sorts=") + return len(s.Sorts) > 0 } func (s *Structure) NeedsAddress() bool { @@ -216,105 +217,79 @@ func (s *Structure) TsTypeMembers() string { return strings.Join(ret, "\n") } -func (s *Structure) parseType(which string) (string, string) { - which += "=" - attrs := s.Attributes - if !strings.Contains(attrs, which) { - return "", "" - } - attrs = strings.ReplaceAll(attrs, which, "`") - parts := strings.Split(attrs, "`") - parts = strings.Split(parts[1], "|") - parts = strings.Split(parts[0], ".") - - first, second := parts[0], "" - if len(parts) > 1 { - second = parts[1] +// ====== for browse code gen ====================================== +func (s *Structure) findItems() Member { + for _, m := range s.Members { + if m.IsItems() { + return m + } } + logger.Fatal("no item in structure: ", s.Class) + return Member{} +} - return first, second +func (s *Structure) ItemFullType() string { + return s.findItems().Type } func (s *Structure) ItemName() string { - _, typ := s.parseType("itemType") - return typ + m := s.findItems() + parts := strings.Split(m.Type, ".") + if len(parts) < 2 { + logger.Fatal("bad embed type (needs two parts): ", m.Type) + } + return parts[1] } func (s *Structure) ItemType() string { - pkg, typ := s.parseType("itemType") - if strings.HasPrefix(pkg, "types") { - return FirstUpper(typ) + m := s.findItems() + parts := strings.Split(m.Type, ".") + if len(parts) < 2 { + logger.Fatal("bad embed type (needs two parts): ", m.Type) } - return FirstLower(pkg) + "." + FirstUpper(typ) -} - -func (s *Structure) InputType() string { - pkg, typ := s.parseType("inputType") - if typ == "" { - return s.ItemType() - } else if strings.HasPrefix(pkg, "types") { - return FirstUpper(typ) + if strings.HasPrefix(parts[0], "types") { + return FirstUpper(parts[1]) } - return FirstLower(pkg) + "." + FirstUpper(typ) + return FirstLower(parts[0]) + "." + FirstUpper(parts[1]) } func (s *Structure) EmbedName() string { - _, typ := s.parseType("embedType") - return Lower(typ) + for _, m := range s.Members { + if m.IsEmbed() { + parts := strings.Split(m.Type, ".") + if len(parts) < 2 { + logger.Fatal("bad embed type (needs two parts): ", m.Type) + } + return Lower(parts[1]) + } + } + return "" } func (s *Structure) EmbedType() string { - pkg, typ := s.parseType("embedType") - if pkg == "types" { - return FirstUpper(typ) + for _, m := range s.Members { + if m.IsEmbed() { + parts := strings.Split(m.Type, ".") + if len(parts) < 2 { + logger.Fatal("bad embed type (needs two parts): ", m.Type) + } + if parts[0] == "types" { + return FirstUpper(parts[1]) + } + return FirstLower(parts[0]) + "." + FirstUpper(parts[1]) + } } - return FirstLower(pkg) + "." + FirstUpper(typ) -} - -func (s *Structure) OtherName() string { - _, typ := s.parseType("otherType") - return Lower(typ) -} - -func (s *Structure) OtherType() string { - pkg, typ := s.parseType("otherType") - return FirstLower(pkg) + "." + FirstUpper(typ) -} - -func (s *Structure) HasItems() bool { - return strings.Contains(s.Attributes, "itemType=") -} - -func (s *Structure) HasEmbed() bool { - return strings.Contains(s.Attributes, "embedType=") -} - -func (s *Structure) HasOther() bool { - return strings.Contains(s.Attributes, "otherType=") -} - -func (s *Structure) NeedsChain() bool { - return !strings.Contains(s.Attributes, "noChain") -} - -func (s *Structure) InitChain() bool { - return !s.NeedsChain() && strings.Contains(s.Attributes, "initChain") -} - -func (s *Structure) NeedsFetch() bool { - return !strings.Contains(s.Attributes, "noFetch") -} - -func (s *Structure) NeedsType() bool { - return !strings.Contains(s.Attributes, "noType") + return "" } -func (s *Structure) NeedsPaging() bool { - return !strings.Contains(s.Attributes, "noPaging") +func (s *Structure) Needs(which string) bool { + no := "no" + FirstUpper(which) + return !strings.Contains(s.Attributes, no) } -func (s *Structure) IsEditable() bool { - return strings.Contains(s.Attributes, "editable") +func (s *Structure) Wants(which string) bool { + wants := "wants" + FirstUpper(which) + return strings.Contains(s.Attributes, wants) } func (s *Structure) SortsInstance() string { @@ -322,81 +297,40 @@ func (s *Structure) SortsInstance() string { return "" } - ret := "sdk.SortSpec {\n" - spec, _ := s.parseType("sorts") - fields := strings.Split(spec, ",") - // logger.Info(fields) - // logger.Info() flds := []string{} orders := []string{} + spec := s.Sorts + fields := strings.Split(spec, ",") for _, field := range fields { - // logger.Info(field) - // logger.Info() parts := strings.Split(field, "+") if len(parts) > 1 { flds = append(flds, "\""+parts[0]+"\"") orders = append(orders, "sdk."+parts[1]) } } + ret := "sdk.SortSpec {\n" ret += "\tFields: []string{" + strings.Join(flds, ",") + "},\n" ret += "\tOrder: []sdk.SortOrder{" + strings.Join(orders, ",") + "},\n" ret += "}," return ret } -func (s *Structure) UiHotKey() string { - keys := map[string]string{ - "project": "1", - "history": "2", - "monitors": "3", - "names": "4", - "abis": "5", - "indexes": "6", - "manifests": "7", - "status": "8", - "settings": "9", - "daemons": "0", - "session": "u", - "config": "v", - "wizard": "w", +func (s *Structure) getUiRoutePart(p int) string { + parts := strings.Split(s.UiRoute, "-") + if len(parts) != 3 { + logger.Fatal("should be three parts to ", s.UiRoute) } - return keys[s.UiRouteName()] -} - -func (s *Structure) IsHistory() bool { - return s.UiRouteName() == "history" -} - -func (s *Structure) IsProject() bool { - return s.UiRouteName() == "project" -} - -func (s *Structure) IsWizard() bool { - return s.UiRouteName() == "wizard" + return parts[p] } func (s *Structure) UiRouteNum() uint64 { - parts := strings.Split(s.UiRoute, "-") - return base.MustParseUint64(parts[0]) + return base.MustParseUint64(s.getUiRoutePart(0)) } func (s *Structure) UiRouteName() string { - parts := strings.Split(s.UiRoute, "-") - return parts[1] -} - -func (s *Structure) UiRouteRoute() string { - ret := Lower(s.UiRouteName()) - if ret == "project" { - return "" - } - return ret + return FirstUpper(s.getUiRoutePart(1)) } -func (s *Structure) UiRouteLabel() string { - return FirstUpper(s.UiRouteName()) -} - -func (s *Structure) UiRouteLower() string { - return Lower(s.UiRouteName()) +func (s *Structure) UiHotKey() string { + return s.getUiRoutePart(2) } diff --git a/src/dev_tools/goMaker/types/utils.go b/src/dev_tools/goMaker/types/utils.go index 1647646759..bbd34860af 100644 --- a/src/dev_tools/goMaker/types/utils.go +++ b/src/dev_tools/goMaker/types/utils.go @@ -64,6 +64,20 @@ func getGeneratorContents(fullPath, subPath, group, reason string) string { } func convertToDestPath(source, routeTag, typeTag, groupTag, reason string) string { + var singularWords = map[string]bool{ + "project": true, + "history": true, + "session": true, + "config": true, + "wizard": true, + } + viewName := func(s string) string { + if singularWords[typeTag] { + return Proper(s) + } + return Proper(Plural(typeTag)) + } + dest := strings.ReplaceAll(source, GetTemplatePath(), "") dest = strings.ReplaceAll(dest, ".tmpl", "") dest = strings.ReplaceAll(dest, "_route_", "/"+routeTag+"/") @@ -73,6 +87,7 @@ func convertToDestPath(source, routeTag, typeTag, groupTag, reason string) strin dest = strings.ReplaceAll(dest, "route.py", routeTag+".py") dest = strings.ReplaceAll(dest, "route.ts", routeTag+".ts") dest = strings.ReplaceAll(dest, "+type+", "+"+typeTag+"+") + dest = strings.ReplaceAll(dest, "_capType", "_"+viewName(typeTag)) dest = strings.ReplaceAll(dest, "type+sort", typeTag+"+sort") dest = strings.ReplaceAll(dest, "type.go", typeTag+".go") dest = strings.ReplaceAll(dest, "type.md", typeTag+".md") diff --git a/src/dev_tools/indexManager/go.mod b/src/dev_tools/indexManager/go.mod index d3d2dc25a7..c629c059ac 100644 --- a/src/dev_tools/indexManager/go.mod +++ b/src/dev_tools/indexManager/go.mod @@ -5,7 +5,7 @@ go 1.22 replace github.com/TrueBlocks/trueblocks-core/sdk => ../../../sdk -require github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c +require github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 require ( github.com/ethereum/go-ethereum v1.13.15 // indirect diff --git a/src/dev_tools/indexManager/go.sum b/src/dev_tools/indexManager/go.sum index acb93dd395..e955ead956 100644 --- a/src/dev_tools/indexManager/go.sum +++ b/src/dev_tools/indexManager/go.sum @@ -1,5 +1,5 @@ -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c h1:ovWX5iJMpegWJZVbj7JFZlseAqwfhvR3lwxyixLfqWY= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/ethereum/go-ethereum v1.13.15 h1:U7sSGYGo4SPjP6iNIifNoyIAiNjrmQkz6EwQG+/EZWo= github.com/ethereum/go-ethereum v1.13.15/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= diff --git a/src/dev_tools/sdkFuzzer/config.go b/src/dev_tools/sdkFuzzer/config.go index eebdc850f2..436375eb7d 100644 --- a/src/dev_tools/sdkFuzzer/config.go +++ b/src/dev_tools/sdkFuzzer/config.go @@ -54,11 +54,11 @@ func TestConfig(which, value, fn string, opts *sdk.ConfigOptions) { ReportOkay(fn) } } - case "session": - if session, _, err := opts.ConfigSession(); err != nil { + case "dump": + if dump, _, err := opts.ConfigDump(); err != nil { ReportError(fn, opts, err) } else { - if err := SaveToFile[types.Session](fn, session); err != nil { + if err := SaveToFile[types.Config](fn, dump); err != nil { ReportError2(fn, err) } else { ReportOkay(fn) diff --git a/src/dev_tools/sdkFuzzer/go.mod b/src/dev_tools/sdkFuzzer/go.mod index 1e09711af9..726bc2a6c5 100644 --- a/src/dev_tools/sdkFuzzer/go.mod +++ b/src/dev_tools/sdkFuzzer/go.mod @@ -4,7 +4,7 @@ module github.com/TrueBlocks/trueblocks-core/sdkFuzzer go 1.22 require ( - github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c + github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 ) diff --git a/src/dev_tools/sdkFuzzer/go.sum b/src/dev_tools/sdkFuzzer/go.sum index c5bfadcf3b..60df299a47 100644 --- a/src/dev_tools/sdkFuzzer/go.sum +++ b/src/dev_tools/sdkFuzzer/go.sum @@ -40,8 +40,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c h1:ovWX5iJMpegWJZVbj7JFZlseAqwfhvR3lwxyixLfqWY= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 h1:v6BDg0K+dIjuo6eawM9iqpJYGPRRiXVCqdSfKvSSvFk= github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0/go.mod h1:b+mmDB9qd+a9DsZRoJs72TalsBULCHHXi0tNmcNM1ng= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= diff --git a/src/dev_tools/testRunner/go.mod b/src/dev_tools/testRunner/go.mod index de1a6c6b88..f6df7c8726 100644 --- a/src/dev_tools/testRunner/go.mod +++ b/src/dev_tools/testRunner/go.mod @@ -6,7 +6,7 @@ go 1.22 replace github.com/TrueBlocks/trueblocks-core/sdk => ../../../sdk require ( - github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c + github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 ) diff --git a/src/dev_tools/testRunner/go.sum b/src/dev_tools/testRunner/go.sum index c5bfadcf3b..60df299a47 100644 --- a/src/dev_tools/testRunner/go.sum +++ b/src/dev_tools/testRunner/go.sum @@ -40,8 +40,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c h1:ovWX5iJMpegWJZVbj7JFZlseAqwfhvR3lwxyixLfqWY= -github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103191228-02c20058347c/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= +github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 h1:v6BDg0K+dIjuo6eawM9iqpJYGPRRiXVCqdSfKvSSvFk= github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0/go.mod h1:b+mmDB9qd+a9DsZRoJs72TalsBULCHHXi0tNmcNM1ng= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= From 67e9e353a01af574da48e4afadf4b4210f8eadf2 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 09:40:55 -0500 Subject: [PATCH 05/13] Updates cleanings --- src/apps/chifra/cmd/config.go | 5 +-- src/apps/chifra/go.mod | 3 -- src/apps/chifra/go.sum | 10 ----- src/apps/chifra/internal/chunks/handle_pin.go | 4 +- src/apps/chifra/internal/chunks/handle_tag.go | 2 +- src/apps/chifra/pkg/logger/colored.go | 10 +++-- src/apps/chifra/pkg/logger/timer.go | 3 +- src/apps/chifra/pkg/manifest/manifest_read.go | 2 +- src/apps/chifra/pkg/manifest/remove_chunk.go | 4 +- src/apps/chifra/pkg/rpc/ping.go | 38 +++++++++++++++++++ src/apps/chifra/pkg/utils/paths.go | 6 +++ 11 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 src/apps/chifra/pkg/rpc/ping.go diff --git a/src/apps/chifra/cmd/config.go b/src/apps/chifra/cmd/config.go index 2ce16619ca..8e5bcc3615 100644 --- a/src/apps/chifra/cmd/config.go +++ b/src/apps/chifra/cmd/config.go @@ -54,10 +54,7 @@ func init() { configCmd.Flags().SortFlags = false configCmd.Flags().BoolVarP(&configPkg.GetOptions().Paths, "paths", "a", false, `show the configuration paths for the system`) - configCmd.Flags().BoolVarP(&configPkg.GetOptions().Session, "session", "s", false, `standin for ui code - no purpose (hidden)`) - if os.Getenv("TEST_MODE") != "true" { - _ = configCmd.Flags().MarkHidden("session") - } + configCmd.Flags().BoolVarP(&configPkg.GetOptions().Dump, "dump", "d", false, `dump the configuration to stdout`) globals.InitGlobals("config", configCmd, &configPkg.GetOptions().Globals, capabilities) configCmd.SetUsageTemplate(UsageWithNotes(notesConfig)) diff --git a/src/apps/chifra/go.mod b/src/apps/chifra/go.mod index ed6ca75006..31355ecd40 100644 --- a/src/apps/chifra/go.mod +++ b/src/apps/chifra/go.mod @@ -15,7 +15,6 @@ require ( github.com/panjf2000/ants/v2 v2.10.0 github.com/pelletier/go-toml/v2 v2.2.2 github.com/spf13/cobra v1.7.0 - github.com/wailsapp/wails/v2 v2.8.2 github.com/wealdtech/go-ens/v3 v3.5.2 golang.org/x/crypto v0.25.0 golang.org/x/term v0.22.0 @@ -47,8 +46,6 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/ipfs/boxo v0.8.0 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/leaanthony/slicer v1.6.0 // indirect - github.com/leaanthony/u v1.1.0 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-libp2p v0.27.8 // indirect diff --git a/src/apps/chifra/go.sum b/src/apps/chifra/go.sum index f3bb7ca953..512b4a6108 100644 --- a/src/apps/chifra/go.sum +++ b/src/apps/chifra/go.sum @@ -439,10 +439,6 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= -github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js= -github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8= -github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI= -github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -455,8 +451,6 @@ github.com/libp2p/go-libp2p v0.27.8/go.mod h1:eCFFtd0s5i/EVKR7+5Ki8bM7qwkNW3TPTT github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= -github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -615,8 +609,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= -github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= @@ -693,8 +685,6 @@ github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBn github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= -github.com/wailsapp/wails/v2 v2.8.2 h1:rYOn9p+7bJiZuFSi2wDyq8rBLHrIX/FoUxov+RpdUOI= -github.com/wailsapp/wails/v2 v2.8.2/go.mod h1:5pTURIST4yZ/wRcmqDUtnM0Mk+caNax/oS610hFiy74= github.com/wealdtech/go-ens/v3 v3.5.2 h1:70CAIiG9hcue6Ja5wxWcnCwi5UfmiW5NH1styxpAbgU= github.com/wealdtech/go-ens/v3 v3.5.2/go.mod h1:4qs2EEeTmv538RoB8QjLS9w5N1HSXS253qhLyNEShBs= github.com/wealdtech/go-multicodec v1.4.0 h1:iq5PgxwssxnXGGPTIK1srvt6U5bJwIp7k6kBrudIWxg= diff --git a/src/apps/chifra/internal/chunks/handle_pin.go b/src/apps/chifra/internal/chunks/handle_pin.go index 58d65f009d..f2b4009fc5 100644 --- a/src/apps/chifra/internal/chunks/handle_pin.go +++ b/src/apps/chifra/internal/chunks/handle_pin.go @@ -42,7 +42,7 @@ func (opts *ChunksOptions) HandlePin(rCtx *output.RenderCtx, blockNums []base.Bl outPath := filepath.Join(config.PathToCache(chain), "tmp", "manifest.json") if opts.Rewrite { - outPath = config.PathToManifest(chain) + outPath = config.PathToManifestFile(chain) } man, err := manifest.LoadManifest(chain, opts.PublisherAddr, manifest.LocalCache) @@ -154,7 +154,7 @@ func (opts *ChunksOptions) HandlePin(rCtx *output.RenderCtx, blockNums []base.Bl report.TimestampHash = localHash } - manPath := config.PathToManifest(chain) + manPath := config.PathToManifestFile(chain) if opts.Deep { manPath = outPath } diff --git a/src/apps/chifra/internal/chunks/handle_tag.go b/src/apps/chifra/internal/chunks/handle_tag.go index a99765c0cc..a491cb44e0 100644 --- a/src/apps/chifra/internal/chunks/handle_tag.go +++ b/src/apps/chifra/internal/chunks/handle_tag.go @@ -82,7 +82,7 @@ func (opts *ChunksOptions) HandleTag(rCtx *output.RenderCtx, blockNums []base.Bl man.Version = opts.Tag man.Specification = base.IpfsHash(config.SpecTags[opts.Tag]) - _ = man.SaveManifest(chain, config.PathToManifest(chain)) + _ = man.SaveManifest(chain, config.PathToManifestFile(chain)) // All that's left to do is report on what happened. msg := fmt.Sprintf("%d chunks were retagged with %s.", nChunksTagged, opts.Tag) diff --git a/src/apps/chifra/pkg/logger/colored.go b/src/apps/chifra/pkg/logger/colored.go index 5d5fd16cfc..1d16aa6c57 100644 --- a/src/apps/chifra/pkg/logger/colored.go +++ b/src/apps/chifra/pkg/logger/colored.go @@ -5,9 +5,13 @@ import ( ) func toColored(s severity, color string, v ...any) { - args := append([]interface{}{color}, v...) - args = append(args, colors.Off) - toLog(s, args...) + if firstElement, ok := v[0].(string); ok { + v[0] = color + firstElement + } else { + v = append([]interface{}{color}, v...) + } + v = append(v, colors.Off) + toLog(s, v...) } func InfoR(v ...any) { diff --git a/src/apps/chifra/pkg/logger/timer.go b/src/apps/chifra/pkg/logger/timer.go index 005f3b9dc9..846f32ae15 100644 --- a/src/apps/chifra/pkg/logger/timer.go +++ b/src/apps/chifra/pkg/logger/timer.go @@ -69,8 +69,7 @@ func (t *Timer) Report(msg string) { return y } - // nItems := 0 - fmt.Printf("PERF,%s%s,%d,%d\n", strings.Repeat("_", t.level), msg, max(1, since.Milliseconds()), max(1, diff.Milliseconds())) + Info(fmt.Sprintf("PERF,%s%s,%d,%d\n", strings.Repeat("_", t.level), msg, max(1, since.Milliseconds()), max(1, diff.Milliseconds()))) t.lastReport = time.Now() } diff --git a/src/apps/chifra/pkg/manifest/manifest_read.go b/src/apps/chifra/pkg/manifest/manifest_read.go index d9ace919ae..d7ecd37974 100644 --- a/src/apps/chifra/pkg/manifest/manifest_read.go +++ b/src/apps/chifra/pkg/manifest/manifest_read.go @@ -21,7 +21,7 @@ import ( // one. If it does (or if the file didn't exist), it saves the new manifest to the file. Finally, it // creates a map of chunks for easy lookup and sets the specification if it is not already set. func LoadManifest(chain string, publisher base.Address, source Source) (man *Manifest, err error) { - manifestFn := config.PathToManifest(chain) + manifestFn := config.PathToManifestFile(chain) exists := file.FileExists(manifestFn) man = &Manifest{} diff --git a/src/apps/chifra/pkg/manifest/remove_chunk.go b/src/apps/chifra/pkg/manifest/remove_chunk.go index 54583531e1..a1031d56fc 100644 --- a/src/apps/chifra/pkg/manifest/remove_chunk.go +++ b/src/apps/chifra/pkg/manifest/remove_chunk.go @@ -14,7 +14,7 @@ import ( // function aborts due to error and the backup files still exist, the function will attempt // to restore the backup files before returning. func RemoveChunk(chain string, publisher base.Address, bloomFn, indexFn string) (err error) { - manifestFn := config.PathToManifest(chain) + manifestFn := config.PathToManifestFile(chain) manifestBackup := manifestFn + ".backup" indexBackup := indexFn + ".backup" @@ -87,7 +87,7 @@ func RemoveChunk(chain string, publisher base.Address, bloomFn, indexFn string) } } man.Chunks = newChunks - if err = man.SaveManifest(chain, config.PathToManifest(chain)); err != nil { + if err = man.SaveManifest(chain, config.PathToManifestFile(chain)); err != nil { return err } diff --git a/src/apps/chifra/pkg/rpc/ping.go b/src/apps/chifra/pkg/rpc/ping.go new file mode 100644 index 0000000000..bf914510b9 --- /dev/null +++ b/src/apps/chifra/pkg/rpc/ping.go @@ -0,0 +1,38 @@ +package rpc + +import ( + "bytes" + "context" + "fmt" + "net/http" + "time" +) + +// PingRpc sends a ping request to the RPC provider, returns an error or nil on success. +func PingRpc(providerUrl string) error { + // Set a timeout of, for example, 2 seconds for the request + ctx, cancel := context.WithTimeout(context.Background(), 2000*time.Millisecond) + defer cancel() + + jsonData := []byte(`{ "jsonrpc": "2.0", "method": "web3_clientVersion", "id": 6 }`) + req, err := http.NewRequestWithContext(ctx, "POST", providerUrl, bytes.NewBuffer(jsonData)) + if err != nil { + return err + } + + req.Header.Set("Content-Type", "application/json") + + clientHTTP := &http.Client{} + resp, err := clientHTTP.Do(req) + if err != nil { + // If the context timeout triggers, this error will reflect it + return err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + + return nil +} diff --git a/src/apps/chifra/pkg/utils/paths.go b/src/apps/chifra/pkg/utils/paths.go index 3910fdcd3f..2f8da195f0 100644 --- a/src/apps/chifra/pkg/utils/paths.go +++ b/src/apps/chifra/pkg/utils/paths.go @@ -8,6 +8,12 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" ) +// MustGetConfigFn ignore errors on GetConfigFn +func MustGetConfigFn(appDir, fn string) string { + ret, _ := GetConfigFn(appDir, fn) + return ret +} + // GetConfigFn returns the user's (OS-specific) configuration folder. If the folder // is not found, an error is returned. If appDir is not empty, it is appended to // the configDir and if the resulting folder does not exist, it is created. From aeb31f51f23294cb09dbb295bcdec5fdf0dd1c4f Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 09:42:12 -0500 Subject: [PATCH 06/13] Updates for chifra config --dump --- .../{handle_session.go => handle_dump.go} | 11 +- src/apps/chifra/internal/config/options.go | 11 +- src/apps/chifra/internal/config/output.go | 4 +- .../internal/init/handle_init_download.go | 2 +- src/apps/chifra/pkg/config/paths.go | 4 +- .../chifra/pkg/configtypes/chain_group.go | 2 +- src/apps/chifra/pkg/types/types_abi.go | 4 + src/apps/chifra/pkg/types/types_chunkstats.go | 4 + src/apps/chifra/pkg/types/types_config.go | 44 ++ src/apps/chifra/pkg/types/types_manifest.go | 8 + src/apps/chifra/pkg/types/types_session.go | 442 ------------------ src/apps/chifra/pkg/types/types_status.go | 1 + 12 files changed, 82 insertions(+), 455 deletions(-) rename src/apps/chifra/internal/config/{handle_session.go => handle_dump.go} (52%) create mode 100644 src/apps/chifra/pkg/types/types_config.go delete mode 100644 src/apps/chifra/pkg/types/types_session.go diff --git a/src/apps/chifra/internal/config/handle_session.go b/src/apps/chifra/internal/config/handle_dump.go similarity index 52% rename from src/apps/chifra/internal/config/handle_session.go rename to src/apps/chifra/internal/config/handle_dump.go index e4f56cfce5..47e09c19e7 100644 --- a/src/apps/chifra/internal/config/handle_session.go +++ b/src/apps/chifra/internal/config/handle_dump.go @@ -1,14 +1,19 @@ package configPkg import ( + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) -// HandleSession returns an empty session -func (opts *ConfigOptions) HandleSession(rCtx *output.RenderCtx) error { +// HandleDump dumps a config to the screen +func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error { fetchData := func(modelChan chan types.Modeler, errorChan chan error) { - modelChan <- &types.Session{} + var s types.Config + s.Config = *config.GetRootConfig() + modelChan <- &s } + + opts.Globals.NoHeader = true return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) } diff --git a/src/apps/chifra/internal/config/options.go b/src/apps/chifra/internal/config/options.go index 3500b07b47..2591bff2b2 100644 --- a/src/apps/chifra/internal/config/options.go +++ b/src/apps/chifra/internal/config/options.go @@ -28,7 +28,7 @@ import ( type ConfigOptions struct { Mode string `json:"mode,omitempty"` // Either show or edit the configuration Paths bool `json:"paths,omitempty"` // Show the configuration paths for the system - Session bool `json:"session,omitempty"` // Standin for ui code - no purpose + Dump bool `json:"dump,omitempty"` // Dump the configuration to stdout Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed @@ -42,7 +42,7 @@ var defaultConfigOptions = ConfigOptions{} func (opts *ConfigOptions) testLog() { logger.TestLog(len(opts.Mode) > 0, "Mode: ", opts.Mode) logger.TestLog(opts.Paths, "Paths: ", opts.Paths) - logger.TestLog(opts.Session, "Session: ", opts.Session) + logger.TestLog(opts.Dump, "Dump: ", opts.Dump) opts.Conn.TestLog(opts.getCaches()) opts.Globals.TestLog() } @@ -72,8 +72,8 @@ func ConfigFinishParseInternal(w io.Writer, values url.Values) *ConfigOptions { opts.Mode = value[0] case "paths": opts.Paths = true - case "session": - opts.Session = true + case "dump": + opts.Dump = true default: if !copy.Globals.Caps.HasKey(key) { err := validate.Usage("Invalid key ({0}) in {1} route.", key, "config") @@ -118,6 +118,9 @@ func configFinishParse(args []string) *ConfigOptions { if len(opts.Mode) == 0 { opts.Mode = "" } + if opts.Dump { + opts.Globals.Format = "json" + } // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt diff --git a/src/apps/chifra/internal/config/output.go b/src/apps/chifra/internal/config/output.go index 5daa67a29a..15843ba199 100644 --- a/src/apps/chifra/internal/config/output.go +++ b/src/apps/chifra/internal/config/output.go @@ -56,8 +56,8 @@ func (opts *ConfigOptions) ConfigInternal(rCtx *output.RenderCtx) error { // EXISTING_CODE if opts.Paths { err = opts.HandlePaths(rCtx) - } else if opts.Session { - err = opts.HandleSession(rCtx) + } else if opts.Dump { + err = opts.HandleDump(rCtx) } else { err = opts.HandleShow(rCtx) } diff --git a/src/apps/chifra/internal/init/handle_init_download.go b/src/apps/chifra/internal/init/handle_init_download.go index d20ef7a5e5..ec6ce93756 100644 --- a/src/apps/chifra/internal/init/handle_init_download.go +++ b/src/apps/chifra/internal/init/handle_init_download.go @@ -181,7 +181,7 @@ func (opts *InitOptions) updateLocalManifest(existing, remote *manifest.Manifest } } - return copy.SaveManifest(chain, config.PathToManifest(chain)) + return copy.SaveManifest(chain, config.PathToManifestFile(chain)) } var spaces = strings.Repeat(" ", 55) diff --git a/src/apps/chifra/pkg/config/paths.go b/src/apps/chifra/pkg/config/paths.go index 780dfb9ab6..cb669a3345 100644 --- a/src/apps/chifra/pkg/config/paths.go +++ b/src/apps/chifra/pkg/config/paths.go @@ -32,8 +32,8 @@ func PathToChainConfig(chain string) (string, error) { return cfgFolder, err } -// PathToManifest returns the path to the manifest database per chain -func PathToManifest(chain string) string { +// PathToManifestFile returns the path to the manifest database per chain +func PathToManifestFile(chain string) string { return filepath.Join(PathToIndex(chain), "manifest.json") } diff --git a/src/apps/chifra/pkg/configtypes/chain_group.go b/src/apps/chifra/pkg/configtypes/chain_group.go index 8090e95a8a..e99add6df8 100644 --- a/src/apps/chifra/pkg/configtypes/chain_group.go +++ b/src/apps/chifra/pkg/configtypes/chain_group.go @@ -8,7 +8,7 @@ type ChainGroup struct { IpfsGateway string `json:"ipfsGateway" toml:"ipfsGateway,omitempty"` KeyEndpoint string `json:"keyEndpoint" toml:"keyEndpoint,omitempty"` LocalExplorer string `json:"localExplorer" toml:"localExplorer,omitempty"` - RemoteExplorer string `json:"removeExplorer" toml:"remoteExplorer,omitempty"` + RemoteExplorer string `json:"remoteExplorer" toml:"remoteExplorer,omitempty"` RpcProvider string `json:"rpcProvider" toml:"rpcProvider"` Symbol string `json:"symbol" toml:"symbol"` Scrape ScrapeSettings `json:"scrape" toml:"scrape"` diff --git a/src/apps/chifra/pkg/types/types_abi.go b/src/apps/chifra/pkg/types/types_abi.go index 79948b17fc..05c46b79c1 100644 --- a/src/apps/chifra/pkg/types/types_abi.go +++ b/src/apps/chifra/pkg/types/types_abi.go @@ -130,4 +130,8 @@ func (s *Abi) FinishUnmarshal() { } // EXISTING_CODE +func (s *Abi) ShallowCopy() Abi { + return *s +} + // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkstats.go b/src/apps/chifra/pkg/types/types_chunkstats.go index 4cf21fd106..828c20c3ce 100644 --- a/src/apps/chifra/pkg/types/types_chunkstats.go +++ b/src/apps/chifra/pkg/types/types_chunkstats.go @@ -98,4 +98,8 @@ func (s *ChunkStats) FinishUnmarshal() { } // EXISTING_CODE +func (s *ChunkStats) ShallowCopy() ChunkStats { + return *s +} + // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_config.go b/src/apps/chifra/pkg/types/types_config.go new file mode 100644 index 0000000000..2946308472 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_config.go @@ -0,0 +1,44 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +package types + +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes" +) + +type Config struct { + configtypes.Config +} + +func (s Config) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *Config) Model(chain, format string, verbose bool, extraOpts map[string]any) Model { + // keys := map[string]any{} + // for key, value := range s.Keys { + // keys[key] = value + // } + c := map[string]any{} + for key, value := range s.Chains { + c[key] = value + } + return Model{ + Data: map[string]any{ + "version": s.Version, + "settings": s.Settings, + "keys": s.Keys, + "pinnging": s.Pinning, + "unchained": s.Unchained, + "chains": s.Chains, + }, + Order: []string{}, + } +} + +func (s *Config) FinishUnmarshal() { +} diff --git a/src/apps/chifra/pkg/types/types_manifest.go b/src/apps/chifra/pkg/types/types_manifest.go index 7631e71a67..cb6ebf9d42 100644 --- a/src/apps/chifra/pkg/types/types_manifest.go +++ b/src/apps/chifra/pkg/types/types_manifest.go @@ -65,4 +65,12 @@ func (s *Manifest) FinishUnmarshal() { } // EXISTING_CODE +func (s *Manifest) ShallowCopy() Manifest { + return Manifest{ + Chain: s.Chain, + Specification: s.Specification, + Version: s.Version, + } +} + // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_session.go b/src/apps/chifra/pkg/types/types_session.go deleted file mode 100644 index 6d98ecd184..0000000000 --- a/src/apps/chifra/pkg/types/types_session.go +++ /dev/null @@ -1,442 +0,0 @@ -package types - -import ( - "context" - "encoding/json" - "errors" - "fmt" - - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" - "github.com/wailsapp/wails/v2/pkg/runtime" -) - -// Session stores ephemeral things such as last window position, -// last view, and recent file list. -type Session struct { - LastChain string `json:"lastChain"` - LastFile string `json:"lastFile"` - LastFolder string `json:"lastFolder"` - LastRoute string `json:"lastRoute"` - LastSub map[string]string `json:"lastSub"` - Window Window `json:"window"` - Wizard Wizard `json:"wizard"` - Toggles Toggles `json:"toggles"` - Chain string `json:"-"` -} - -func (s Session) String() string { - bytes, _ := json.Marshal(s) - return string(bytes) -} - -func (s *Session) Model(chain, format string, verbose bool, extraOpts map[string]any) Model { - var model = map[string]any{} - var order = []string{} - - model = map[string]any{ - "lastChain": s.LastChain, - "lastFile": s.LastFile, - "lastFolder": s.LastFolder, - "lastRoute": s.LastRoute, - "window": s.Window, - "wizard": s.Wizard, - "toggles": s.Toggles, - } - order = []string{ - "lastChain", - "lastFile", - "lastFolder", - "lastRoute", - "window", - "wizard", - "toggles", - } - - return Model{model, order} -} - -func (s *Session) FinishUnmarshal() { - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *Session) ShallowCopy() Session { - return *s -} - -const theTitle = "Browse by TrueBlocks" - -var defLayout = Layout{ - Header: true, - Menu: true, - Help: true, - Footer: true, -} - -var defHeader = Headers{ - Project: false, - History: true, - Monitors: false, - Names: false, - Abis: false, - Indexes: false, - Manifests: false, - Status: true, - Settings: true, -} - -var defDaemons = Daemons{ - Freshen: true, -} - -var defaultSession = Session{ - LastChain: "mainnet", - LastFile: "Untitled.tbx", - LastRoute: "/wizard", - LastSub: map[string]string{"/history": "0xf503017d7baf7fbc0fff7492b751025c6a78179b"}, - Window: Window{ - X: 0, - Y: 0, - Width: 0, - Height: 0, - Title: theTitle, - }, - Wizard: Wizard{State: Welcome}, - Toggles: Toggles{ - Layout: defLayout, - Headers: defHeader, - Daemons: defDaemons, - }, -} - -// Save saves the session to the configuration folder. -func (s *Session) Save() error { - if fn, err := utils.GetConfigFn("browse", "session.json"); err != nil { - return err - } else { - if contents, _ := json.MarshalIndent(s, "", " "); len(contents) > 0 { - _ = file.StringToAsciiFile(fn, string(contents)) - } - return nil - } -} - -var ErrLoadingSession = errors.New("error loading session") - -// Load loads the session from the configuration folder. If the file contains -// data, we return true. False otherwise. -func (s *Session) Load() error { - loaded := false - defer func() { - if !loaded { - *s = defaultSession - } else { - // Ensure a valid file (if for example the user edited it) - if s.Wizard.State == Okay && s.LastRoute == "/wizard" { - s.LastRoute = "/" - } - if s.LastChain == "" { - s.LastChain = "mainnet" - } - if s.LastFile == "" { - s.LastFile = "Untitled.tbx" - } - } - _ = s.Save() // creates the session file if it doesn't already exist - }() - - fn, err := utils.GetConfigFn("browse", "session.json") - if err != nil { - return fmt.Errorf("%w: %v", ErrLoadingSession, err) - } - - contents := file.AsciiFileToString(fn) - if len(contents) == 0 { - // This is not an error (the default session will be used) - return nil - } - - if err = json.Unmarshal([]byte(contents), s); err != nil { - return fmt.Errorf("%w: %v", ErrLoadingSession, err) - } - - loaded = true - return nil -} - -func (s *Session) SetRoute(route, subRoute string) { - s.LastRoute = route - if len(subRoute) > 0 { - s.LastSub[route] = subRoute - } - _ = s.Save() -} - -var ErrScreenNotFound = errors.New("screen not found") - -// CleanWindowSize ensures a valid window size. (If the app has never run before -// or the session fails to load its width or height will be zero.) This function -// always returns a valid window size, but it may also return an error. -func (s *Session) CleanWindowSize(ctx context.Context) (Window, error) { - // Any window size other than 0,0 is already okay. - if s.Window.Width != 0 && s.Window.Height != 0 { - return s.Window, nil - } - - ret := Window{X: 30, Y: 30, Width: 1024, Height: 768} - defer func() { - _ = s.Save() - }() - - if screens, err := runtime.ScreenGetAll(ctx); err != nil { - return ret, fmt.Errorf("error getting screens %w", err) - - } else { - var fullScreen *Window = nil - for _, screen := range screens { - if screen.IsCurrent || screen.IsPrimary { - fullScreen = &Window{ - Width: screen.Size.Width, - Height: screen.Size.Height, - } - break - } - } - if fullScreen != nil { - // We found the screen, so we can set a reasonable window size. - s.Window.X = fullScreen.Width / 6 - s.Window.Y = fullScreen.Width / 6 - s.Window.Width = (5 * fullScreen.Width) / 6 - s.Window.Height = (5 * fullScreen.Width) / 6 - } - } - return s.Window, nil -} - -type Layout struct { - Header bool `json:"header"` - Menu bool `json:"menu"` - Help bool `json:"help"` - Footer bool `json:"footer"` -} - -type Headers struct { - Project bool `json:"project"` - History bool `json:"history"` - Monitors bool `json:"monitors"` - Names bool `json:"names"` - Abis bool `json:"abis"` - Indexes bool `json:"indexes"` - Manifests bool `json:"manifests"` - Status bool `json:"status"` - Settings bool `json:"settings"` -} - -type Daemons struct { - Freshen bool `json:"freshen"` - Scraper bool `json:"scraper"` - Ipfs bool `json:"ipfs"` -} - -type Toggles struct { - Layout Layout `json:"layout"` - Headers Headers `json:"headers"` - Daemons Daemons `json:"daemons"` -} - -func (t *Toggles) IsOn(which string) bool { - if which == "" { - which = "project" - } - switch which { - case "header": - return t.Layout.Header - case "menu": - return t.Layout.Menu - case "help": - return t.Layout.Help - case "footer": - return t.Layout.Footer - case "project": - return t.Headers.Project - case "history": - return t.Headers.History - case "monitors": - return t.Headers.Monitors - case "names": - return t.Headers.Names - case "abis": - return t.Headers.Abis - case "indexes": - return t.Headers.Indexes - case "manifests": - return t.Headers.Manifests - case "status": - return t.Headers.Status - case "settings": - return t.Headers.Settings - case "freshen": - return t.Daemons.Freshen - case "scraper": - return t.Daemons.Scraper - case "ipfs": - return t.Daemons.Ipfs - } - return false -} - -func (t *Toggles) SetState(which string, onOff bool) { - if which == "" { - which = "project" - } - switch which { - case "header": - t.Layout.Header = onOff - case "menu": - t.Layout.Menu = onOff - case "help": - t.Layout.Help = onOff - case "footer": - t.Layout.Footer = onOff - case "project": - t.Headers.Project = onOff - case "history": - t.Headers.History = onOff - case "monitors": - t.Headers.Monitors = onOff - case "names": - t.Headers.Names = onOff - case "abis": - t.Headers.Abis = onOff - case "indexes": - t.Headers.Indexes = onOff - case "manifests": - t.Headers.Manifests = onOff - case "status": - t.Headers.Status = onOff - case "settings": - t.Headers.Settings = onOff - case "freshen": - t.Daemons.Freshen = onOff - case "scraper": - t.Daemons.Scraper = onOff - case "ipfs": - t.Daemons.Ipfs = onOff - } -} - -// Window stores the last position and title of the window -type Window struct { - X int `json:"x"` - Y int `json:"y"` - Width int `json:"width"` - Height int `json:"height"` - Title string `json:"title"` -} - -func (w *Window) String() string { - bytes, _ := json.Marshal(w) - return string(bytes) -} - -type Wizard struct { - State WizState `json:"state"` -} - -var stateOrder = []WizState{ - Welcome, - Error, - TomlOkay, - RpcOkay, - BloomsOkay, - IndexOkay, - Okay, -} - -func (w *Wizard) Step(step WizStep) { - switch step { - case Reset: - w.State = Error - case Previous: - if w.State == TomlOkay { - w.State = Welcome - } else { - for i := range stateOrder { - if stateOrder[i] == w.State && i > 0 { - w.State = stateOrder[i-1] - break - } - } - } - case Next: - if w.State == Welcome { - w.State = TomlOkay - } else { - for i := range stateOrder { - if stateOrder[i] == w.State && i < len(stateOrder)-1 { - w.State = stateOrder[i+1] - break - } - } - } - case Finish: - w.State = Okay - } -} - -type WizState string - -const ( - Welcome WizState = "welcome" - TomlOkay WizState = "tomlOkay" - RpcOkay WizState = "rpcOkay" - BloomsOkay WizState = "bloomsOkay" - IndexOkay WizState = "indexOkay" - Error WizState = "error" - Okay WizState = "okay" -) - -// String returns the string representation of the WizState. -func (s WizState) String() string { - return string(s) -} - -// AllStates - all possible WizStates for the frontend codegen -var AllStates = []struct { - Value WizState `json:"value"` - TSName string `json:"tsName"` -}{ - {Welcome, "WELCOME"}, - {TomlOkay, "TOMLOKAY"}, - {RpcOkay, "RPCOKAY"}, - {BloomsOkay, "BLOOMSOKAY"}, - {IndexOkay, "INDEXOKAY"}, - {Error, "ERROR"}, - {Okay, "OKAY"}, -} - -type WizStep string - -const ( - Reset WizStep = "Reset" - Previous WizStep = "Previous" - Next WizStep = "Next" - Finish WizStep = "Finish" -) - -// String returns the string representation of the Step. -func (s WizStep) String() string { - return string(s) -} - -// AllSteps - all possible steps for the frontend codegen -var AllSteps = []struct { - Value WizStep `json:"value"` - TSName string `json:"tsName"` -}{ - {Reset, "RESET"}, - {Previous, "PREVIOUS"}, - {Next, "NEXT"}, - {Finish, "FINISH"}, -} diff --git a/src/apps/chifra/pkg/types/types_status.go b/src/apps/chifra/pkg/types/types_status.go index e4bc105b9f..34ff54a13f 100644 --- a/src/apps/chifra/pkg/types/types_status.go +++ b/src/apps/chifra/pkg/types/types_status.go @@ -157,6 +157,7 @@ func (s *Status) ShallowCopy() Status { s.Caches = nil ret := *s s.Caches = caches + ret.Chain = s.Chain return ret } From 610a178dd5777dfd48f41f76ad6a36614e4ba06c Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 09:42:45 -0500 Subject: [PATCH 07/13] Updates all updates --- docs | 2 +- examples | 2 +- node | 2 +- sdk | 2 +- tests | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs b/docs index b6f85082fd..4ee7263bbb 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit b6f85082fd063b80a926ddd260d2adffb5610636 +Subproject commit 4ee7263bbb575a2b59a5ce3863aac68a87932d13 diff --git a/examples b/examples index 64d09d9c11..1b3af5629c 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 64d09d9c11f514eb7503cd5917b7cc025f6c778d +Subproject commit 1b3af5629c9543269aae2afb9020e1eeb91632cd diff --git a/node b/node index 6f0cc43dd1..6b58ecbcfe 160000 --- a/node +++ b/node @@ -1 +1 @@ -Subproject commit 6f0cc43dd1e86a87eaa93fdf927f6fd9f2bc7968 +Subproject commit 6b58ecbcfe3e24b988628521643efaf6f67dca4f diff --git a/sdk b/sdk index 9cc169f6ea..a690f1dcd8 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 9cc169f6ea27e8fdf2c59ce49c898f93a0d756dd +Subproject commit a690f1dcd883c7df50fb22956004c7f45593c13e diff --git a/tests b/tests index a03f2f5fa4..3d390674b3 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit a03f2f5fa428ea6bccdd57434b97342bd1decdbd +Subproject commit 3d390674b3ee56e9c155aef8dcc43e24f1bd2487 From 9a7d34064e3c6bb2e5de8b858b106676e6b1ed4a Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 10:12:21 -0500 Subject: [PATCH 08/13] Various updates --- .github/workflows/build-and-test.yml | 12 ++++++------ examples | 2 +- node | 2 +- src/CMakeLists.txt | 1 + src/dev_tools/sdkFuzzer/go.mod | 2 +- src/dev_tools/sdkFuzzer/go.sum | 4 ++-- src/dev_tools/testRunner/go.mod | 2 +- src/dev_tools/testRunner/go.sum | 4 ++-- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cbf681dd92..ad0e5347c1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -37,22 +37,22 @@ jobs: run: | sudo apt-mark hold grub-efi-amd64-signed sudo apt-get update --fix-missing - sudo apt-get upgrade - sudo apt-get install build-essential git cmake - sudo apt-get install python3 tree jq - sudo apt-get install libcurl3-dev + sudo apt-get upgrade -y + sudo apt-get install -y build-essential git cmake + sudo apt-get install -y python3 tree jq + sudo apt-get install -y libcurl4-openssl-dev - name: Run basic golang unit tests run: | mkdir -p build cd build ../scripts/go-work-sync.sh - cmake ../src + cmake ../src -Wno-dev cd other/install make cd ../../../ cd ${{ env.CHIFRA_PATH }} export TB_NO_PROVIDER_CHECK=true - go test ./... + go test -v ./... 2>&1 | tee test_output.log RemoteTests: needs: Build runs-on: ubuntu-latest diff --git a/examples b/examples index 1b3af5629c..92fbb1bd6c 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 1b3af5629c9543269aae2afb9020e1eeb91632cd +Subproject commit 92fbb1bd6c5f17c827ad8857f804a46db51ea452 diff --git a/node b/node index 6b58ecbcfe..db068b6f2b 160000 --- a/node +++ b/node @@ -1 +1 @@ -Subproject commit 6b58ecbcfe3e24b988628521643efaf6f67dca4f +Subproject commit db068b6f2be7ffc0a9375356cb300207cf119084 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20829d095d..02ffdbec31 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required (VERSION 3.5) +cmake_policy(SET CMP0074 NEW) # ---------------------------------------------------------------------------------------- if(NOT WIN32) diff --git a/src/dev_tools/sdkFuzzer/go.mod b/src/dev_tools/sdkFuzzer/go.mod index 726bc2a6c5..c71d624f7a 100644 --- a/src/dev_tools/sdkFuzzer/go.mod +++ b/src/dev_tools/sdkFuzzer/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 - github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 + github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0 ) require ( diff --git a/src/dev_tools/sdkFuzzer/go.sum b/src/dev_tools/sdkFuzzer/go.sum index 60df299a47..494a5e7fc3 100644 --- a/src/dev_tools/sdkFuzzer/go.sum +++ b/src/dev_tools/sdkFuzzer/go.sum @@ -42,8 +42,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= -github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 h1:v6BDg0K+dIjuo6eawM9iqpJYGPRRiXVCqdSfKvSSvFk= -github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0/go.mod h1:b+mmDB9qd+a9DsZRoJs72TalsBULCHHXi0tNmcNM1ng= +github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0 h1:5ekcTuR1cPWcr4GSHO15p3QtycaZyo095vKbiw3wYB4= +github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0/go.mod h1:KgHs6YTCCbQwOrT15Z1Zhi6H0on/PIlFr6aP/ktzL1w= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= diff --git a/src/dev_tools/testRunner/go.mod b/src/dev_tools/testRunner/go.mod index f6df7c8726..4e3c065d4b 100644 --- a/src/dev_tools/testRunner/go.mod +++ b/src/dev_tools/testRunner/go.mod @@ -7,7 +7,7 @@ replace github.com/TrueBlocks/trueblocks-core/sdk => ../../../sdk require ( github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 - github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 + github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0 ) require ( diff --git a/src/dev_tools/testRunner/go.sum b/src/dev_tools/testRunner/go.sum index 60df299a47..494a5e7fc3 100644 --- a/src/dev_tools/testRunner/go.sum +++ b/src/dev_tools/testRunner/go.sum @@ -42,8 +42,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63 h1:+Sinnuci96Ie+kUKiIn5EeUtCunsTTT4au22daUZcDI= github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20241103193928-2a3d9f89af63/go.mod h1:gsyd2/TDvhZ2reZIutMYRoqqhHiFbPG0b4OG1uI+HL8= -github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0 h1:v6BDg0K+dIjuo6eawM9iqpJYGPRRiXVCqdSfKvSSvFk= -github.com/TrueBlocks/trueblocks-sdk/v3 v3.8.0/go.mod h1:b+mmDB9qd+a9DsZRoJs72TalsBULCHHXi0tNmcNM1ng= +github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0 h1:5ekcTuR1cPWcr4GSHO15p3QtycaZyo095vKbiw3wYB4= +github.com/TrueBlocks/trueblocks-sdk/v3 v3.9.0/go.mod h1:KgHs6YTCCbQwOrT15Z1Zhi6H0on/PIlFr6aP/ktzL1w= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= From 364c253c2c61c47b38d96176d621330db30fbbc5 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 10:42:30 -0500 Subject: [PATCH 09/13] Adds Config type to types package --- src/apps/chifra/internal/config/handle_dump.go | 11 +++++++++-- src/apps/chifra/pkg/configtypes/config.go | 4 ---- src/apps/chifra/pkg/types/types_config.go | 11 ++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/apps/chifra/internal/config/handle_dump.go b/src/apps/chifra/internal/config/handle_dump.go index 47e09c19e7..7744bc8f94 100644 --- a/src/apps/chifra/internal/config/handle_dump.go +++ b/src/apps/chifra/internal/config/handle_dump.go @@ -9,8 +9,15 @@ import ( // HandleDump dumps a config to the screen func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error { fetchData := func(modelChan chan types.Modeler, errorChan chan error) { - var s types.Config - s.Config = *config.GetRootConfig() + config := *config.GetRootConfig() + s := types.Config{ + Version: config.Version, + Settings: config.Settings, + Keys: config.Keys, + Pinning: config.Pinning, + Unchained: config.Unchained, + Chains: config.Chains, + } modelChan <- &s } diff --git a/src/apps/chifra/pkg/configtypes/config.go b/src/apps/chifra/pkg/configtypes/config.go index 55704a1230..74c2ac4e85 100644 --- a/src/apps/chifra/pkg/configtypes/config.go +++ b/src/apps/chifra/pkg/configtypes/config.go @@ -24,10 +24,6 @@ func (s *Config) String() string { return string(bytes) } -func (s *Config) ShallowCopy() Config { - return *s -} - func NewConfig(cachePath, indexPath, defaultIpfs string) Config { ret := defaultConfig ret.Settings.CachePath = cachePath diff --git a/src/apps/chifra/pkg/types/types_config.go b/src/apps/chifra/pkg/types/types_config.go index 2946308472..68c3c8ba5f 100644 --- a/src/apps/chifra/pkg/types/types_config.go +++ b/src/apps/chifra/pkg/types/types_config.go @@ -10,7 +10,12 @@ import ( ) type Config struct { - configtypes.Config + Version configtypes.VersionGroup `json:"version" toml:"version"` + Settings configtypes.SettingsGroup `json:"settings" toml:"settings"` + Keys map[string]configtypes.KeyGroup `json:"keys" toml:"keys"` + Pinning configtypes.PinningGroup `json:"pinning" toml:"pinning"` + Unchained configtypes.UnchainedGroup `json:"unchained" toml:"unchained,omitempty" comment:"Do not edit these values unless instructed to do so."` + Chains map[string]configtypes.ChainGroup `json:"chains" toml:"chains"` } func (s Config) String() string { @@ -42,3 +47,7 @@ func (s *Config) Model(chain, format string, verbose bool, extraOpts map[string] func (s *Config) FinishUnmarshal() { } + +func (s *Config) ShallowCopy() Config { + return *s +} From a5aa3976fa588d2377256afbfbb2903829013d65 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 11:04:21 -0500 Subject: [PATCH 10/13] Cleanings --- .github/workflows/build-and-test.yml | 5 ++++- node | 2 +- src/CMakeLists.txt | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index ad0e5347c1..cc54371b84 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -8,6 +8,9 @@ jobs: Lint: runs-on: ubuntu-latest steps: + - name: Clean Go module cache + run: | + rm -rf $HOME/go/pkg/mod - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: @@ -46,7 +49,7 @@ jobs: mkdir -p build cd build ../scripts/go-work-sync.sh - cmake ../src -Wno-dev + cmake ../src -Wno-dev -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON cd other/install make cd ../../../ diff --git a/node b/node index db068b6f2b..d135c40ae9 160000 --- a/node +++ b/node @@ -1 +1 @@ -Subproject commit db068b6f2be7ffc0a9375356cb300207cf119084 +Subproject commit d135c40ae9f7faa44c9ac00bdd2fde1cdd139f28 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02ffdbec31..20829d095d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required (VERSION 3.5) -cmake_policy(SET CMP0074 NEW) # ---------------------------------------------------------------------------------------- if(NOT WIN32) From 0d44ea39dc0829955da502b2908db89869ce7a94 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 11:06:24 -0500 Subject: [PATCH 11/13] Cleanings --- .github/workflows/build-and-test.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cc54371b84..cbf681dd92 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -8,9 +8,6 @@ jobs: Lint: runs-on: ubuntu-latest steps: - - name: Clean Go module cache - run: | - rm -rf $HOME/go/pkg/mod - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: @@ -40,22 +37,22 @@ jobs: run: | sudo apt-mark hold grub-efi-amd64-signed sudo apt-get update --fix-missing - sudo apt-get upgrade -y - sudo apt-get install -y build-essential git cmake - sudo apt-get install -y python3 tree jq - sudo apt-get install -y libcurl4-openssl-dev + sudo apt-get upgrade + sudo apt-get install build-essential git cmake + sudo apt-get install python3 tree jq + sudo apt-get install libcurl3-dev - name: Run basic golang unit tests run: | mkdir -p build cd build ../scripts/go-work-sync.sh - cmake ../src -Wno-dev -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON + cmake ../src cd other/install make cd ../../../ cd ${{ env.CHIFRA_PATH }} export TB_NO_PROVIDER_CHECK=true - go test -v ./... 2>&1 | tee test_output.log + go test ./... RemoteTests: needs: Build runs-on: ubuntu-latest From 7ebc85672db07cdad7781d2d0225c6e4f3c26d43 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 11:12:53 -0500 Subject: [PATCH 12/13] Cleanings --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cbf681dd92..96b2cb238a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -18,7 +18,7 @@ jobs: run: | ./scripts/go-work-sync.sh - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: version: v1.61.0 working-directory: ${{ env.CHIFRA_PATH }} From d58a067056d77d5e5fbe7ca19fd3d7d511ce7d3a Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Mon, 25 Nov 2024 11:16:36 -0500 Subject: [PATCH 13/13] Cleanings --- .github/workflows/build-and-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 96b2cb238a..e24dded0cd 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,6 +23,7 @@ jobs: version: v1.61.0 working-directory: ${{ env.CHIFRA_PATH }} args: --timeout=5m --verbose --out-format=colored-line-number + skip-pkg-cache: true Build: needs: Lint runs-on: ubuntu-20.04