diff --git a/docs b/docs index 744361bd5c..8aa87665c4 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 744361bd5c69b3d483170de3df2d9a023b603155 +Subproject commit 8aa87665c486f45346e54bea8513b9cf25c8643a diff --git a/sdk b/sdk index ff1ff09efc..69ee1ae440 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit ff1ff09efcbe70405e377c1133d77e0c1940af8d +Subproject commit 69ee1ae440c229f3b7a9925e31a33008d1478979 diff --git a/src/apps/chifra/cmd/explore.go b/src/apps/chifra/cmd/explore.go index 7973f3f851..6fa8ec4ca0 100644 --- a/src/apps/chifra/cmd/explore.go +++ b/src/apps/chifra/cmd/explore.go @@ -48,15 +48,11 @@ const notesExplore = `` func init() { var capabilities caps.Capability // capabilities for chifra explore - capabilities = capabilities.Add(caps.Verbose) - capabilities = capabilities.Add(caps.Version) - capabilities = capabilities.Add(caps.Noop) - capabilities = capabilities.Add(caps.NoColor) - capabilities = capabilities.Add(caps.Chain) - capabilities = capabilities.Add(caps.File) + capabilities = capabilities.Add(caps.Default) exploreCmd.Flags().SortFlags = false + exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().NoOpen, "no_open", "n", false, `return the URL without opening it`) exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Local, "local", "l", false, `open the local TrueBlocks explorer`) exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Google, "google", "g", false, `search google excluding popular blockchain explorers`) exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Dalle, "dalle", "d", false, `open the address to the DalleDress explorer (hidden)`) diff --git a/src/apps/chifra/internal/explore/README.md b/src/apps/chifra/internal/explore/README.md index d17107365f..6e1538f31f 100644 --- a/src/apps/chifra/internal/explore/README.md +++ b/src/apps/chifra/internal/explore/README.md @@ -15,14 +15,15 @@ Arguments: terms - one or more address, name, block, or transaction identifier Flags: - -l, --local open the local TrueBlocks explorer - -g, --google search google excluding popular blockchain explorers - -h, --help display this help screen + -n, --no_open return the URL without opening it + -l, --local open the local TrueBlocks explorer + -g, --google search google excluding popular blockchain explorers + -h, --help display this help screen ``` Data models produced by this tool: -- none +- [destination](/data-model/other/#destination) ### Other Options diff --git a/src/apps/chifra/internal/explore/handle_show.go b/src/apps/chifra/internal/explore/handle_show.go index cf92e3df39..6c26fc1e71 100644 --- a/src/apps/chifra/internal/explore/handle_show.go +++ b/src/apps/chifra/internal/explore/handle_show.go @@ -1,21 +1,23 @@ package explorePkg import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func (opts *ExploreOptions) HandleShow(rCtx *output.RenderCtx) error { - for _, url := range urls { - ret := url.getUrl(opts) - if !opts.Globals.TestMode { - logger.Info("Opening", ret) - utils.OpenBrowser(ret) - } else { - logger.Info("Not opening", ret, "in test mode") + fetchData := func(modelChan chan types.Modeler, errorChan chan error) { + for _, dest := range opts.Destinations { + dests := dest.Resolve(opts.Globals.Chain, opts.Google, opts.Dalle, opts.Local) + for _, d := range dests { + if !opts.NoOpen && !opts.Globals.TestMode { + utils.OpenBrowser(d.Url) + } + modelChan <- &d + } } } - return nil + return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) } diff --git a/src/apps/chifra/internal/explore/options.go b/src/apps/chifra/internal/explore/options.go index 9259f45066..45aba7152d 100644 --- a/src/apps/chifra/internal/explore/options.go +++ b/src/apps/chifra/internal/explore/options.go @@ -14,14 +14,13 @@ import ( "io" "net/http" "net/url" - "path" "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk" // EXISTING_CODE @@ -30,6 +29,7 @@ import ( // ExploreOptions provides all command options for the chifra explore command. type ExploreOptions struct { Terms []string `json:"terms,omitempty"` // One or more address, name, block, or transaction identifier + NoOpen bool `json:"noOpen,omitempty"` // Return the URL without opening it Local bool `json:"local,omitempty"` // Open the local TrueBlocks explorer Google bool `json:"google,omitempty"` // Search google excluding popular blockchain explorers Dalle bool `json:"dalle,omitempty"` // Open the address to the DalleDress explorer @@ -37,6 +37,7 @@ type ExploreOptions struct { Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE + Destinations []types.Destination // EXISTING_CODE } @@ -45,6 +46,7 @@ var defaultExploreOptions = ExploreOptions{} // testLog is used only during testing to export the options for this test case. func (opts *ExploreOptions) testLog() { logger.TestLog(len(opts.Terms) > 0, "Terms: ", opts.Terms) + logger.TestLog(opts.NoOpen, "NoOpen: ", opts.NoOpen) logger.TestLog(opts.Local, "Local: ", opts.Local) logger.TestLog(opts.Google, "Google: ", opts.Google) logger.TestLog(opts.Dalle, "Dalle: ", opts.Dalle) @@ -78,6 +80,8 @@ func ExploreFinishParseInternal(w io.Writer, values url.Values) *ExploreOptions s := strings.Split(val, " ") // may contain space separated items opts.Terms = append(opts.Terms, s...) } + case "noOpen": + opts.NoOpen = true case "local": opts.Local = true case "google": @@ -140,12 +144,7 @@ func GetOptions() *ExploreOptions { func getCaps() caps.Capability { var capabilities caps.Capability // capabilities for chifra explore - capabilities = capabilities.Add(caps.Verbose) - capabilities = capabilities.Add(caps.Version) - capabilities = capabilities.Add(caps.Noop) - capabilities = capabilities.Add(caps.NoColor) - capabilities = capabilities.Add(caps.Chain) - capabilities = capabilities.Add(caps.File) + capabilities = capabilities.Add(caps.Default) // EXISTING_CODE // EXISTING_CODE return capabilities @@ -169,61 +168,4 @@ func (opts *ExploreOptions) getCaches() (caches map[walk.CacheType]bool) { } // EXISTING_CODE -func (u *ExploreUrl) getUrl(opts *ExploreOptions) string { - - var chain = opts.Globals.Chain - - if opts.Google { - var query = "https://www.google.com/search?q=[{TERM}]" - query = strings.Replace(query, "[{TERM}]", u.term, -1) - var exclusions = []string{ - "etherscan", "etherchain", "bloxy", "bitquery", "ethplorer", "tokenview", "anyblocks", "explorer", - } - for _, ex := range exclusions { - query += ("+-" + ex) - } - return query - } - - if opts.Dalle { - var query = "http://192.34.63.136:8080/dalle/simple/[{TERM}]" - return strings.Replace(query, "[{TERM}]", u.term, -1) - } - - if u.termType == ExploreFourByte { - var query = "https://www.4byte.directory/signatures/?bytes4_signature=[{TERM}]" - query = strings.Replace(query, "[{TERM}]", u.term, -1) - return query - } - - if u.termType == ExploreEnsName { - var query = "https://app.ens.domains/name/[{TERM}]/details" - query = strings.Replace(query, "[{TERM}]", u.term, -1) - return query - } - - url := config.GetChain(chain).RemoteExplorer - query := "" - switch u.termType { - case ExploreNone: - // do nothing - case ExploreTx: - query = path.Join("tx", u.term) - case ExploreBlock: - query = path.Join("block", u.term) - case ExploreAddress: - fallthrough - default: - query = path.Join("address", u.term) - } - - if opts.Local { - url = config.GetChain(chain).LocalExplorer - query = strings.Replace(query, "tx/", "explorer/transactions/", -1) - query = strings.Replace(query, "block/", "explorer/blocks/", -1) - } - - return url + query -} - // EXISTING_CODE diff --git a/src/apps/chifra/internal/explore/validate.go b/src/apps/chifra/internal/explore/validate.go index 9f68961a4e..39bcfb5f93 100644 --- a/src/apps/chifra/internal/explore/validate.go +++ b/src/apps/chifra/internal/explore/validate.go @@ -10,29 +10,11 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" "github.com/ethereum/go-ethereum" ) -type ExploreType uint8 - -const ( - ExploreNone ExploreType = iota - ExploreAddress - ExploreName - ExploreEnsName - ExploreTx - ExploreBlock - ExploreFourByte -) - -type ExploreUrl struct { - term string - termType ExploreType -} - -var urls []ExploreUrl - func (opts *ExploreOptions) validateExplore() error { chain := opts.Globals.Chain @@ -67,28 +49,24 @@ func (opts *ExploreOptions) validateExplore() error { if base.IsValidAddress(arg) { if strings.Contains(arg, ".eth") { - urls = append(urls, ExploreUrl{arg, ExploreEnsName}) + opts.Destinations = append(opts.Destinations, types.NewDestination(arg, types.DestinationEnsName)) } else { - urls = append(urls, ExploreUrl{arg, ExploreAddress}) + opts.Destinations = append(opts.Destinations, types.NewDestination(arg, types.DestinationAddress)) } // We got a valid address, we're done checking continue } // The argument is not an address, so we can't use --google - if opts.Google { - return validate.Usage("The {0} option requires {1}.", "--google", "an address term") - } - - if opts.Dalle { - return validate.Usage("The {0} option requires {1}.", "--dalle", "an address term") + if opts.Google || opts.Dalle { + continue } valid, _ := validate.IsValidTransId(chain, []string{arg}, validate.ValidTransId) if valid { txHash, err := opts.idToTxHash(arg, validate.IsBlockHash) if err == nil { - urls = append(urls, ExploreUrl{txHash, ExploreTx}) + opts.Destinations = append(opts.Destinations, types.NewDestination(txHash, types.DestinationTx)) continue } // an error here is okay since we can't distinquish between tx hashes and block hashes... @@ -98,7 +76,7 @@ func (opts *ExploreOptions) validateExplore() error { if valid { blockHash, err := opts.idToBlockHash(chain, arg, validate.IsBlockHash) if err == nil { - urls = append(urls, ExploreUrl{blockHash.Hex(), ExploreBlock}) + opts.Destinations = append(opts.Destinations, types.NewDestination(blockHash.Hex(), types.DestinationBlock)) continue } // An error here is not okay because we have a valid hash but it's not a valid on-chain @@ -107,41 +85,23 @@ func (opts *ExploreOptions) validateExplore() error { } if validate.IsValidFourByte(arg) { - urls = append(urls, ExploreUrl{arg, ExploreFourByte}) + opts.Destinations = append(opts.Destinations, types.NewDestination(arg, types.DestinationFourByte)) continue } return validate.Usage("The {0} option ({1}) {2}.", "term", arg, "is not valid") } - if len(urls) == 0 { - urls = append(urls, ExploreUrl{"", ExploreNone}) + if len(opts.Destinations) == 0 { + if opts.Google || opts.Dalle { + return validate.Usage("The {0} options require {1}.", "--dalle and --google", "an address term") + } + opts.Destinations = append(opts.Destinations, types.NewDestination("", types.DestinationNone)) } return opts.Globals.Validate() } -func (t ExploreType) String() string { - switch t { - case ExploreNone: - return "ExploreNone" - case ExploreAddress: - return "ExploreAddress" - case ExploreName: - return "ExploreName" - case ExploreEnsName: - return "ExploreEnsName" - case ExploreTx: - return "ExploreTx" - case ExploreBlock: - return "ExploreBlock" - case ExploreFourByte: - return "ExploreFourByte" - default: - return fmt.Sprintf("%d", t) - } -} - func (opts *ExploreOptions) idToBlockHash(chain, arg string, isBlockHash func(arg string) bool) (base.Hash, error) { _ = chain // linter if isBlockHash(arg) { diff --git a/src/apps/chifra/pkg/types/types_destination.go b/src/apps/chifra/pkg/types/types_destination.go new file mode 100644 index 0000000000..f656cd1e85 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_destination.go @@ -0,0 +1,175 @@ +// 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. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + "path" + "strings" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" +) + +// EXISTING_CODE + +type Destination struct { + Source string `json:"source"` + Term string `json:"term"` + TermType DestType `json:"termType"` + Url string `json:"url"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s Destination) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *Destination) Model(chain, format string, verbose bool, extraOpts map[string]any) Model { + var model = map[string]any{} + var order = []string{} + + // EXISTING_CODE + model = map[string]any{ + "term": s.Term, + "termType": s.TermType, + "url": s.Url, + "source": s.Source, + } + order = []string{ + "term", + "termType", + "url", + "source", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *Destination) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +type DestType string + +const ( + DestinationNone DestType = "none" + DestinationAddress DestType = "address" + DestinationName DestType = "name" + DestinationEnsName DestType = "ensName" + DestinationTx DestType = "tx" + DestinationBlock DestType = "block" + DestinationFourByte DestType = "4byte" +) + +func (t DestType) String() string { + switch t { + case DestinationNone: + return "DestinationNone" + case DestinationAddress: + return "DestinationAddress" + case DestinationName: + return "DestinationName" + case DestinationEnsName: + return "DestinationEnsName" + case DestinationTx: + return "DestinationTx" + case DestinationBlock: + return "DestinationBlock" + case DestinationFourByte: + return "DestinationFourByte" + default: + return "Invalid DestType" + } +} + +func NewDestination(term string, termType DestType) Destination { + return Destination{ + Term: term, + TermType: termType, + } +} + +func NewDestinationEx(exp Destination, url, source string) Destination { + ret := exp + ret.Url = url + ret.Source = source + return ret +} + +func (s *Destination) Resolve(chain string, google, dalle, local bool) []Destination { + ret := []Destination{} + if google { + var query = "https://www.google.com/search?q=[{TERM}]" + query = strings.Replace(query, "[{TERM}]", s.Term, -1) + var exclusions = []string{ + "etherscan", "etherchain", "bloxy", "bitquery", "ethplorer", "tokenview", "anyblocks", "explorer", + } + for _, ex := range exclusions { + query += ("+-" + ex) + } + ret = append(ret, NewDestinationEx(*s, query, "google")) + } + + if dalle { + var query = "http://192.34.63.136:8080/dalle/simple/[{TERM}]" + ret = append(ret, NewDestinationEx(*s, strings.Replace(query, "[{TERM}]", s.Term, -1), "dalle")) + } + + if len(ret) > 0 { + return ret + } + + if s.TermType == DestinationFourByte { + var query = "https://www.4byte.directory/signatures/?bytes4_signature=[{TERM}]" + query = strings.Replace(query, "[{TERM}]", s.Term, -1) + ret = append(ret, NewDestinationEx(*s, query, "url")) + } + + if s.TermType == DestinationEnsName { + var query = "https://app.ens.domains/name/[{TERM}]/details" + query = strings.Replace(query, "[{TERM}]", s.Term, -1) + ret = append(ret, NewDestinationEx(*s, query, "url")) + } + + url := config.GetChain(chain).RemoteExplorer + query := "" + switch s.TermType { + case DestinationNone: + // do nothing + case DestinationTx: + query = path.Join("tx", s.Term) + case DestinationBlock: + query = path.Join("block", s.Term) + case DestinationAddress: + fallthrough + default: + query = path.Join("address", s.Term) + } + + if local { + url = config.GetChain(chain).LocalExplorer + query = strings.Replace(query, "tx/", "explorer/transactions/", -1) + query = strings.Replace(query, "block/", "explorer/blocks/", -1) + } + + ret = append(ret, NewDestinationEx(*s, url+query, "url")) + return ret +} + +// EXISTING_CODE diff --git a/src/apps/chifra/sdk/explore.go b/src/apps/chifra/sdk/explore.go new file mode 100644 index 0000000000..e81c2db687 --- /dev/null +++ b/src/apps/chifra/sdk/explore.go @@ -0,0 +1,34 @@ +// 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. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package sdk + +import ( + "io" + "net/url" + + explore "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/explore" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" + outputHelpers "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output/helpers" +) + +// Explore provides an interface to the command line chifra explore through the SDK. +func Explore(rCtx *output.RenderCtx, w io.Writer, values url.Values) error { + explore.ResetOptions(sdkTestMode) + opts := explore.ExploreFinishParseInternal(w, values) + // EXISTING_CODE + // EXISTING_CODE + outputHelpers.InitJsonWriterApi("explore", w, &opts.Globals) + err := opts.ExploreInternal(rCtx) + outputHelpers.CloseJsonWriterIfNeededApi("explore", err, &opts.Globals) + + return err +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/dev_tools/goMaker/templates/classDefinitions/destination.toml b/src/dev_tools/goMaker/templates/classDefinitions/destination.toml new file mode 100644 index 0000000000..dbb4c29031 --- /dev/null +++ b/src/dev_tools/goMaker/templates/classDefinitions/destination.toml @@ -0,0 +1,7 @@ +[settings] + class = "Destination" + doc_group = "05-Other" + doc_descr = "an enhanced url used by chifra explore" + doc_route = "524-destination" + attributes = "" + produced_by = "explore" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/destination.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/destination.csv new file mode 100644 index 0000000000..a10ddc3130 --- /dev/null +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/destination.csv @@ -0,0 +1,5 @@ +name ,type ,strDefault ,attributes ,docOrder ,description +term ,string , , , 1 ,the term used to produce the url +termType ,DestType , , , 2 ,the type of the term +url ,string , , , 3 ,the url produced +source ,string , , , 4 ,the option that produced the url diff --git a/src/dev_tools/goMaker/templates/cmd-line-options.csv b/src/dev_tools/goMaker/templates/cmd-line-options.csv index f55bfa65e3..a2f73952b8 100644 --- a/src/dev_tools/goMaker/templates/cmd-line-options.csv +++ b/src/dev_tools/goMaker/templates/cmd-line-options.csv @@ -323,8 +323,9 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,handler,option_ty # 51000,,Other,,,,,,,,group,,,,,,Access to other and external data # -52000,apps,Other,explore,fireStorm,,,,visible|docs|notApi,,command,,,Open the explorer,[flags] [terms...],verbose|version|noop|noColor|chain|file|,Open a local or remote explorer for one or more addresses, blocks, or transactions. -52020,apps,Other,explore,fireStorm,terms,,,visible|docs,1,positional,list,,,,,one or more address, name, block, or transaction identifier +52000,apps,Other,explore,fireStorm,,,,visible|docs|notApi,,command,,,Open the explorer,[flags] [terms...],default,Open a local or remote explorer for one or more addresses, blocks, or transactions. +52020,apps,Other,explore,fireStorm,terms,,,visible|docs,1,positional,list,Destination,,,,one or more address, name, block, or transaction identifier +52025,apps,Other,explore,fireStorm,no_open,n,,visible|docs,,switch,,,,,,return the URL without opening it 52030,apps,Other,explore,fireStorm,local,l,,visible|docs,,switch,,,,,,open the local TrueBlocks explorer 52040,apps,Other,explore,fireStorm,google,g,,visible|docs,,switch,,,,,,search google excluding popular blockchain explorers 52050,apps,Other,explore,fireStorm,dalle,d,,,,switch,,,,,,open the address to the DalleDress explorer diff --git a/src/dev_tools/goMaker/types/types_codebase.go b/src/dev_tools/goMaker/types/types_codebase.go index 2c6503e26c..25726a0aa3 100644 --- a/src/dev_tools/goMaker/types/types_codebase.go +++ b/src/dev_tools/goMaker/types/types_codebase.go @@ -143,6 +143,7 @@ var knownTypes = map[string]bool{ "StorageSlot": true, "TokenType": true, "StatePart": true, + "DestType": true, } func (cb *CodeBase) Validate() error { diff --git a/src/dev_tools/goMaker/types/types_sorts.go b/src/dev_tools/goMaker/types/types_sorts.go index b007e89c47..ea0ff50c23 100644 --- a/src/dev_tools/goMaker/types/types_sorts.go +++ b/src/dev_tools/goMaker/types/types_sorts.go @@ -35,7 +35,7 @@ func (c *Command) Sorts2() string { tmpl := ` func Sort{{toPlural .Type}}({{toLowerPlural .Type}} []types.{{.Type}}, sortSpec SortSpec) error { if len(sortSpec.Fields) != len(sortSpec.Order) { - return fmt.Errorf("Fields and Order must have the same length") + return fmt.Errorf("fields and order must have the same length") } sorts := make([]func(p1, p2 types.{{.Type}}) bool, len(sortSpec.Fields)) diff --git a/src/dev_tools/goMaker/types/utils.go b/src/dev_tools/goMaker/types/utils.go index 7f78737992..9cefbe1fff 100644 --- a/src/dev_tools/goMaker/types/utils.go +++ b/src/dev_tools/goMaker/types/utils.go @@ -23,19 +23,22 @@ func shouldProcess(source, subPath, tag string) (bool, error) { return false, nil } - skip := tag == "explore" || tag == "scrape" || tag == "daemon" isSdk := strings.Contains(source, "sdk_") + isPython := strings.Contains(source, "python") + isTypeScript := strings.Contains(source, "typescript") isFuzzer := strings.Contains(source, "sdkFuzzer") - if skip && (isSdk || isFuzzer) { - if tag == "scrape" { - isPython := strings.Contains(source, "python") - isTypeScript := strings.Contains(source, "typescript") - if isPython || isTypeScript || isFuzzer { - // do not generate code for scrape for Python or TypeScript SDKs - return false, nil - } - } else { - // do not generate code for daemon or explore for SDK + switch tag { + case "daemon": + if isSdk || isFuzzer { + return false, nil + } + case "scrape": + if isFuzzer { + return false, nil + } + fallthrough + case "explore": + if isSdk && (isPython || isTypeScript || isFuzzer) { return false, nil } } diff --git a/src/dev_tools/sdkFuzzer/explore.go b/src/dev_tools/sdkFuzzer/explore.go new file mode 100644 index 0000000000..b02ff98567 --- /dev/null +++ b/src/dev_tools/sdkFuzzer/explore.go @@ -0,0 +1,69 @@ +// 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. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ +package main + +// EXISTING_CODE +import ( + "fmt" + "strings" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" + sdk "github.com/TrueBlocks/trueblocks-sdk/v3" +) + +// EXISTING_CODE + +// DoExplore tests the Explore sdk function +func DoExplore() { + file.EstablishFolder("sdkFuzzer-output/explore") + opts := sdk.ExploreOptions{} + ShowHeader("DoExplore", opts) + + globs := noCache(noEther(globals)) + noOpen := []bool{false, true} + local := []bool{false, true} + google := []bool{false, true} + dalle := []bool{false, true} + // Fuzz Loop + // EXISTING_CODE + _ = globs + _ = noOpen + _ = local + _ = google + _ = dalle + // EXISTING_CODE + Wait() +} + +func TestExplore(which, value, fn string, opts *sdk.ExploreOptions) { + fn = strings.Replace(fn, ".json", "-"+which+".json", 1) + // EXISTING_CODE + // EXISTING_CODE + + switch which { + case "explore": + if explore, _, err := opts.Explore(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.Destination](fn, explore); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } + } + default: + ReportError(fn, opts, fmt.Errorf("unknown which: %s", which)) + logger.Fatal("Quitting...") + return + } +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/tests b/tests index d381819eba..8a4f49aa8e 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit d381819eba3bfdb9e16b47685c41cb4857ed63a4 +Subproject commit 8a4f49aa8eee0f0b37c8f70292943e23b6ebb4cf