github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/tokens.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 tokensPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/tokens" 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 // tokensCmd represents the tokens command 26 var tokensCmd = &cobra.Command{ 27 Use: usageTokens, 28 Long: longTokens, 29 Version: versionText, 30 PreRun: outputHelpers.PreRunWithJsonWriter("tokens", func() *globals.GlobalOptions { 31 return &tokensPkg.GetOptions().Globals 32 }), 33 RunE: file.RunWithFileSupport("tokens", tokensPkg.RunTokens, tokensPkg.ResetOptions), 34 PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions { 35 return &tokensPkg.GetOptions().Globals 36 }), 37 } 38 39 const usageTokens = `tokens [flags] <address> <address> [address...] [block...] 40 41 Arguments: 42 addrs - two or more addresses (0x...), the first is an ERC20 token, balances for the rest are reported (required) 43 blocks - an optional list of one or more blocks at which to report balances, defaults to 'latest'` 44 45 const longTokens = `Purpose: 46 Retrieve token balance(s) for one or more addresses at given block(s).` 47 48 const notesTokens = ` 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 token contract(s) from which you request balances are not ERC20 compliant, the results are undefined. 53 - If the queried node does not store historical state, the results are undefined. 54 - Special blocks are detailed under chifra when --list. 55 - If the --parts option is not empty, all addresses are considered tokens and each token's attributes are presented.` 56 57 func init() { 58 var capabilities caps.Capability // capabilities for chifra tokens 59 capabilities = capabilities.Add(caps.Default) 60 capabilities = capabilities.Add(caps.Caching) 61 capabilities = capabilities.Add(caps.Names) 62 63 tokensCmd.Flags().SortFlags = false 64 65 tokensCmd.Flags().StringSliceVarP(&tokensPkg.GetOptions().Parts, "parts", "p", nil, `which parts of the token information to retrieve 66 One or more of [ name | symbol | decimals | totalSupply | version | some | all ]`) 67 tokensCmd.Flags().BoolVarP(&tokensPkg.GetOptions().ByAcct, "by_acct", "b", false, `consider each address an ERC20 token except the last, whose balance is reported for each token`) 68 tokensCmd.Flags().BoolVarP(&tokensPkg.GetOptions().Changes, "changes", "c", false, `only report a balance when it changes from one block to the next`) 69 tokensCmd.Flags().BoolVarP(&tokensPkg.GetOptions().NoZero, "no_zero", "z", false, `suppress the display of zero balance accounts`) 70 globals.InitGlobals("tokens", tokensCmd, &tokensPkg.GetOptions().Globals, capabilities) 71 72 tokensCmd.SetUsageTemplate(UsageWithNotes(notesTokens)) 73 tokensCmd.SetOut(os.Stderr) 74 75 // EXISTING_CODE 76 // EXISTING_CODE 77 78 chifraCmd.AddCommand(tokensCmd) 79 }