binding

package
v0.105.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FExecute added in v0.103.0

func FExecute(tmplt *template.Template, out io.Writer, data any) error

FExecute tries to execute given template over the data provided, apply gofmt rules to the result and write the result to the provided io.Writer. If a format error occurs while formatting the resulting binding, then the generated binding is written "as is" and no error is returned.

func Generate

func Generate(cfg Config) error

Generate writes Go file containing smartcontract bindings to the `cfg.Output`. It doesn't check manifest from Config for validity, incorrect manifest can lead to unexpected results.

Types

type Config

type Config struct {
	Package  string             `yaml:"package,omitempty"`
	Manifest *manifest.Manifest `yaml:"-"`
	// Hash denotes the contract hash and is allowed to be empty for RPC bindings
	// generation (if not provided by the user).
	Hash      util.Uint160                 `yaml:"hash,omitempty"`
	Overrides map[string]Override          `yaml:"overrides,omitempty"`
	CallFlags map[string]callflag.CallFlag `yaml:"callflags,omitempty"`
	// NamedTypes contains exported structured types that have some name (even
	// if the original structure doesn't) and a number of internal fields. The
	// map key is in the form of `namespace.name`, the value is fully-qualified
	// and possibly nested description of the type structure.
	NamedTypes map[string]ExtendedType `yaml:"namedtypes,omitempty"`
	// Types contains type structure description for various types used in
	// smartcontract. The map key has one of the following forms:
	// - `methodName` for method return value;
	// - `mathodName.paramName` for method's parameter value.
	// - `eventName.paramName` for event's parameter value.
	Types  map[string]ExtendedType `yaml:"types,omitempty"`
	Output io.Writer               `yaml:"-"`
}

Config contains parameter for the generated binding.

func NewConfig

func NewConfig() Config

NewConfig initializes and returns a new config instance.

type ContractTmpl added in v0.99.5

type ContractTmpl struct {
	PackageName  string
	ContractName string
	Imports      []string
	Hash         string
	Methods      []MethodTmpl
}

func TemplateFromManifest added in v0.99.5

func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract.ParamType, *Config) (string, string)) ContractTmpl

TemplateFromManifest create a contract template using the given configuration and type conversion function. It assumes manifest to be present in the configuration and assumes it to be correct (passing IsValid check).

type ExtendedType added in v0.100.0

type ExtendedType struct {
	Base      smartcontract.ParamType `yaml:"base"`
	Name      string                  `yaml:"name,omitempty"`      // Structure name, omitted for arrays, interfaces and maps.
	Interface string                  `yaml:"interface,omitempty"` // Interface type name, "iterator" only for now.
	Key       smartcontract.ParamType `yaml:"key,omitempty"`       // Key type (only simple types can be used for keys) for maps.
	Value     *ExtendedType           `yaml:"value,omitempty"`     // Value type for iterators, arrays and maps.
	Fields    []FieldExtendedType     `yaml:"fields,omitempty"`    // Ordered type data for structure fields.
}

func (*ExtendedType) Equals added in v0.102.0

func (e *ExtendedType) Equals(other *ExtendedType) bool

Equals compares two extended types field-by-field and returns true if they are equal.

type FieldExtendedType added in v0.100.0

type FieldExtendedType struct {
	Field        string `yaml:"field"`
	ExtendedType `yaml:",inline"`
}

type MethodTmpl added in v0.99.5

type MethodTmpl struct {
	Name       string
	NameABI    string
	CallFlag   string
	Comment    string
	Arguments  []ParamTmpl
	ReturnType string
}

type Override

type Override struct {
	// Package contains a fully-qualified package name.
	Package string
	// TypeName contains type name together with a package alias.
	TypeName string
}

Override contains a package and a type to replace manifest method parameter type with.

func NewOverrideFromString

func NewOverrideFromString(s string) Override

NewOverrideFromString parses s and returns method parameter type override spec.

func (Override) MarshalYAML

func (o Override) MarshalYAML() (any, error)

MarshalYAML implements the YAML marshaler interface.

func (*Override) UnmarshalYAML

func (o *Override) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the YAML Unmarshaler interface.

type ParamTmpl added in v0.99.5

type ParamTmpl struct {
	Name string
	Type string
}

Jump to

Keyboard shortcuts

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