codegen

package
v0.0.0-...-9409369 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFuncMap = template.FuncMap{
	"_sub": func(a, b int) int { return a - b },
	"_actionId": func(schema datamod.TableSchema) string {
		var argsSign string
		if len(schema.Values) > 0 {
			solTypes := make([]string, 0, len(schema.Values))
			for _, field := range schema.Values {
				solTypes = append(solTypes, field.Type.SolType)
			}
			argsSign = "(" + strings.Join(solTypes, ",") + ")"
		} else {
			argsSign = ""
		}
		methodName := params.SolidityActionMethodName(schema.Name)
		sign := fmt.Sprintf("%s(%s)", methodName, argsSign)
		hash := crypto.Keccak256([]byte(sign))
		return fmt.Sprintf("0x%x", hash[:4])
	},
}

Functions

func CheckDir

func CheckDir(dirPath string) error

CheckDir checks if the given path is a directory.

func CheckFile

func CheckFile(filePath string) error

CheckFile checks if the given path is a file.

func DeleteAllFilesInDir

func DeleteAllFilesInDir(dir string) error

DeleteAllFilesInDir deletes all files in the given directory.

func ExecuteTemplate

func ExecuteTemplate(tplStr string, jsonSchemaPath, outPath string, data map[string]interface{}, funcMap template.FuncMap) error

ExecuteTemplate executes a template with the given data and writes the output to a file. It will load the JSON schema from the given path and add it to the data map.

func GenerateSchemasDescriptionString

func GenerateSchemasDescriptionString(schemas []datamod.TableSchema) string

GenerateSchemasDescriptionString generates a string with the description of the schemas.

Types

type Config

type Config struct {
	ActionsJsonPath string
	TablesJsonPath  string
	Out             string
}

func (Config) Validate

func (c Config) Validate() error

Validate validates the contents of the Config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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