compiler: emit bindings configuration
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
42c1e8b0e3
commit
a2cef15932
7 changed files with 273 additions and 58 deletions
|
@ -15,11 +15,13 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/binding"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"golang.org/x/tools/go/packages"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const fileExt = "nef"
|
||||
|
@ -72,6 +74,9 @@ type Options struct {
|
|||
|
||||
// Permissions is a list of permissions for every contract method.
|
||||
Permissions []manifest.Permission
|
||||
|
||||
// BindingsFile contains configuration for smart-contract bindings generator.
|
||||
BindingsFile string
|
||||
}
|
||||
|
||||
type buildInfo struct {
|
||||
|
@ -258,7 +263,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
if err != nil {
|
||||
return f.Script, err
|
||||
}
|
||||
if o.DebugInfo == "" && o.ManifestFile == "" {
|
||||
if o.DebugInfo == "" && o.ManifestFile == "" && o.BindingsFile == "" {
|
||||
return f.Script, nil
|
||||
}
|
||||
|
||||
|
@ -289,6 +294,29 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if o.BindingsFile != "" {
|
||||
cfg := binding.NewConfig()
|
||||
cfg.Package = di.MainPkg
|
||||
for _, m := range di.Methods {
|
||||
for _, p := range m.Parameters {
|
||||
if p.RealType.TypeName != "" {
|
||||
cfg.Overrides[m.Name.Name+"."+p.Name] = p.RealType
|
||||
}
|
||||
}
|
||||
if m.ReturnTypeReal.TypeName != "" {
|
||||
cfg.Overrides[m.Name.Name] = m.ReturnTypeReal
|
||||
}
|
||||
}
|
||||
data, err := yaml.Marshal(&cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't marshal bindings configuration: %w", err)
|
||||
}
|
||||
err = ioutil.WriteFile(o.BindingsFile, data, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't write bindings configuration: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if o.ManifestFile != "" {
|
||||
m, err := CreateManifest(di, o)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue