interop: reuse state.Native in ContractMD

This commit is contained in:
Evgeniy Stratonikov 2021-02-09 12:29:41 +03:00
parent 6ca7b4b966
commit 02ca3d3dfd
3 changed files with 9 additions and 20 deletions

View file

@ -1245,13 +1245,9 @@ func (bc *Blockchain) GetNativeContractScriptHash(name string) (util.Uint160, er
// GetNatives returns list of native contracts. // GetNatives returns list of native contracts.
func (bc *Blockchain) GetNatives() []state.NativeContract { func (bc *Blockchain) GetNatives() []state.NativeContract {
res := make([]state.NativeContract, len(bc.contracts.Contracts)) res := make([]state.NativeContract, 0, len(bc.contracts.Contracts))
for i, c := range bc.contracts.Contracts { for _, c := range bc.contracts.Contracts {
md := c.Metadata() res = append(res, c.Metadata().NativeContract)
res[i].ID = md.ID
res[i].Hash = md.Hash
res[i].Manifest = md.Manifest
res[i].NEF = md.NEF
} }
return res return res
} }

View file

@ -99,12 +99,9 @@ type Contract interface {
// ContractMD represents native contract instance. // ContractMD represents native contract instance.
type ContractMD struct { type ContractMD struct {
Manifest manifest.Manifest state.NativeContract
Name string Name string
ID int32 Methods map[MethodAndArgCount]MethodAndPrice
NEF nef.File
Hash util.Uint160
Methods map[MethodAndArgCount]MethodAndPrice
} }
// MethodAndArgCount represents method's signature. // MethodAndArgCount represents method's signature.
@ -117,10 +114,11 @@ type MethodAndArgCount struct {
func NewContractMD(name string, id int32) *ContractMD { func NewContractMD(name string, id int32) *ContractMD {
c := &ContractMD{ c := &ContractMD{
Name: name, Name: name,
ID: id,
Methods: make(map[MethodAndArgCount]MethodAndPrice), Methods: make(map[MethodAndArgCount]MethodAndPrice),
} }
c.ID = id
// NEF is now stored in contract state and affects state dump. // NEF is now stored in contract state and affects state dump.
// Therefore values are taken from C# node. // Therefore values are taken from C# node.
c.NEF.Header.Compiler = "neo-core-v3.0" c.NEF.Header.Compiler = "neo-core-v3.0"

View file

@ -453,12 +453,7 @@ func (m *Management) OnPersist(ic *interop.Context) error {
md := native.Metadata() md := native.Metadata()
cs := &state.Contract{ cs := &state.Contract{
ContractBase: state.ContractBase{ ContractBase: md.ContractBase,
ID: md.ID,
Hash: md.Hash,
NEF: md.NEF,
Manifest: md.Manifest,
},
} }
err := m.PutContractState(ic.DAO, cs) err := m.PutContractState(ic.DAO, cs)
if err != nil { if err != nil {