Documentation ¶
Index ¶
- Variables
- func AddCLI(sourceCode, structName string, noformat, includemain bool) (string, error)
- func GenerateHeader(packageName string, cli bool, includeMain bool, foundry string, abi string, ...) (string, error)
- func GenerateTypes(structName string, abi []byte, bytecode []byte, packageName string, ...) (string, error)
- type ABIBoundParameter
- type CLISpecification
- type HandlerDefinition
- type HeaderParameters
- type MethodArgument
- type MethodReturnValue
Constants ¶
This section is empty.
Variables ¶
var CLICodeTemplate string = `` /* 4595-byte string literal not displayed */
This template is used to generate the skeleton of the CLI, along with all utility methods that can be used by CLI handlers. It is expected to be applied to a CLISpecification struct.
var DeployCommandTemplate string = `` /* 3971-byte string literal not displayed */
This template generates the handler for smart contract deployment. It is intended to be used with a CLISpecification struct.
var ErrParameterUnnamed error = errors.New("parameter is unnamed")
ErrParameterUnnamed is raised when a method argument is unnamed. go-ethereum's bind.Bind does not leave its method arguments unnamed, so this also indicates a skew in seer's assumptions and the actual generated code it is using from go-ethereum's bind.Bind.
var ErrParsingCLISpecification error = errors.New("error parsing CLI parameters")
ErrParsingCLISpecification is raised when there is an error producing a CLI specification from AST nodes. It indicates that seer's assumptions about the code generated by the go-ethereum Go bindings generators are no longer correct.
var HeaderTemplate string = `` /* 524-byte string literal not displayed */
This is the Go template used to create header information at the top of the generated code. At a bare minimum, the header specifies the version of seer that was used to generate the code. This template should be applied to a EVMHeaderParameters struct.
var TransactMethodCommandsTemplate string = `` /* 4520-byte string literal not displayed */
This template generates the handlers for all smart contract methods that submit transactions. It is intended to be used with a CLISpecification struct.
var ViewMethodCommandsTemplate string = `` /* 2501-byte string literal not displayed */
This template generates the handlers for all smart contract call methods. It is intended to be used with a CLISpecification struct.
Functions ¶
func AddCLI ¶
AddCLI adds CLI code (using github.com/spf13/cobra command-line framework) for code generated by the GenerateTypes function. The output of this function *contains* the input, with enrichments (some of then inline). It should not be concatenated with the output of GenerateTypes, but rather be used as part of a chain.
func GenerateHeader ¶ added in v0.1.1
func GenerateHeader(packageName string, cli bool, includeMain bool, foundry string, abi string, bytecode string, structname string, outputfile string, noformat bool) (string, error)
Generates the header comment for the generated code.
func GenerateTypes ¶
func GenerateTypes(structName string, abi []byte, bytecode []byte, packageName string, aliases map[string]string) (string, error)
GenerateTypes generates Go bindings to an Ethereum contract ABI (or union of such). This functionality is roughly equivalent to that provided by the `abigen` tool provided by go-ethereum: https://github.com/ethereum/go-ethereum/tree/master/cmd/abigen Under the hood, GenerateTypes uses the Bind method implemented in go-ethereum in a manner similar to abigen. It just offers a simpler call signature that makes more sense for users of seer.
Arguments:
- structName: The name of the generated Go struct that will represent this contract.
- abi: The bytes representing the contract's ABI.
- bytecode: The bytes representing the contract's bytecode. If this is provided, a "deploy" method will be generated. If it is not provided, no such method will be generated.
- packageName: If this is provided, the generated code will contain a package declaration of this name.
- aliases: This is a mapping of aliases for identifiers from an ABI. Necessary because Go bindings have trouble with overloaded methods in an ABI.
Types ¶
type ABIBoundParameter ¶
type ABIBoundParameter struct { Name string GoType string Node ast.Node IsArray bool Length int Subtypes []ABIBoundParameter }
ABIBoundParameter represents a Go type that is bound to an Ethereum contract ABI item. The different types of types we need to deal with (based on https://github.com/ethereum/go-ethereum/blob/47d76c5f9508d3594bfc9aafa95c04edae71c5a1/accounts/abi/bind/bind.go#L338): - uint8 - uint16 - uint32 - uint64 - int8 - int16 - int32 - int64 - *big.Int - [n]byte - []byte - string - bool - array - struct
func ParseBoundParameter ¶
func ParseBoundParameter(arg ast.Node) (ABIBoundParameter, error)
ParseBoundParameter parses an ast.Node representing a method parameter (or return value). It inspects the ast.Node recursively to determine the information needed to parse that node to the user from command-line input or to present an instance of that type to a user as command output.
type CLISpecification ¶
type CLISpecification struct { StructName string DeployHandler HandlerDefinition ViewHandlers []HandlerDefinition TransactHandlers []HandlerDefinition }
Data structure that parametrizes CLI generation.
func ParseCLISpecification ¶
func ParseCLISpecification(structName string, deployMethod *ast.FuncDecl, viewMethods map[string]*ast.FuncDecl, transactMethods map[string]*ast.FuncDecl) (CLISpecification, error)
Produces a CLI specification for the structure with the given name, provided the AST nodes representing the deployment method, the tranasaction methods, and the view methods for the corresponding smart contract.
The value of the deployMethod argument is used to determine if the deployment functionality will be added to the CLI. If deployMethod is nil, then a deployment command is not generated. This is signified by the result.DeployHandler.MethodName being empty in the resulting CLISpecification.
type HandlerDefinition ¶
type HandlerDefinition struct { MethodName string HandlerName string MethodArgs []MethodArgument MethodReturns []MethodReturnValue }
HandlerDefinition specifies a (sub)command handler that needs to be generated as part of the CLI.
type HeaderParameters ¶ added in v0.1.1
type HeaderParameters struct { Version string PackageName string CLI bool IncludeMain bool Foundry string ABI string Bytecode string StructName string OutputFile string NoFormat bool }
Parameters used to generate header comment for generated code.
type MethodArgument ¶
type MethodArgument struct { Argument ABIBoundParameter CLIVar string CLIRawVar string CLIName string CLIType string CLIRawType string Flag string PreRunE string }
MethodArgument specifies a method argument to a smart contract bound method and how it should be handled in the generated CLI.
func DeriveMethodArguments ¶
func DeriveMethodArguments(parameters []ABIBoundParameter) ([]MethodArgument, error)
Fills in the information required to represent the given parameters as command-line argument. Takes an array of ABIBoundParameter structs because it deduplicates flags. This is where we map the Go types used in the methods to the Go types used to parse those arguments from the command line.
type MethodReturnValue ¶
type MethodReturnValue struct { ReturnValue ABIBoundParameter CaptureName string CaptureType string InitializeCode string PrintCode string }
MethodReturnValue specifies a value returned by a smart contract bound method and how it should be handled in the generated CLI.
func DeriveMethodReturnValues ¶
func DeriveMethodReturnValues(parameters []ABIBoundParameter) ([]MethodReturnValue, error)
Fills in the information required to present the given return values to the user as output from a CLI.