From f8a11f61b62f7fc16887992c80f7df7383b30025 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 14:07:26 +0300 Subject: [PATCH] core: update *.Contract.* interops 1. Remove GetScript, IsPayable, GetStorageContext. 2. Revert 82319538 related to GetStorageContext. 3. Rename Migrate to Update. 4. Move remaining to System.Contract.*. Related #1031. --- pkg/compiler/syscall.go | 9 +++---- pkg/core/helper_test.go | 2 +- pkg/core/interop/context.go | 2 -- pkg/core/interop_neo.go | 26 ++----------------- pkg/core/interop_neo_test.go | 22 ---------------- pkg/core/interop_system.go | 22 ---------------- pkg/core/interops.go | 9 ++----- pkg/core/interops_test.go | 3 --- pkg/interop/contract/contract.go | 34 +++++-------------------- pkg/rpc/request/txBuilder.go | 2 +- pkg/rpc/server/server_test.go | 6 ++--- pkg/rpc/server/testdata/testblocks.acc | Bin 6784 -> 6784 bytes 12 files changed, 18 insertions(+), 119 deletions(-) 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 39cd4d68c1e202b51e21b1a945c199c9f359007d..48261344581038f8c46b38b4dce64a704ccaeeaf 100644 GI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