core: call _deploy method during create/update

This commit is contained in:
Evgenii Stratonikov 2020-10-02 12:56:51 +03:00
parent b71f9e296c
commit 2d9ef9219a
4 changed files with 115 additions and 5 deletions

View file

@ -9,8 +9,10 @@ import (
"github.com/mr-tron/base58"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@ -109,7 +111,7 @@ func contractCreate(ic *interop.Context) error {
return fmt.Errorf("cannot convert contract to stack item: %w", err)
}
ic.VM.Estack().PushVal(cs)
return nil
return callDeploy(ic, newcontract, false)
}
// contractUpdate migrates a contract. This method assumes that Manifest and Script
@ -183,6 +185,15 @@ func contractUpdate(ic *interop.Context) error {
}
}
return callDeploy(ic, contract, true)
}
func callDeploy(ic *interop.Context, cs *state.Contract, isUpdate bool) error {
md := cs.Manifest.ABI.GetMethod(manifest.MethodDeploy)
if md != nil {
return contract.CallExInternal(ic, cs, manifest.MethodDeploy,
[]stackitem.Item{stackitem.NewBool(isUpdate)}, smartcontract.All)
}
return nil
}