github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/logs/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 logsPkg
     6  
     7  import (
     8  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
     9  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate"
    10  )
    11  
    12  func (opts *LogsOptions) validateLogs() error {
    13  	chain := opts.Globals.Chain
    14  
    15  	opts.testLog()
    16  
    17  	if opts.BadFlag != nil {
    18  		return opts.BadFlag
    19  	}
    20  
    21  	if !config.IsChainConfigured(chain) {
    22  		return validate.Usage("chain {0} is not properly configured.", chain)
    23  	}
    24  
    25  	if len(opts.Globals.File) > 0 {
    26  		// Do nothing
    27  	} else {
    28  		if len(opts.Transactions) == 0 {
    29  			return validate.Usage("Please supply one or more transaction identifiers.")
    30  		}
    31  		if !validate.HasArticulationKey(opts.Articulate) {
    32  			return validate.Usage("The {0} option requires an Etherscan API key.", "--articulate")
    33  		}
    34  	}
    35  
    36  	err := validate.ValidateIdentifiers(
    37  		chain,
    38  		opts.Transactions,
    39  		validate.ValidTransId,
    40  		-1,
    41  		&opts.TransactionIds,
    42  	)
    43  	if err != nil {
    44  		if invalidLiteral, ok := err.(*validate.InvalidIdentifierLiteralError); ok {
    45  			return invalidLiteral
    46  		}
    47  		return err
    48  	}
    49  
    50  	return opts.Globals.Validate()
    51  }