Skip to content

Commit

Permalink
Merge pull request #3907 from TrueBlocks/goMaker-4
Browse files Browse the repository at this point in the history
Many changes to improve usability for browse
  • Loading branch information
tjayrush authored Nov 25, 2024
2 parents c7ca8bd + d58a067 commit 37990b3
Show file tree
Hide file tree
Showing 48 changed files with 353 additions and 631 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ 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 }}
args: --timeout=5m --verbose --out-format=colored-line-number
skip-pkg-cache: true
Build:
needs: Lint
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 1 files
+8 −0 content/api/openapi.yaml
2 changes: 1 addition & 1 deletion node
Submodule node updated 4 files
+2 −1 app/app_config.go
+2 −5 go.mod
+2 −14 go.sum
+0 −26 utils/utils.go
2 changes: 1 addition & 1 deletion sdk
5 changes: 1 addition & 4 deletions src/apps/chifra/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions src/apps/chifra/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/apps/chifra/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/chunks/handle_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions src/apps/chifra/internal/config/handle_dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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"
)

// HandleDump dumps a config to the screen
func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error {
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
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
}

opts.Globals.NoHeader = true
return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts())
}
14 changes: 0 additions & 14 deletions src/apps/chifra/internal/config/handle_session.go

This file was deleted.

11 changes: 7 additions & 4 deletions src/apps/chifra/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -118,6 +118,9 @@ func configFinishParse(args []string) *ConfigOptions {
if len(opts.Mode) == 0 {
opts.Mode = "<empty>"
}
if opts.Dump {
opts.Globals.Format = "json"
}
// EXISTING_CODE
if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" {
opts.Globals.Format = defFmt
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/init/handle_init_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/config/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/configtypes/chain_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 0 additions & 4 deletions src/apps/chifra/pkg/configtypes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/apps/chifra/pkg/logger/colored.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/apps/chifra/pkg/logger/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/manifest/manifest_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/manifest/remove_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
38 changes: 38 additions & 0 deletions src/apps/chifra/pkg/rpc/ping.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions src/apps/chifra/pkg/types/types_abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ func (s *Abi) FinishUnmarshal() {
}

// EXISTING_CODE
func (s *Abi) ShallowCopy() Abi {
return *s
}

// EXISTING_CODE
4 changes: 4 additions & 0 deletions src/apps/chifra/pkg/types/types_chunkstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ func (s *ChunkStats) FinishUnmarshal() {
}

// EXISTING_CODE
func (s *ChunkStats) ShallowCopy() ChunkStats {
return *s
}

// EXISTING_CODE
Loading

0 comments on commit 37990b3

Please sign in to comment.