From 02ca3d3dfd0d882296f896dfd6353eadfa94402e Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 9 Feb 2021 12:29:41 +0300 Subject: [PATCH] interop: reuse `state.Native` in `ContractMD` --- pkg/core/blockchain.go | 10 +++------- pkg/core/interop/context.go | 12 +++++------- pkg/core/native/management.go | 7 +------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 7fa8478a5..4e9ef7e16 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1245,13 +1245,9 @@ func (bc *Blockchain) GetNativeContractScriptHash(name string) (util.Uint160, er // GetNatives returns list of native contracts. func (bc *Blockchain) GetNatives() []state.NativeContract { - res := make([]state.NativeContract, len(bc.contracts.Contracts)) - for i, c := range bc.contracts.Contracts { - md := c.Metadata() - res[i].ID = md.ID - res[i].Hash = md.Hash - res[i].Manifest = md.Manifest - res[i].NEF = md.NEF + res := make([]state.NativeContract, 0, len(bc.contracts.Contracts)) + for _, c := range bc.contracts.Contracts { + res = append(res, c.Metadata().NativeContract) } return res } diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index c10d31933..8ce2cf65b 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -99,12 +99,9 @@ type Contract interface { // ContractMD represents native contract instance. type ContractMD struct { - Manifest manifest.Manifest - Name string - ID int32 - NEF nef.File - Hash util.Uint160 - Methods map[MethodAndArgCount]MethodAndPrice + state.NativeContract + Name string + Methods map[MethodAndArgCount]MethodAndPrice } // MethodAndArgCount represents method's signature. @@ -117,10 +114,11 @@ type MethodAndArgCount struct { func NewContractMD(name string, id int32) *ContractMD { c := &ContractMD{ Name: name, - ID: id, Methods: make(map[MethodAndArgCount]MethodAndPrice), } + c.ID = id + // NEF is now stored in contract state and affects state dump. // Therefore values are taken from C# node. c.NEF.Header.Compiler = "neo-core-v3.0" diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 8145c8405..8b7e534a1 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -453,12 +453,7 @@ func (m *Management) OnPersist(ic *interop.Context) error { md := native.Metadata() cs := &state.Contract{ - ContractBase: state.ContractBase{ - ID: md.ID, - Hash: md.Hash, - NEF: md.NEF, - Manifest: md.Manifest, - }, + ContractBase: md.ContractBase, } err := m.PutContractState(ic.DAO, cs) if err != nil {