mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-03 09:22:49 +00:00
re-use serialized arguments for storing
This commit is contained in:
parent
dfd5c9bb68
commit
cd7caf519a
2 changed files with 9 additions and 15 deletions
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue