abisPkg

package
v0.0.0-...-3f8eaf4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 35 Imported by: 0

README

chifra abis

The chifra abis tool retrieves one or more ABI files for the given address(es). It searches for ABIs, sequentially, in the following locations:

  • the current working folder,
  • the TrueBlocks local cache,
  • Etherscan,
  • (in the future) ENS and Sourcify.

While this tool may be used from the command line, its primary purpose is in support of the --articulate option for tools such as chifra export and chifra logs.

If possible, the tool will follow proxied addresses searching for the ABI, but that does not always work. In that case, you may use the --proxy_for option.

The --known option prints a list of semi-standard function signatures such as the ERC20 standard, ERC 721 standard, various functions from OpenZeppelin, various Uniswap functions, etc. As an optimization, the known signatures are searched first during articulation.

The --encode option generates a 32-byte encoding for a given cannonical function or event signature. For functions, you may manually extract the first four bytes of the hash.

The --find option is experimental. Please see the notes below for more information.

Purpose:
  Fetches the ABI for a smart contract.

Usage:
  chifra abis [flags] <address> [address...]

Arguments:
  addrs - a list of one or more smart contracts whose ABIs to display (required)

Flags:
  -k, --known              load common 'known' ABIs from cache
  -r, --proxy_for string   redirects the query to this implementation
  -f, --find strings       search for function or event declarations given a four- or 32-byte code(s)
  -n, --hint strings       for the --find option only, provide hints to speed up the search
  -e, --encode string      generate the 32-byte encoding for a given cannonical function or event signature
  -o, --cache              force the results of the query into the cache
  -D, --decache            removes related items from the cache
  -x, --fmt string         export format, one of [none|json*|txt|csv]
  -v, --verbose            enable verbose output
  -h, --help               display this help screen

Notes:
  - Search for either four byte signatures or event signatures with the --find option.

Data models produced by this tool:

notes

Without the --verbose option, the result is a compacted form of the ABI. Add --verbose for full details.

The chifra abis --find option scans the cross product of two sets. The first set contains more than 100,000 function and event names. The second set contains approximately 700 function signatures. The cross product of these two sets creates 70,000,000 combinations of name(signature) each of which is hashed to create either a four-byte or a 32-byte hash. Very infrequently, the tool will find matches for an otherwise unknown signatures.

Other Options

All tools accept the following additional flags, although in some cases, they have no meaning.

  -v, --version         display the current version of the tool
      --output string   write the results to file 'fn' and return the filename
      --append          for --output command only append to instead of replace contents of file
      --file string     specify multiple sets of command line options in a file

Note: For the --file string option, you may place a series of valid command lines in a file using any valid flags. In some cases, this may significantly improve performance. A semi-colon at the start of any line makes it a comment.

Note: If you use --output --append option and at the same time the --file option, you may not switch export formats in the command file. For example, a command file with two different commands, one with --fmt csv and the other with --fmt json will produce both invalid CSV and invalid JSON.

Documentation

Overview

Package abisPkg handles the chifra abis command. It The tool retrieves one or more ABI files for the given address(es). It searches for ABIs, sequentially, in the following locations: - the current working folder, - the TrueBlocks local cache, - Etherscan, - (in the future) ENS and Sourcify. While this tool may be used from the command line, its primary purpose is in support of the --articulate option for tools such as chifra export and chifra logs. If possible, the tool will follow proxied addresses searching for the ABI, but that does not always work. In that case, you may use the --proxy_for option. The --known option prints a list of semi-standard function signatures such as the ERC20 standard, ERC 721 standard, various functions from OpenZeppelin, various Uniswap functions, etc. As an optimization, the known signatures are searched first during articulation. The --encode option generates a 32-byte encoding for a given cannonical function or event signature. For functions, you may manually extract the first four bytes of the hash. The --find option is experimental. Please see the notes below for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetOptions

func ResetOptions(testMode bool)

func RunAbis

func RunAbis(cmd *cobra.Command, args []string) error

RunAbis handles the abis command for the command line. Returns error only as per cobra.

func ServeAbis

func ServeAbis(w http.ResponseWriter, r *http.Request) error

ServeAbis handles the abis command for the API. Returns an error.

Types

type AbisOptions

type AbisOptions struct {
	Addrs    []string              `json:"addrs,omitempty"`    // A list of one or more smart contracts whose ABIs to display
	Known    bool                  `json:"known,omitempty"`    // Load common 'known' ABIs from cache
	ProxyFor string                `json:"proxyFor,omitempty"` // Redirects the query to this implementation
	Find     []string              `json:"find,omitempty"`     // Search for function or event declarations given a four- or 32-byte code(s)
	Hint     []string              `json:"hint,omitempty"`     // For the --find option only, provide hints to speed up the search
	Encode   string                `json:"encode,omitempty"`   // Generate the 32-byte encoding for a given cannonical function or event signature
	Globals  globals.GlobalOptions `json:"globals,omitempty"`  // The global options
	Conn     *rpc.Connection       `json:"conn,omitempty"`     // The connection to the RPC server
	BadFlag  error                 `json:"badFlag,omitempty"`  // An error flag if needed
	// EXISTING_CODE
	ProxyForAddr base.Address `json:"-"`
}

AbisOptions provides all command options for the chifra abis command.

func GetAbisOptions

func GetAbisOptions(args []string, g *globals.GlobalOptions) *AbisOptions

GetAbisOptions returns the options for this tool so other tools may use it.

func GetOptions

func GetOptions() *AbisOptions

func (*AbisOptions) AbisInternal

func (opts *AbisOptions) AbisInternal() error

AbisInternal handles the internal workings of the abis command. Returns an error.

func (*AbisOptions) HandleAbiFind

func (opts *AbisOptions) HandleAbiFind() error

func (*AbisOptions) HandleDecache

func (opts *AbisOptions) HandleDecache() error

func (*AbisOptions) HandleEncode

func (opts *AbisOptions) HandleEncode() error

func (*AbisOptions) HandleMany

func (opts *AbisOptions) HandleMany() (err error)

func (*AbisOptions) HandleShow

func (opts *AbisOptions) HandleShow() (err error)

func (*AbisOptions) String

func (opts *AbisOptions) String() string

String implements the Stringer interface

type CFunctionArray

type CFunctionArray []types.SimpleFunction

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL