Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: add ability to generate .abi.json file #916

Merged
merged 3 commits into from
May 4, 2020

Conversation

AnnaShaleva
Copy link
Member

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.

@AnnaShaleva AnnaShaleva added the compiler Go smart contract compiler label Apr 28, 2020
@AnnaShaleva AnnaShaleva self-assigned this Apr 28, 2020
@codecov
Copy link

codecov bot commented Apr 28, 2020

Codecov Report

Merging #916 into master-2.x will increase coverage by 0.04%.
The diff coverage is 64.28%.

Impacted file tree graph

@@              Coverage Diff               @@
##           master-2.x     #916      +/-   ##
==============================================
+ Coverage       67.86%   67.90%   +0.04%     
==============================================
  Files             142      142              
  Lines           13433    13471      +38     
==============================================
+ Hits             9116     9148      +32     
- Misses           3900     3906       +6     
  Partials          417      417              
Impacted Files Coverage Δ
pkg/compiler/compiler.go 47.36% <0.00%> (-7.74%) ⬇️
pkg/rpc/request/txBuilder.go 52.08% <0.00%> (ø)
pkg/compiler/debug.go 86.92% <87.09%> (+4.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f417c8...99d0baf. Read the comment docs.

ABIInfo string

// Contract metadata.
ContractDetails *request.ContractDetails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move ContractDetails out of rpc/request to smartcontract, importing anything RPC-related into the compiler is just weird.

@@ -260,3 +298,40 @@ func parsePairJSON(data []byte, sep string) (string, string, error) {
}
return ss[0], ss[1], nil
}

func (di *DebugInfo) convertToABI(contract []byte, cd *request.ContractDetails) ABI {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some test for it?

@AnnaShaleva
Copy link
Member Author

Also as part of #902, for the current moment we have difference in abi.json parameters/variables type format which leads to Invalid variable attributes error in NEO Express. The difference is in serialization of non-standard types:

  • c# implementation has Unknown: {type} (see for details)
  • go implementation has Any, which can not be properly parsed by NEO debugger.

However, that's not critical error.

@@ -11,6 +11,8 @@ import (
"path/filepath"
"strings"

"github.com/nspcc-dev/neo-go/pkg/smartcontract"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line.

@@ -8,6 +8,11 @@ import (
"go/types"
"strconv"
"strings"

"github.com/nspcc-dev/neo-go/pkg/smartcontract"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line.

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor corrections and please port it then to 3.0, we may change it in the future to reuse manifests or absorb some other 3.0-related changes, but still this one lays some nice basis for this work.

@@ -3,6 +3,9 @@ package compiler
import (
"testing"

"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line.

params := make([]DebugParam, 0, ps.NumFields())
for i := range params {
params := make([]DebugParam, ps.NumFields())
count := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think append() style would still look a bit better here (not needing any count, for example), to fix the original problem you only need to change the range iterator.

Method `methodInfoFromScope(...)` always returned an empty parameters
set, so we were missing this information in both .abi.json and
.debug.json files. Fixed now.
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).
@roman-khimov roman-khimov merged commit a025838 into master-2.x May 4, 2020
@roman-khimov roman-khimov deleted the compiler/generate_abi branch May 4, 2020 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Go smart contract compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants