github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/transactions.go (about)

     1  // Copyright 2016, 2024 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   * Parts of this file were auto generated. Edit only those parts of
     6   * the code inside of 'EXISTING_CODE' tags.
     7   */
     8  
     9  package cmd
    10  
    11  // EXISTING_CODE
    12  import (
    13  	"os"
    14  
    15  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals"
    16  	transactionsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/transactions"
    17  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps"
    18  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
    19  	outputHelpers "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output/helpers"
    20  	"github.com/spf13/cobra"
    21  )
    22  
    23  // EXISTING_CODE
    24  
    25  // transactionsCmd represents the transactions command
    26  var transactionsCmd = &cobra.Command{
    27  	Use:     usageTransactions,
    28  	Long:    longTransactions,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("transactions", func() *globals.GlobalOptions {
    31  		return &transactionsPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("transactions", transactionsPkg.RunTransactions, transactionsPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &transactionsPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageTransactions = `transactions [flags] <tx_id> [tx_id...]
    40  
    41  Arguments:
    42    transactions - a space-separated list of one or more transaction identifiers (required)`
    43  
    44  const longTransactions = `Purpose:
    45    Retrieve one or more transactions from the chain or local cache.`
    46  
    47  const notesTransactions = `
    48  Notes:
    49    - The transactions list may be one or more transaction hashes, blockNumber.transactionID pairs, or a blockHash.transactionID pairs.
    50    - This tool checks for valid input syntax, but does not check that the transaction requested actually exists.
    51    - If the queried node does not store historical state, the results for most older transactions are undefined.
    52    - The --decache option removes the all transaction(s) and all traces in those transactions from the cache.
    53    - The --traces option requires your RPC to provide trace data. See the README for more information.`
    54  
    55  func init() {
    56  	var capabilities caps.Capability // capabilities for chifra transactions
    57  	capabilities = capabilities.Add(caps.Default)
    58  	capabilities = capabilities.Add(caps.Caching)
    59  	capabilities = capabilities.Add(caps.Ether)
    60  	capabilities = capabilities.Add(caps.Names)
    61  
    62  	transactionsCmd.Flags().SortFlags = false
    63  
    64  	transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Articulate, "articulate", "a", false, `articulate the retrieved data if ABIs can be found`)
    65  	transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Traces, "traces", "t", false, `include the transaction's traces in the results`)
    66  	transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Uniq, "uniq", "u", false, `display a list of uniq addresses found in the transaction`)
    67  	transactionsCmd.Flags().StringVarP(&transactionsPkg.GetOptions().Flow, "flow", "f", "", `for the uniq option only, export only from or to (including trace from or to)
    68  One of [ from | to ]`)
    69  	transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Logs, "logs", "l", false, `display only the logs found in the transaction(s)`)
    70  	transactionsCmd.Flags().StringSliceVarP(&transactionsPkg.GetOptions().Emitter, "emitter", "m", nil, `for the --logs option only, filter logs to show only those logs emitted by the given address(es)`)
    71  	transactionsCmd.Flags().StringSliceVarP(&transactionsPkg.GetOptions().Topic, "topic", "B", nil, `for the --logs option only, filter logs to show only those with this topic(s)`)
    72  	transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().CacheTraces, "cache_traces", "R", false, `force the transaction's traces into the cache`)
    73  	globals.InitGlobals("transactions", transactionsCmd, &transactionsPkg.GetOptions().Globals, capabilities)
    74  
    75  	transactionsCmd.SetUsageTemplate(UsageWithNotes(notesTransactions))
    76  	transactionsCmd.SetOut(os.Stderr)
    77  
    78  	// EXISTING_CODE
    79  	// EXISTING_CODE
    80  
    81  	chifraCmd.AddCommand(transactionsCmd)
    82  }