github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/names/handle_show.go (about) 1 package namesPkg 2 3 import ( 4 "strings" 5 6 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 10 ) 11 12 func (opts *NamesOptions) HandleShow(rCtx *output.RenderCtx) error { 13 chain := opts.Globals.Chain 14 testMode := opts.Globals.TestMode 15 namesArray, err := loadNamesArray(chain, opts.getType(), types.SortByAddress, opts.Terms) 16 if err != nil { 17 return err 18 } 19 20 fetchData := func(modelChan chan types.Modeler, errorChan chan error) { 21 if len(namesArray) == 0 { 22 hasAddr := strings.Contains(strings.Join(opts.Terms, " "), "0x") 23 hadEths := strings.Contains(strings.Join(opts.OrigTerms, " "), ".eth") 24 if hadEths && hasAddr { 25 for i, t := range opts.Terms { 26 orig := opts.OrigTerms[i] 27 if strings.Contains(orig, ".eth") { 28 modelChan <- &types.Name{ 29 Tags: "66-ENS", 30 Name: orig, 31 Address: base.HexToAddress(t), 32 } 33 } else if strings.Contains(orig, "0x") { 34 modelChan <- &types.Name{ 35 Tags: "Not found", 36 Address: base.HexToAddress(orig), 37 } 38 } 39 } 40 } else { 41 logger.Warn("No known names found for", opts.Terms) 42 if !testMode { 43 logger.Warn("Original command:", opts.OrigTerms) 44 } 45 } 46 return 47 } else { 48 for _, name := range namesArray { 49 modelChan <- &name 50 } 51 } 52 } 53 54 extraOpts := map[string]any{ 55 "expand": opts.Expand, 56 "prefund": opts.Prefund, 57 } 58 59 if opts.Addr { 60 extraOpts["single"] = "address" 61 opts.Globals.NoHeader = true 62 } 63 64 return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOptsWithExtra(extraOpts)) 65 }