github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/traces/validate.go (about) 1 // Copyright 2021 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 5 package tracesPkg 6 7 import ( 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" 12 ) 13 14 func (opts *TracesOptions) validateTraces() error { 15 chain := opts.Globals.Chain 16 17 opts.testLog() 18 19 if opts.BadFlag != nil { 20 return opts.BadFlag 21 } 22 23 if !config.IsChainConfigured(chain) { 24 return validate.Usage("chain {0} is not properly configured.", chain) 25 } 26 27 if len(opts.Globals.File) > 0 { 28 // Do nothing 29 } else { 30 if len(opts.Transactions) == 0 && len(opts.Filter) == 0 { 31 return validate.Usage("Please supply one or more transaction identifiers or filters.") 32 } 33 34 err, ok := opts.Conn.IsNodeTracing() 35 if !ok { 36 return validate.Usage("{0} requires tracing, err: {1}", "chifra traces", err.Error()) 37 } 38 39 if !validate.HasArticulationKey(opts.Articulate) { 40 return validate.Usage("The {0} option requires an Etherscan API key.", "--articulate") 41 } 42 43 if len(opts.Filter) > 0 { 44 // TODO: Check validity of the filter string 45 if opts.Globals.TestMode { 46 v := types.TraceFilter{} 47 logger.Info(v.ParseBangString(chain, opts.Filter)) 48 } 49 } 50 } 51 52 err := validate.ValidateIdentifiers( 53 chain, 54 opts.Transactions, 55 validate.ValidTransId, 56 -1, 57 &opts.TransactionIds, 58 ) 59 if err != nil { 60 if invalidLiteral, ok := err.(*validate.InvalidIdentifierLiteralError); ok { 61 return invalidLiteral 62 } 63 return err 64 } 65 66 return opts.Globals.Validate() 67 }