github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/blocks.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  	blocksPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/blocks"
    16  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals"
    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  // blocksCmd represents the blocks command
    26  var blocksCmd = &cobra.Command{
    27  	Use:     usageBlocks,
    28  	Long:    longBlocks,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("blocks", func() *globals.GlobalOptions {
    31  		return &blocksPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("blocks", blocksPkg.RunBlocks, blocksPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &blocksPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageBlocks = `blocks [flags] <block> [block...]
    40  
    41  Arguments:
    42    blocks - a space-separated list of one or more block identifiers (required)`
    43  
    44  const longBlocks = `Purpose:
    45    Retrieve one or more blocks from the chain or local cache.`
    46  
    47  const notesBlocks = `
    48  Notes:
    49    - Blocks is a space-separated list of values, a start-end range, a special, or any combination.
    50    - Blocks may be specified as either numbers or hashes.
    51    - Special blocks are detailed under chifra when --list.
    52    - With the --logs option, optionally specify one or more --emitter, one or more --topics, either or both.
    53    - The --logs option is significantly faster if you provide an --emitter and/or a --topic.
    54    - Multiple topics match on topic0, topic1, and so on, not on different topic0's.
    55    - The --decache option removes the block(s), all transactions in those block(s), and all traces in those transactions from the cache.
    56    - The --withdrawals option is only available on certain chains. It is ignored otherwise.
    57    - The --traces option requires your RPC to provide trace data. See the README for more information.`
    58  
    59  func init() {
    60  	var capabilities caps.Capability // capabilities for chifra blocks
    61  	capabilities = capabilities.Add(caps.Default)
    62  	capabilities = capabilities.Add(caps.Caching)
    63  	capabilities = capabilities.Add(caps.Ether)
    64  	capabilities = capabilities.Add(caps.Names)
    65  
    66  	blocksCmd.Flags().SortFlags = false
    67  
    68  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Hashes, "hashes", "e", false, `display only transaction hashes, default is to display full transaction detail`)
    69  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Uncles, "uncles", "c", false, `display uncle blocks (if any) instead of the requested block`)
    70  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Traces, "traces", "t", false, `export the traces from the block as opposed to the block data`)
    71  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Uniq, "uniq", "u", false, `display a list of uniq address appearances per transaction`)
    72  	blocksCmd.Flags().StringVarP(&blocksPkg.GetOptions().Flow, "flow", "f", "", `for the --uniq option only, export only from or to (including trace from or to)
    73  One of [ from | to | reward ]`)
    74  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Logs, "logs", "l", false, `display only the logs found in the block(s)`)
    75  	blocksCmd.Flags().StringSliceVarP(&blocksPkg.GetOptions().Emitter, "emitter", "m", nil, `for the --logs option only, filter logs to show only those logs emitted by the given address(es)`)
    76  	blocksCmd.Flags().StringSliceVarP(&blocksPkg.GetOptions().Topic, "topic", "B", nil, `for the --logs option only, filter logs to show only those with this topic(s)`)
    77  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Withdrawals, "withdrawals", "i", false, `export the withdrawals from the block as opposed to the block data`)
    78  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Articulate, "articulate", "a", false, `for the --logs option only, articulate the retrieved data if ABIs can be found`)
    79  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().Count, "count", "U", false, `display only the count of appearances for --addrs or --uniq`)
    80  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().CacheTxs, "cache_txs", "X", false, `force a write of the block's transactions to the cache (slow)`)
    81  	blocksCmd.Flags().BoolVarP(&blocksPkg.GetOptions().CacheTraces, "cache_traces", "R", false, `force a write of the block's traces to the cache (slower)`)
    82  	globals.InitGlobals("blocks", blocksCmd, &blocksPkg.GetOptions().Globals, capabilities)
    83  
    84  	blocksCmd.SetUsageTemplate(UsageWithNotes(notesBlocks))
    85  	blocksCmd.SetOut(os.Stderr)
    86  
    87  	// EXISTING_CODE
    88  	// EXISTING_CODE
    89  
    90  	chifraCmd.AddCommand(blocksCmd)
    91  }