Skip to content

Commit

Permalink
re-use serialized arguments for storing
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Oct 31, 2024
1 parent dfd5c9b commit cd7caf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 3 additions & 1 deletion pkg/core/interop/contract/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -83,6 +84,7 @@ func Call(ic *interop.Context) error {
Hash: u,
Method: method,
Arguments: arr,
ArgumentsBytes: argBytes,
ArgumentsCount: uint32(arrCount),
IsValid: valid,
})
Expand Down
20 changes: 6 additions & 14 deletions pkg/core/state/notification_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,28 @@ 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"`
}

func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) {
ci.Hash.DecodeBinary(r)
ci.Method = r.ReadString()
args := stackitem.DecodeBinary(r)
if r.Err != nil {
return
}
arr, ok := args.Value().([]stackitem.Item)
if !ok {
r.Err = errors.New("array or Struct expected")
ci.ArgumentsBytes = r.ReadVarBytes()
si, err := stackitem.Deserialize(ci.ArgumentsBytes)
if err != nil {
return
}
ci.Arguments = stackitem.NewArray(arr)
ci.Arguments = si.(*stackitem.Array)
ci.ArgumentsCount = r.ReadU32LE()
ci.IsValid = r.ReadBool()
}

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)
}
Expand Down

0 comments on commit cd7caf5

Please sign in to comment.