github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/traces.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  	tracesPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/traces"
    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  // tracesCmd represents the traces command
    26  var tracesCmd = &cobra.Command{
    27  	Use:     usageTraces,
    28  	Long:    longTraces,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("traces", func() *globals.GlobalOptions {
    31  		return &tracesPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("traces", tracesPkg.RunTraces, tracesPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &tracesPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageTraces = `traces [flags] <tx_id> [tx_id...]
    40  
    41  Arguments:
    42    transactions - a space-separated list of one or more transaction identifiers (required)`
    43  
    44  const longTraces = `Purpose:
    45    Retrieve traces for the given transaction(s).`
    46  
    47  const notesTraces = `
    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    - A bang separated filter has the following fields (at least one of which is required) and is separated with a bang (!): fromBlk, toBlk, fromAddr, toAddr, after, count.
    53    - This command 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 traces
    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  	tracesCmd.Flags().SortFlags = false
    63  
    64  	tracesCmd.Flags().BoolVarP(&tracesPkg.GetOptions().Articulate, "articulate", "a", false, `articulate the retrieved data if ABIs can be found`)
    65  	tracesCmd.Flags().StringVarP(&tracesPkg.GetOptions().Filter, "filter", "f", "", `call the node's trace_filter routine with bang-separated filter`)
    66  	tracesCmd.Flags().BoolVarP(&tracesPkg.GetOptions().Count, "count", "U", false, `display only the number of traces for the transaction (fast)`)
    67  	globals.InitGlobals("traces", tracesCmd, &tracesPkg.GetOptions().Globals, capabilities)
    68  
    69  	tracesCmd.SetUsageTemplate(UsageWithNotes(notesTraces))
    70  	tracesCmd.SetOut(os.Stderr)
    71  
    72  	// EXISTING_CODE
    73  	// EXISTING_CODE
    74  
    75  	chifraCmd.AddCommand(tracesCmd)
    76  }