From c4f7b06974cfe36238db09c20c55450f19e38a17 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 13 Jul 2020 13:05:31 +0300 Subject: [PATCH] core, compiler: return struct from GetScriptContainer interop Closes #1173 --- examples/engine/engine.go | 2 +- pkg/compiler/codegen.go | 2 +- pkg/core/interop_system.go | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/engine/engine.go b/examples/engine/engine.go index e747863d1..f71db3399 100644 --- a/examples/engine/engine.go +++ b/examples/engine/engine.go @@ -7,7 +7,7 @@ import ( // Main is that famous Main() function, you know. func Main() bool { tx := runtime.GetScriptContainer() - runtime.Notify(tx) + runtime.Notify(tx.Hash) callingScriptHash := runtime.GetCallingScriptHash() runtime.Notify(callingScriptHash) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index f51de0942..1b71e3a41 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1146,7 +1146,7 @@ func (c *codegen) convertSyscall(expr *ast.CallExpr, api, name string) { } emit.Syscall(c.prog.BinWriter, api) switch name { - case "GetTransaction", "GetBlock": + case "GetTransaction", "GetBlock", "GetScriptContainer": c.emitConvert(stackitem.StructT) } diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index c1df13b58..0b2905aad 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -179,10 +179,19 @@ func bcGetTransactionHeight(ic *interop.Context, v *vm.VM) error { return nil } -// engineGetScriptContainer returns transaction that contains the script being -// run. +// engineGetScriptContainer returns transaction or block that contains the script +// being run. func engineGetScriptContainer(ic *interop.Context, v *vm.VM) error { - v.Estack().PushVal(stackitem.NewInterop(ic.Container)) + var item stackitem.Item + switch t := ic.Container.(type) { + case *transaction.Transaction: + item = transactionToStackItem(t) + case *block.Block: + item = blockToStackItem(t) + default: + return errors.New("unknown script container") + } + v.Estack().PushVal(item) return nil }