From 8b7abd36c99f874069c1c8de61b15262c4bb413d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 9 Jun 2020 13:24:37 +0300 Subject: [PATCH] core: remove Block.GetTransactions, Block.GetTransactionsCount interops Updated System.Blockchain.GetBlock interop replaced the functionality of the following interops: System.Block.GetTransactions System.Block.GetTransactionCount Neo.Block.GetTransactions Neo.Block.GetTransactionsCount --- pkg/compiler/syscall.go | 4 ---- pkg/core/interop_system.go | 29 ----------------------------- pkg/core/interops.go | 4 ---- pkg/core/interops_test.go | 2 -- pkg/interop/block/block.go | 24 ------------------------ 5 files changed, 63 deletions(-) delete mode 100644 pkg/interop/block/block.go diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 0ea6e1158..f6bbf3ccf 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -55,10 +55,6 @@ var syscalls = map[string]map[string]string{ "GetConsensusData": "Neo.Header.GetConsensusData", "GetNextConsensus": "Neo.Header.GetNextConsensus", }, - "block": { - "GetTransactionCount": "Neo.Block.GetTransactionCount", - "GetTransactions": "Neo.Block.GetTransactions", - }, "contract": { "GetScript": "Neo.Contract.GetScript", "IsPayable": "Neo.Contract.IsPayable", diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index a571a09cf..9a30fbaf8 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -250,35 +250,6 @@ func headerGetTimestamp(ic *interop.Context, v *vm.VM) error { return nil } -// blockGetTransactionCount returns transactions count in the given block. -func blockGetTransactionCount(ic *interop.Context, v *vm.VM) error { - blockInterface := v.Estack().Pop().Value() - block, ok := blockInterface.(*block.Block) - if !ok { - return errors.New("value is not a block") - } - v.Estack().PushVal(len(block.Transactions)) - return nil -} - -// blockGetTransactions returns transactions from the given block. -func blockGetTransactions(ic *interop.Context, v *vm.VM) error { - blockInterface := v.Estack().Pop().Value() - block, ok := blockInterface.(*block.Block) - if !ok { - return errors.New("value is not a block") - } - if len(block.Transactions) > vm.MaxArraySize { - return errors.New("too many transactions") - } - txes := make([]stackitem.Item, 0, len(block.Transactions)) - for _, tx := range block.Transactions { - txes = append(txes, stackitem.NewInterop(tx)) - } - v.Estack().PushVal(txes) - return nil -} - // engineGetScriptContainer returns transaction that contains the script being // run. func engineGetScriptContainer(ic *interop.Context, v *vm.VM) error { diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 97bc2a6af..889742b3a 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -62,8 +62,6 @@ func getInteropFromSlice(ic *interop.Context, slice []interop.Function) func(uin // All lists are sorted, keep 'em this way, please. var systemInterops = []interop.Function{ - {Name: "System.Block.GetTransactionCount", Func: blockGetTransactionCount, Price: 1}, - {Name: "System.Block.GetTransactions", Func: blockGetTransactions, Price: 1}, {Name: "System.Blockchain.GetBlock", Func: bcGetBlock, Price: 250}, {Name: "System.Blockchain.GetContract", Func: bcGetContract, Price: 100}, {Name: "System.Blockchain.GetHeader", Func: bcGetHeader, Price: 100}, @@ -104,8 +102,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Account.GetBalance", Func: accountGetBalance, Price: 1}, {Name: "Neo.Account.GetScriptHash", Func: accountGetScriptHash, Price: 1}, {Name: "Neo.Account.IsStandard", Func: accountIsStandard, Price: 100}, - {Name: "Neo.Block.GetTransactionCount", Func: blockGetTransactionCount, Price: 1}, - {Name: "Neo.Block.GetTransactions", Func: blockGetTransactions, Price: 1}, {Name: "Neo.Blockchain.GetAccount", Func: bcGetAccount, Price: 100}, {Name: "Neo.Blockchain.GetContract", Func: bcGetContract, Price: 100}, {Name: "Neo.Blockchain.GetHeader", Func: bcGetHeader, Price: 100}, diff --git a/pkg/core/interops_test.go b/pkg/core/interops_test.go index 4b1168ff9..40d4db5ae 100644 --- a/pkg/core/interops_test.go +++ b/pkg/core/interops_test.go @@ -34,8 +34,6 @@ func TestUnexpectedNonInterops(t *testing.T) { funcs := []func(*interop.Context, *vm.VM) error{ accountGetBalance, accountGetScriptHash, - blockGetTransactionCount, - blockGetTransactions, contractGetScript, contractGetStorageContext, contractIsPayable, diff --git a/pkg/interop/block/block.go b/pkg/interop/block/block.go deleted file mode 100644 index b47d25158..000000000 --- a/pkg/interop/block/block.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Package block provides getters for Neo Block structure. -*/ -package block - -import "github.com/nspcc-dev/neo-go/pkg/interop/blockchain" - -// Block represents a NEO block, it's an opaque data structure that you can get -// data from only using functions from this package. It's similar in function to -// the Block class in the Neo .net framework. To use it you need to get it via -// blockchain.GetBlock function call. -type Block struct{} - -// GetTransactionCount returns the number of recorded transactions in the given -// block. It uses `Neo.Block.GetTransactionCount` syscall internally. -func GetTransactionCount(b Block) int { - return 0 -} - -// GetTransactions returns a slice of transactions recorded in the given block. -// It uses `Neo.Block.GetTransactions` syscall internally. -func GetTransactions(b Block) []blockchain.Transaction { - return []blockchain.Transaction{} -}