github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/transactions/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 transactionsPkg 6 7 import ( 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" 11 ) 12 13 func (opts *TransactionsOptions) validateTransactions() error { 14 chain := opts.Globals.Chain 15 16 opts.testLog() 17 18 if opts.BadFlag != nil { 19 return opts.BadFlag 20 } 21 22 if !config.IsChainConfigured(chain) { 23 return validate.Usage("chain {0} is not properly configured.", chain) 24 } 25 26 if len(opts.Flow) > 0 { 27 if !opts.Uniq { 28 return validate.Usage("The {0} option is only available with the {1} option", "--flow", "--uniq") 29 } 30 err := validate.ValidateEnum("flow", opts.Flow, "[from|to]") 31 if err != nil { 32 return err 33 } 34 } 35 36 if len(opts.Globals.File) > 0 { 37 // Do nothing 38 } else { 39 if !opts.Logs && (len(opts.Emitter) > 0 || len(opts.Topic) > 0) { 40 return validate.Usage("The {0} option are only available with the {1} option.", "--emitter and --topic", "--log") 41 } else if opts.Logs { 42 for _, emitter := range opts.Emitter { 43 valid, err := base.IsValidAddressE(emitter) 44 if !valid { 45 return err 46 } 47 } 48 49 for _, topic := range opts.Topic { 50 valid, err := validate.IsValidTopicE(topic) 51 if !valid { 52 return err 53 } 54 } 55 } 56 57 if len(opts.Transactions) == 0 { 58 return validate.Usage("Please supply one or more transaction identifiers.") 59 } 60 61 if opts.Traces { 62 err, ok := opts.Conn.IsNodeTracing() 63 if !ok { 64 return validate.Usage("{0} requires tracing, err: {1}", "chifra export --traces", err.Error()) 65 } 66 if opts.Uniq { 67 return validate.Usage("The {0} option is not available{1}.", "--uniq", " with the --traces option") 68 } 69 } 70 71 if !validate.HasArticulationKey(opts.Articulate) { 72 return validate.Usage("The {0} option requires an Etherscan API key.", "--articulate") 73 } 74 } 75 76 err := validate.ValidateIdentifiers( 77 chain, 78 opts.Transactions, 79 validate.ValidTransId, 80 -1, 81 &opts.TransactionIds, 82 ) 83 if err != nil { 84 if invalidLiteral, ok := err.(*validate.InvalidIdentifierLiteralError); ok { 85 return invalidLiteral 86 } 87 return err 88 } 89 90 return opts.Globals.Validate() 91 }