github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/slurp.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  	slurpPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/slurp"
    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  // slurpCmd represents the slurp command
    26  var slurpCmd = &cobra.Command{
    27  	Use:     usageSlurp,
    28  	Long:    longSlurp,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("slurp", func() *globals.GlobalOptions {
    31  		return &slurpPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("slurp", slurpPkg.RunSlurp, slurpPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &slurpPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageSlurp = `slurp [flags] <address> [address...] [block...]
    40  
    41  Arguments:
    42    addrs - one or more addresses to slurp from Etherscan (required)
    43    blocks - an optional range of blocks to slurp`
    44  
    45  const longSlurp = `Purpose:
    46    Fetch data from Etherscan and other APIs for any address.`
    47  
    48  const notesSlurp = `
    49  Notes:
    50    - An address must be either an ENS name or start with '0x' and be forty-two characters long.
    51    - Portions of this software are Powered by Etherscan.io, Covalent, Alchemy, TrueBlocks Key APIs.
    52    - See slurp/README on how to configure keys for API providers.
    53    - The withdrawals option is only available on certain chains. It is ignored otherwise.
    54    - If the value of --source is key, --parts is ignored.
    55    - The --types option is deprecated, use --parts instead.`
    56  
    57  func init() {
    58  	var capabilities caps.Capability // capabilities for chifra slurp
    59  	capabilities = capabilities.Add(caps.Default)
    60  	capabilities = capabilities.Add(caps.Caching)
    61  	capabilities = capabilities.Add(caps.Ether)
    62  	capabilities = capabilities.Add(caps.Names)
    63  
    64  	slurpCmd.Flags().SortFlags = false
    65  
    66  	slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Parts, "parts", "r", nil, `which types of transactions to request
    67  One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | all ]`)
    68  	slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Appearances, "appearances", "p", false, `show only the blocknumber.tx_id appearances of the exported transactions`)
    69  	slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Articulate, "articulate", "a", false, `articulate the retrieved data if ABIs can be found`)
    70  	slurpCmd.Flags().StringVarP(&slurpPkg.GetOptions().Source, "source", "S", "etherscan", `the source of the slurped data
    71  One of [ etherscan | key | covalent | alchemy ]`)
    72  	slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Count, "count", "U", false, `for --appearances mode only, display only the count of records`)
    73  	slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().Page, "page", "g", 0, `the page to retrieve (page number)`)
    74  	slurpCmd.Flags().StringVarP(&slurpPkg.GetOptions().PageId, "page_id", "", "", `the page to retrieve (page ID)`)
    75  	slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().PerPage, "per_page", "P", 1000, `the number of records to request on each page`)
    76  	slurpCmd.Flags().Float64VarP(&slurpPkg.GetOptions().Sleep, "sleep", "s", .25, `seconds to sleep between requests`)
    77  	slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Types, "types", "t", nil, `deprecated, use --parts instead (hidden)`)
    78  	if os.Getenv("TEST_MODE") != "true" {
    79  		_ = slurpCmd.Flags().MarkHidden("types")
    80  	}
    81  	_ = slurpCmd.Flags().MarkDeprecated("types", "The --types option has been deprecated.")
    82  	globals.InitGlobals("slurp", slurpCmd, &slurpPkg.GetOptions().Globals, capabilities)
    83  
    84  	slurpCmd.SetUsageTemplate(UsageWithNotes(notesSlurp))
    85  	slurpCmd.SetOut(os.Stderr)
    86  
    87  	// EXISTING_CODE
    88  	// EXISTING_CODE
    89  
    90  	chifraCmd.AddCommand(slurpCmd)
    91  }