diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index f4fad18b5..374dacfe7 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -37,12 +37,9 @@ var syscalls = map[string]map[string]string{ "GetTransactionHeight": "System.Blockchain.GetTransactionHeight", }, "contract": { - "GetScript": "Neo.Contract.GetScript", - "IsPayable": "Neo.Contract.IsPayable", - "Create": "Neo.Contract.Create", - "Destroy": "Neo.Contract.Destroy", - "Migrate": "Neo.Contract.Migrate", - "GetStorageContext": "Neo.Contract.GetStorageContext", + "Create": "System.Contract.Create", + "Destroy": "System.Contract.Destroy", + "Update": "System.Contract.Update", }, "engine": { "GetScriptContainer": "System.ExecutionEngine.GetScriptContainer", diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index f8a20f059..3c04e798e 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -236,7 +236,7 @@ func TestCreateBasicChain(t *testing.T) { require.NoError(t, err) emit.Bytes(script.BinWriter, bs) emit.Bytes(script.BinWriter, avm) - emit.Syscall(script.BinWriter, "Neo.Contract.Create") + emit.Syscall(script.BinWriter, "System.Contract.Create") txScript := script.Bytes() invFee := util.Fixed8FromFloat(100) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index c9c833e99..a6ac1f393 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -28,7 +28,6 @@ type Context struct { Block *block.Block Tx *transaction.Transaction DAO *dao.Cached - LowerDAO dao.DAO Notifications []state.NotificationEvent Log *zap.Logger } @@ -44,7 +43,6 @@ func NewContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO, n Block: block, Tx: tx, DAO: dao, - LowerDAO: d, Notifications: nes, Log: log, } diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index 802e734bd..9b57250e6 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -114,30 +114,8 @@ func contractCreate(ic *interop.Context, v *vm.VM) error { return nil } -// contractGetScript returns a script associated with a contract. -func contractGetScript(ic *interop.Context, v *vm.VM) error { - csInterface := v.Estack().Pop().Value() - cs, ok := csInterface.(*state.Contract) - if !ok { - return fmt.Errorf("%T is not a contract state", cs) - } - v.Estack().PushVal(cs.Script) - return nil -} - -// contractIsPayable returns whether contract is payable. -func contractIsPayable(ic *interop.Context, v *vm.VM) error { - csInterface := v.Estack().Pop().Value() - cs, ok := csInterface.(*state.Contract) - if !ok { - return fmt.Errorf("%T is not a contract state", cs) - } - v.Estack().PushVal(cs.IsPayable()) - return nil -} - -// contractMigrate migrates a contract. -func contractMigrate(ic *interop.Context, v *vm.VM) error { +// contractUpdate migrates a contract. +func contractUpdate(ic *interop.Context, v *vm.VM) error { contract, err := ic.DAO.GetContractState(v.GetCurrentScriptHash()) if contract == nil { return errors.New("contract doesn't exist") diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index 0170cb00e..063ab2775 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -212,28 +212,6 @@ func TestECDSAVerify(t *testing.T) { }) } -func TestContractGetScript(t *testing.T) { - v, contractState, context, chain := createVMAndContractState(t) - defer chain.Close() - v.Estack().PushVal(stackitem.NewInterop(contractState)) - - err := contractGetScript(context, v) - require.NoError(t, err) - script := v.Estack().Pop().Value() - require.Equal(t, contractState.Script, script) -} - -func TestContractIsPayable(t *testing.T) { - v, contractState, context, chain := createVMAndContractState(t) - defer chain.Close() - v.Estack().PushVal(stackitem.NewInterop(contractState)) - - err := contractIsPayable(context, v) - require.NoError(t, err) - isPayable := v.Estack().Pop().Value() - require.Equal(t, contractState.IsPayable(), isPayable) -} - // Helper functions to create VM, InteropContext, TX, Account, Contract. func createVM(t *testing.T) (*vm.VM, *interop.Context, *Blockchain) { diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 1ac2948d7..09239598b 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -529,25 +529,3 @@ func contractDestroy(ic *interop.Context, v *vm.VM) error { } return nil } - -// contractGetStorageContext retrieves StorageContext of a contract. -func contractGetStorageContext(ic *interop.Context, v *vm.VM) error { - csInterface := v.Estack().Pop().Value() - cs, ok := csInterface.(*state.Contract) - if !ok { - return fmt.Errorf("%T is not a contract state", cs) - } - _, err := ic.DAO.GetContractState(cs.ScriptHash()) - if err != nil { - return fmt.Errorf("non-existent contract") - } - _, err = ic.LowerDAO.GetContractState(cs.ScriptHash()) - if err == nil { - return fmt.Errorf("contract was not created in this transaction") - } - stc := &StorageContext{ - ScriptHash: cs.ScriptHash(), - } - v.Estack().PushVal(stackitem.NewInterop(stc)) - return nil -} diff --git a/pkg/core/interops.go b/pkg/core/interops.go index c73f48105..819be06ab 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -70,8 +70,9 @@ var systemInterops = []interop.Function{ {Name: "System.Blockchain.GetTransactionHeight", Func: bcGetTransactionHeight, Price: 100}, {Name: "System.Contract.Call", Func: contractCall, Price: 1}, {Name: "System.Contract.CallEx", Func: contractCallEx, Price: 1}, + {Name: "System.Contract.Create", Func: contractCreate, Price: 0}, {Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1}, - {Name: "System.Contract.GetStorageContext", Func: contractGetStorageContext, Price: 1}, + {Name: "System.Contract.Update", Func: contractUpdate, Price: 0}, {Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 1}, {Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 1}, {Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1}, @@ -104,12 +105,6 @@ var systemInterops = []interop.Function{ } var neoInterops = []interop.Function{ - {Name: "Neo.Contract.Create", Func: contractCreate, Price: 0}, - {Name: "Neo.Contract.Destroy", Func: contractDestroy, Price: 1}, - {Name: "Neo.Contract.GetScript", Func: contractGetScript, Price: 1}, - {Name: "Neo.Contract.GetStorageContext", Func: contractGetStorageContext, Price: 1}, - {Name: "Neo.Contract.IsPayable", Func: contractIsPayable, Price: 1}, - {Name: "Neo.Contract.Migrate", Func: contractMigrate, Price: 0}, {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: 1}, {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1}, diff --git a/pkg/core/interops_test.go b/pkg/core/interops_test.go index b346926e2..168edf1a9 100644 --- a/pkg/core/interops_test.go +++ b/pkg/core/interops_test.go @@ -32,9 +32,6 @@ func TestUnexpectedNonInterops(t *testing.T) { // All of these functions expect an interop item on the stack. funcs := []func(*interop.Context, *vm.VM) error{ - contractGetScript, - contractGetStorageContext, - contractIsPayable, storageContextAsReadOnly, storageDelete, storageFind, diff --git a/pkg/interop/contract/contract.go b/pkg/interop/contract/contract.go index 4a67f0748..509b41a17 100644 --- a/pkg/interop/contract/contract.go +++ b/pkg/interop/contract/contract.go @@ -3,54 +3,32 @@ Package contract provides functions to work with contracts. */ package contract -import "github.com/nspcc-dev/neo-go/pkg/interop/storage" - // Contract represents a Neo contract and is used in interop functions. It's // an opaque data structure that you can manipulate with using functions from // this package. It's similar in function to the Contract class in the Neo .net // framework. type Contract struct{} -// GetScript returns the script of the given contract. It uses -// `Neo.Contract.GetScript` syscall. -func GetScript(c Contract) []byte { - return nil -} - -// IsPayable returns whether the given contract is payable (able to accept -// asset transfers to its address). It uses `Neo.Contract.IsPayable` syscall. -func IsPayable(c Contract) bool { - return false -} - -// GetStorageContext returns storage context for the given contract. It only -// works for contracts created in this transaction (so you can't take a storage -// context for arbitrary contract). Refer to the `storage` package on how to -// use this context. This function uses `Neo.Contract.GetStorageContext` syscall. -func GetStorageContext(c Contract) storage.Context { - return storage.Context{} -} - // Create creates a new contract using a set of input parameters: // script contract's bytecode (limited in length by 1M) // manifest contract's manifest (limited in length by 2 KiB) // It returns this new created Contract when successful (and fails transaction -// if not). It uses `Neo.Contract.Create` syscall. +// if not). It uses `System.Contract.Create` syscall. func Create(script []byte, manifest []byte) Contract { return Contract{} } -// Migrate migrates calling contract (that is the one that calls Migrate) to -// the new contract. Its parameters have exactly the same semantics as for +// Update updates script and manifest of the calling contract (that is the one that calls Update) +// to the new ones. Its parameters have exactly the same semantics as for // Create. The old contract will be deleted by this call, if it has any storage // associated it will be migrated to the new contract. New contract is returned. -// This function uses `Neo.Contract.Migrate` syscall. -func Migrate(script []byte, manifest []byte) Contract { +// This function uses `System.Contract.Update` syscall. +func Update(script []byte, manifest []byte) Contract { return Contract{} } // Destroy deletes calling contract (the one that calls Destroy) from the // blockchain, so it's only possible to do that from the contract itself and // not by any outside code. When contract is deleted all associated storage -// items are deleted too. This function uses `Neo.Contract.Destroy` syscall. +// items are deleted too. This function uses `System.Contract.Destroy` syscall. func Destroy() {} diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index 5c3cd1eed..7176ff7f2 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -24,7 +24,7 @@ func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util. rawManifest := w.Bytes() emit.Bytes(script.BinWriter, rawManifest) emit.Bytes(script.BinWriter, avm) - emit.Syscall(script.BinWriter, "Neo.Contract.Create") + emit.Syscall(script.BinWriter, "System.Contract.Create") sysfee := util.Fixed8(core.StoragePrice * (len(avm) + len(rawManifest))) return script.Bytes(), sysfee, nil } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index bcc28e0f5..2d502f960 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -56,12 +56,12 @@ var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["9d84eee99b8fda7cba4931ae54b316c1c0468bd4526b8b4eb6cf62d771abe9c7"]`, + params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("9d84eee99b8fda7cba4931ae54b316c1c0468bd4526b8b4eb6cf62d771abe9c7") + expectedTxHash, err := util.Uint256DecodeStringLE("136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -483,7 +483,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["9d84eee99b8fda7cba4931ae54b316c1c0468bd4526b8b4eb6cf62d771abe9c7"]`, + params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, result: func(e *executor) interface{} { h := 0 return &h diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 39cd4d68c..482613445 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ