compiler: add ability to generate .abi.json file
A part of integration with NEO Blockchain Toolkit (see #902). To be able to deploy smart-contract compiled with neo-go compiler via NEO Express, we have to generate additional .abi.json file. This file contains the following information: - hash of the compiled contract - smart-contract metadata (title, description, version, author, email, has-storage, has-dynamic-invoke, is-payable) - smart-contract entry point - functions - events However, this .abi.json file is slightly different from the one, described in manifest.go, so we have to add auxilaury stractures for json marshalling. The .abi.json format used by NEO-Express is described [here](https://github.com/neo-project/neo-devpack-dotnet/blob/master/src/Neo.Compiler.MSIL/FuncExport.cs#L66).
This commit is contained in:
parent
ab7f2cb4fb
commit
2ec1d76320
4 changed files with 186 additions and 11 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"golang.org/x/tools/go/loader"
|
||||
)
|
||||
|
||||
|
@ -26,6 +27,12 @@ type Options struct {
|
|||
|
||||
// The name of the output for debug info.
|
||||
DebugInfo string
|
||||
|
||||
// The name of the output for application binary interface info.
|
||||
ABIInfo string
|
||||
|
||||
// Contract metadata.
|
||||
ContractDetails *smartcontract.ContractDetails
|
||||
}
|
||||
|
||||
type buildInfo struct {
|
||||
|
@ -105,5 +112,16 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
return b, ioutil.WriteFile(o.DebugInfo, data, os.ModePerm)
|
||||
if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
|
||||
return b, err
|
||||
}
|
||||
if o.ABIInfo == "" {
|
||||
return b, err
|
||||
}
|
||||
abi := di.convertToABI(b, o.ContractDetails)
|
||||
abiData, err := json.Marshal(abi)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
return b, ioutil.WriteFile(o.ABIInfo, abiData, os.ModePerm)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue