diff --git a/pkg/rpc/response/result/invoke.go b/pkg/rpc/response/result/invoke.go index 5f84ba5cc..e1073954c 100644 --- a/pkg/rpc/response/result/invoke.go +++ b/pkg/rpc/response/result/invoke.go @@ -10,7 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/vm" + "github.com/nspcc-dev/neo-go/pkg/vm/invocations" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -36,8 +36,8 @@ type RegisterIterator func(sessionID string, item stackitem.Item, id int, finali // InvokeDiag is an additional diagnostic data for invocation. type InvokeDiag struct { - Changes []storage.Operation `json:"storagechanges"` - Invocations []*vm.InvocationTree `json:"invokedcontracts"` + Changes []storage.Operation `json:"storagechanges"` + Invocations []*invocations.Tree `json:"invokedcontracts"` } // NewInvoke returns a new Invoke structure with the given fields set. diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 412c1f692..b36c10f62 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -41,8 +41,8 @@ import ( rpc2 "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/emit" + "github.com/nspcc-dev/neo-go/pkg/vm/invocations" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" @@ -962,12 +962,12 @@ var rpcTestCases = map[string][]rpcTestCase{ Notifications: []state.NotificationEvent{}, Diagnostics: &result.InvokeDiag{ Changes: []storage.Operation{}, - Invocations: []*vm.InvocationTree{{ + Invocations: []*invocations.Tree{{ Current: hash.Hash160(script), - Calls: []*vm.InvocationTree{ + Calls: []*invocations.Tree{ { Current: nnsHash, - Calls: []*vm.InvocationTree{ + Calls: []*invocations.Tree{ { Current: stdHash, }, @@ -1075,12 +1075,12 @@ var rpcTestCases = map[string][]rpcTestCase{ Notifications: []state.NotificationEvent{}, Diagnostics: &result.InvokeDiag{ Changes: []storage.Operation{}, - Invocations: []*vm.InvocationTree{{ + Invocations: []*invocations.Tree{{ Current: hash.Hash160(script), - Calls: []*vm.InvocationTree{ + Calls: []*invocations.Tree{ { Current: nnsHash, - Calls: []*vm.InvocationTree{ + Calls: []*invocations.Tree{ { Current: stdHash, }, @@ -1167,7 +1167,7 @@ var rpcTestCases = map[string][]rpcTestCase{ Notifications: []state.NotificationEvent{}, Diagnostics: &result.InvokeDiag{ Changes: []storage.Operation{}, - Invocations: []*vm.InvocationTree{{ + Invocations: []*invocations.Tree{{ Current: hash.Hash160(script), }}, }, @@ -1278,7 +1278,7 @@ var rpcTestCases = map[string][]rpcTestCase{ Notifications: []state.NotificationEvent{}, Diagnostics: &result.InvokeDiag{ Changes: []storage.Operation{}, - Invocations: []*vm.InvocationTree{{ + Invocations: []*invocations.Tree{{ Current: hash.Hash160(script), }}, }, diff --git a/pkg/vm/context.go b/pkg/vm/context.go index 5cdbf9a4c..955554482 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/invocations" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -53,7 +54,7 @@ type Context struct { // NEF represents a NEF file for the current contract. NEF *nef.File // invTree is an invocation tree (or branch of it) for this context. - invTree *InvocationTree + invTree *invocations.Tree // onUnload is a callback that should be called after current context unloading // if no exception occurs. onUnload ContextUnloadCallback diff --git a/pkg/vm/invocation_tree.go b/pkg/vm/invocation_tree.go deleted file mode 100644 index c743310be..000000000 --- a/pkg/vm/invocation_tree.go +++ /dev/null @@ -1,12 +0,0 @@ -package vm - -import ( - "github.com/nspcc-dev/neo-go/pkg/util" -) - -// InvocationTree represents a tree with script hashes; when traversing it, -// you can see how contracts called each other. -type InvocationTree struct { - Current util.Uint160 `json:"hash"` - Calls []*InvocationTree `json:"call,omitempty"` -} diff --git a/pkg/vm/invocation_tree_test.go b/pkg/vm/invocation_tree_test.go index dc60ba677..b3f3896c7 100644 --- a/pkg/vm/invocation_tree_test.go +++ b/pkg/vm/invocation_tree_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/invocations" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/stretchr/testify/require" ) @@ -36,13 +37,13 @@ func TestInvocationTree(t *testing.T) { topHash := v.Context().ScriptHash() require.NoError(t, v.Run()) - res := &InvocationTree{ - Calls: []*InvocationTree{{ + res := &invocations.Tree{ + Calls: []*invocations.Tree{{ Current: topHash, - Calls: []*InvocationTree{ + Calls: []*invocations.Tree{ { Current: util.Uint160{1}, - Calls: []*InvocationTree{ + Calls: []*invocations.Tree{ { Current: util.Uint160{2}, }, @@ -53,7 +54,7 @@ func TestInvocationTree(t *testing.T) { }, { Current: util.Uint160{4}, - Calls: []*InvocationTree{ + Calls: []*invocations.Tree{ { Current: util.Uint160{5}, }, diff --git a/pkg/vm/invocations/invocation_tree.go b/pkg/vm/invocations/invocation_tree.go new file mode 100644 index 000000000..9b5f0be0e --- /dev/null +++ b/pkg/vm/invocations/invocation_tree.go @@ -0,0 +1,12 @@ +package invocations + +import ( + "github.com/nspcc-dev/neo-go/pkg/util" +) + +// Tree represents a tree with script hashes; when traversing it, +// you can see how contracts called each other. +type Tree struct { + Current util.Uint160 `json:"hash"` + Calls []*Tree `json:"call,omitempty"` +} diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index d29b2f9fc..aea077e74 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -21,6 +21,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util/slice" + "github.com/nspcc-dev/neo-go/pkg/vm/invocations" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" @@ -87,7 +88,7 @@ type VM struct { trigger trigger.Type // invTree is a top-level invocation tree (if enabled). - invTree *InvocationTree + invTree *invocations.Tree } var ( @@ -271,11 +272,11 @@ func (v *VM) LoadFileWithFlags(path string, f callflag.CallFlag) error { // CollectInvocationTree enables collecting invocation tree data. func (v *VM) EnableInvocationTree() { - v.invTree = &InvocationTree{} + v.invTree = &invocations.Tree{} } // GetInvocationTree returns the current invocation tree structure. -func (v *VM) GetInvocationTree() *InvocationTree { +func (v *VM) GetInvocationTree() *invocations.Tree { return v.invTree } @@ -356,7 +357,7 @@ func (v *VM) loadScriptWithCallingHash(b []byte, exe *nef.File, caller util.Uint if parent != nil { curTree = parent.invTree } - newTree := &InvocationTree{Current: ctx.ScriptHash()} + newTree := &invocations.Tree{Current: ctx.ScriptHash()} curTree.Calls = append(curTree.Calls, newTree) ctx.invTree = newTree }