From cd7caf519a60e032f3b3a38fd4ba9e9596c0ecec Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Thu, 31 Oct 2024 10:25:13 +0100 Subject: [PATCH] re-use serialized arguments for storing --- pkg/core/interop/contract/call.go | 4 +++- pkg/core/state/notification_event.go | 20 ++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pkg/core/interop/contract/call.go b/pkg/core/interop/contract/call.go index bc91010fc..be1bbfdea 100644 --- a/pkg/core/interop/contract/call.go +++ b/pkg/core/interop/contract/call.go @@ -74,7 +74,8 @@ func Call(ic *interop.Context) error { arr := stackitem.NewArray(args) arrCount := len(args) valid := true - if _, err = ic.DAO.GetItemCtx().Serialize(arr, false); err != nil { + argBytes := []byte{} + if argBytes, err = ic.DAO.GetItemCtx().Serialize(arr, false); err != nil { arr = stackitem.NewArray([]stackitem.Item{}) valid = false } @@ -83,6 +84,7 @@ func Call(ic *interop.Context) error { Hash: u, Method: method, Arguments: arr, + ArgumentsBytes: argBytes, ArgumentsCount: uint32(arrCount), IsValid: valid, }) diff --git a/pkg/core/state/notification_event.go b/pkg/core/state/notification_event.go index 17619de68..0d0394a4d 100644 --- a/pkg/core/state/notification_event.go +++ b/pkg/core/state/notification_event.go @@ -24,6 +24,7 @@ type ContractInvocation struct { Hash util.Uint160 `json:"contract_hash"` Method string `json:"method"` Arguments *stackitem.Array `json:"arguments"` + ArgumentsBytes []byte `json:"arguments_bytes"` ArgumentsCount uint32 `json:"arguments_count"` IsValid bool `json:"is_valid"` } @@ -31,16 +32,12 @@ type ContractInvocation struct { func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) { ci.Hash.DecodeBinary(r) ci.Method = r.ReadString() - args := stackitem.DecodeBinary(r) - if r.Err != nil { + ci.ArgumentsBytes = r.ReadVarBytes() + si, err := stackitem.Deserialize(ci.ArgumentsBytes) + if err != nil { return } - arr, ok := args.Value().([]stackitem.Item) - if !ok { - r.Err = errors.New("array or Struct expected") - return - } - ci.Arguments = stackitem.NewArray(arr) + ci.Arguments = si.(*stackitem.Array) ci.ArgumentsCount = r.ReadU32LE() ci.IsValid = r.ReadBool() } @@ -48,12 +45,7 @@ func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) { func (ci *ContractInvocation) EncodeBinaryWithContext(w *io.BinWriter, sc *stackitem.SerializationContext) { ci.Hash.EncodeBinary(w) w.WriteString(ci.Method) - b, err := sc.Serialize(ci.Arguments, false) - if err != nil { - w.Err = err - return - } - w.WriteBytes(b) + w.WriteVarBytes(ci.ArgumentsBytes) w.WriteU32LE(ci.ArgumentsCount) w.WriteBool(ci.IsValid) }