From b5494320f9f2414c103227ba2ed7637e0da06a06 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 11 Aug 2020 11:21:54 +0300 Subject: [PATCH] compiler, cli: support events from .yml config file We currently can't process events in codegen, so we have to provide them via .yml config file. Do not delete the rest of the code connected with conversion of MethodDebugInfo.Event into manifest.Event as we have issue #1038. --- cli/smartcontract/smart_contract.go | 1 + pkg/compiler/compiler.go | 6 +++++- pkg/compiler/debug.go | 13 ++++--------- pkg/compiler/debug_test.go | 2 +- pkg/compiler/interop_test.go | 2 +- pkg/core/helper_test.go | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 262050d91..65888a61e 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -389,6 +389,7 @@ func contractCompile(ctx *cli.Context) error { return err } o.ContractFeatures = conf.GetFeatures() + o.ContractEvents = conf.Events o.ContractSupportedStandards = conf.SupportedStandards } diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index b221b8d74..41b5bef84 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "golang.org/x/tools/go/loader" ) @@ -37,6 +38,9 @@ type Options struct { // Contract features. ContractFeatures smartcontract.PropertyState + // Runtime notifications. + ContractEvents []manifest.Event + // The list of standards supported by the contract. ContractSupportedStandards []string } @@ -176,7 +180,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { } if o.ManifestFile != "" { - m, err := di.ConvertToManifest(o.ContractFeatures, o.ContractSupportedStandards...) + m, err := di.ConvertToManifest(o.ContractFeatures, o.ContractEvents, o.ContractSupportedStandards...) if err != nil { return b, fmt.Errorf("failed to convert debug info to manifest: %w", err) } diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index 2edfc3150..a0ceaa254 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -359,8 +359,7 @@ func parsePairJSON(data []byte, sep string) (string, string, error) { // ConvertToManifest converts contract to the manifest.Manifest struct for debugger. // Note: manifest is taken from the external source, however it can be generated ad-hoc. See #1038. -func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, supportedStandards ...string) (*manifest.Manifest, error) { - var err error +func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, events []manifest.Event, supportedStandards ...string) (*manifest.Manifest, error) { if di.MainPkg == "" { return nil, errors.New("no Main method was found") } @@ -374,19 +373,15 @@ func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, supported methods = append(methods, mMethod) } } - events := make([]manifest.Event, len(di.Events)) - for i, event := range di.Events { - events[i], err = event.ToManifestEvent() - if err != nil { - return nil, err - } - } result := manifest.NewManifest(di.Hash) result.Features = fs if supportedStandards != nil { result.SupportedStandards = supportedStandards } + if events == nil { + events = make([]manifest.Event, 0) + } result.ABI = manifest.ABI{ Hash: di.Hash, Methods: methods, diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 6c5a415cd..cf158825c 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -127,7 +127,7 @@ func unexportedMethod() int { return 1 } } t.Run("convert to Manifest", func(t *testing.T) { - actual, err := d.ConvertToManifest(smartcontract.HasStorage) + actual, err := d.ConvertToManifest(smartcontract.HasStorage, nil) require.NoError(t, err) // note: offsets are hard to predict, so we just take them from the output expected := &manifest.Manifest{ diff --git a/pkg/compiler/interop_test.go b/pkg/compiler/interop_test.go index e0cceeb59..02e349a66 100644 --- a/pkg/compiler/interop_test.go +++ b/pkg/compiler/interop_test.go @@ -88,7 +88,7 @@ func TestAppCall(t *testing.T) { inner, di, err := compiler.CompileWithDebugInfo(strings.NewReader(srcInner)) require.NoError(t, err) - m, err := di.ConvertToManifest(smartcontract.NoProperties) + m, err := di.ConvertToManifest(smartcontract.NoProperties, nil) require.NoError(t, err) ih := hash.Hash160(inner) diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 9b6e2f9fa..1bb666df4 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -232,7 +232,7 @@ func TestCreateBasicChain(t *testing.T) { t.Logf("contractHash: %s", hash.Hash160(avm).StringLE()) script := io.NewBufBinWriter() - m, err := di.ConvertToManifest(smartcontract.HasStorage) + m, err := di.ConvertToManifest(smartcontract.HasStorage, nil) require.NoError(t, err) bs, err := m.MarshalJSON() require.NoError(t, err)