github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/export.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  	exportPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/export"
    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  // exportCmd represents the export command
    26  var exportCmd = &cobra.Command{
    27  	Use:     usageExport,
    28  	Long:    longExport,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("export", func() *globals.GlobalOptions {
    31  		return &exportPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("export", exportPkg.RunExport, exportPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &exportPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageExport = `export [flags] <address> [address...] [topics...] [fourbytes...]
    40  
    41  Arguments:
    42    addrs - one or more addresses (0x...) to export (required)
    43    topics - filter by one or more log topics (only for --logs option)
    44    fourbytes - filter by one or more fourbytes (only for transactions and trace options)`
    45  
    46  const longExport = `Purpose:
    47    Export full details of transactions for one or more addresses.`
    48  
    49  const notesExport = `
    50  Notes:
    51    - An address must be either an ENS name or start with '0x' and be forty-two characters long.
    52    - Articulating the export means turn the EVM's byte data into human-readable text (if possible).
    53    - For the --logs option, you may optionally specify one or more --emitter, one or more --topics, or both.
    54    - The --logs option is significantly faster if you provide an --emitter or a --topic.
    55    - Neighbors include every address that appears in any transaction in which the export address also appears.
    56    - If present, --first_/--last_block are applied, followed by user-supplied filters such as asset or topic, followed by --first_/--max_record if present.
    57    - The --first_record and --max_record options are zero-based (as are the block options).
    58    - The _block and _record filters are ignored when used with the --count option.
    59    - If the --reversed option is present, the appearance list is reversed prior to all processing (including filtering).
    60    - The --decache option will remove all cache items (blocks, transactions, traces, etc.) for the given address(es).
    61    - The --withdrawals option is only available on certain chains. It is ignored otherwise.
    62    - The --traces option requires your RPC to provide trace data. See the README for more information.`
    63  
    64  func init() {
    65  	var capabilities caps.Capability // capabilities for chifra export
    66  	capabilities = capabilities.Add(caps.Default)
    67  	capabilities = capabilities.Add(caps.Caching)
    68  	capabilities = capabilities.Add(caps.Ether)
    69  	capabilities = capabilities.Add(caps.Names)
    70  
    71  	exportCmd.Flags().SortFlags = false
    72  
    73  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Appearances, "appearances", "p", false, `export a list of appearances`)
    74  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Receipts, "receipts", "r", false, `export receipts instead of transactional data`)
    75  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Logs, "logs", "l", false, `export logs instead of transactional data`)
    76  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Traces, "traces", "t", false, `export traces instead of transactional data`)
    77  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Neighbors, "neighbors", "n", false, `export the neighbors of the given address`)
    78  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Accounting, "accounting", "C", false, `attach accounting records to the exported data (applies to transactions export only)`)
    79  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Statements, "statements", "A", false, `for the accounting options only, export only statements`)
    80  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Balances, "balances", "b", false, `traverse the transaction history and show each change in ETH balances`)
    81  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Withdrawals, "withdrawals", "i", false, `export withdrawals for the given address`)
    82  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Articulate, "articulate", "a", false, `articulate transactions, traces, logs, and outputs`)
    83  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().CacheTraces, "cache_traces", "R", false, `force the transaction's traces into the cache`)
    84  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Count, "count", "U", false, `for --appearances mode only, display only the count of records`)
    85  	exportCmd.Flags().Uint64VarP(&exportPkg.GetOptions().FirstRecord, "first_record", "c", 0, `the first record to process`)
    86  	exportCmd.Flags().Uint64VarP(&exportPkg.GetOptions().MaxRecords, "max_records", "e", 250, `the maximum number of records to process`)
    87  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Relevant, "relevant", "N", false, `for log and accounting export only, export only logs relevant to one of the given export addresses`)
    88  	exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Emitter, "emitter", "m", nil, `for the --logs option only, filter logs to show only those logs emitted by the given address(es)`)
    89  	exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Topic, "topic", "B", nil, `for the --logs option only, filter logs to show only those with this topic(s)`)
    90  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Reverted, "reverted", "V", false, `export only transactions that were reverted`)
    91  	exportCmd.Flags().StringSliceVarP(&exportPkg.GetOptions().Asset, "asset", "P", nil, `for the accounting options only, export statements only for this asset`)
    92  	exportCmd.Flags().StringVarP(&exportPkg.GetOptions().Flow, "flow", "f", "", `for the accounting options only, export statements with incoming, outgoing, or zero value
    93  One of [ in | out | zero ]`)
    94  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Factory, "factory", "y", false, `for --traces only, report addresses created by (or self-destructed by) the given address(es)`)
    95  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Unripe, "unripe", "u", false, `export transactions labeled unripe (i.e. less than 28 blocks old)`)
    96  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().Reversed, "reversed", "E", false, `produce results in reverse chronological order`)
    97  	exportCmd.Flags().BoolVarP(&exportPkg.GetOptions().NoZero, "no_zero", "z", false, `for the --count option only, suppress the display of zero appearance accounts`)
    98  	exportCmd.Flags().Uint64VarP((*uint64)(&exportPkg.GetOptions().FirstBlock), "first_block", "F", 0, `first block to process (inclusive)`)
    99  	exportCmd.Flags().Uint64VarP((*uint64)(&exportPkg.GetOptions().LastBlock), "last_block", "L", 0, `last block to process (inclusive)`)
   100  	globals.InitGlobals("export", exportCmd, &exportPkg.GetOptions().Globals, capabilities)
   101  
   102  	exportCmd.SetUsageTemplate(UsageWithNotes(notesExport))
   103  	exportCmd.SetOut(os.Stderr)
   104  
   105  	// EXISTING_CODE
   106  	// This no-op makes scripting a bit easier. You may provide `--txs` option to the chifra export command, and it will be the same as no parameters at all.
   107  	var unused bool
   108  	exportCmd.Flags().BoolVarP(&unused, "txs", "", false, "no-op options shows transactions (same as default)")
   109  	_ = exportCmd.Flags().MarkHidden("txs")
   110  	// EXISTING_CODE
   111  
   112  	chifraCmd.AddCommand(exportCmd)
   113  }