re-use serialized arguments for storing

This commit is contained in:
Erik van den Brink 2024-10-31 10:25:13 +01:00
parent dfd5c9bb68
commit cd7caf519a
2 changed files with 9 additions and 15 deletions

View file

@ -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,
})

View file

@ -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)
}