github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/state.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 statePkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/state" 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 // stateCmd represents the state command 26 var stateCmd = &cobra.Command{ 27 Use: usageState, 28 Long: longState, 29 Version: versionText, 30 PreRun: outputHelpers.PreRunWithJsonWriter("state", func() *globals.GlobalOptions { 31 return &statePkg.GetOptions().Globals 32 }), 33 RunE: file.RunWithFileSupport("state", statePkg.RunState, statePkg.ResetOptions), 34 PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions { 35 return &statePkg.GetOptions().Globals 36 }), 37 } 38 39 const usageState = `state [flags] <address> [address...] [block...] 40 41 Arguments: 42 addrs - one or more addresses (0x...) from which to retrieve balances (required) 43 blocks - an optional list of one or more blocks at which to report balances, defaults to 'latest'` 44 45 const longState = `Purpose: 46 Retrieve account balance(s) for one or more addresses at given block(s).` 47 48 const notesState = ` 49 Notes: 50 - An address must be either an ENS name or start with '0x' and be forty-two characters long. 51 - Blocks is a space-separated list of values, a start-end range, a special, or any combination. 52 - If the queried node does not store historical state, the results are undefined. 53 - Special blocks are detailed under chifra when --list. 54 - Balance is the default mode. To select a single mode use none first, followed by that mode. 55 - Valid parameters for --call include Solidity-like syntax: balanceOf(0x316b...183d), a four-byte followed by parameters: 0x70a08231(0x316b...183d), or encoded input data. 56 - You may specify multiple parts on a single line. 57 - In the --call string, you may separate multiple calls with a colon.` 58 59 func init() { 60 var capabilities caps.Capability // capabilities for chifra state 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 stateCmd.Flags().SortFlags = false 67 68 stateCmd.Flags().StringSliceVarP(&statePkg.GetOptions().Parts, "parts", "p", nil, `control which state to export 69 One or more of [ balance | nonce | code | proxy | deployed | accttype | some | all ]`) 70 stateCmd.Flags().BoolVarP(&statePkg.GetOptions().Changes, "changes", "c", false, `only report a balance when it changes from one block to the next`) 71 stateCmd.Flags().BoolVarP(&statePkg.GetOptions().NoZero, "no_zero", "z", false, `suppress the display of zero balance accounts`) 72 stateCmd.Flags().StringVarP(&statePkg.GetOptions().Call, "call", "l", "", `call a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings`) 73 stateCmd.Flags().BoolVarP(&statePkg.GetOptions().Articulate, "articulate", "a", false, `for the --call option only, articulate the retrieved data if ABIs can be found`) 74 stateCmd.Flags().StringVarP(&statePkg.GetOptions().ProxyFor, "proxy_for", "r", "", `for the --call option only, redirects calls to this implementation`) 75 globals.InitGlobals("state", stateCmd, &statePkg.GetOptions().Globals, capabilities) 76 77 stateCmd.SetUsageTemplate(UsageWithNotes(notesState)) 78 stateCmd.SetOut(os.Stderr) 79 80 // EXISTING_CODE 81 // EXISTING_CODE 82 83 chifraCmd.AddCommand(stateCmd) 84 }