stackitem: serialize/deserialize pointers, fix #2815
They of course can't be serialized, but in protected mode we still need to handle them somehow.
This commit is contained in:
parent
286f40b828
commit
9ba18b5dfa
2 changed files with 31 additions and 0 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// MaxDeserialized is the maximum number one deserialized item can contain
|
||||
|
@ -168,6 +169,13 @@ func (w *SerializationContext) serialize(item Item) error {
|
|||
} else {
|
||||
return fmt.Errorf("%w: Interop", ErrUnserializable)
|
||||
}
|
||||
case *Pointer:
|
||||
if w.allowInvalid {
|
||||
w.data = append(w.data, byte(PointerT))
|
||||
w.appendVarUint(uint64(t.pos))
|
||||
} else {
|
||||
return fmt.Errorf("%w: Pointer", ErrUnserializable)
|
||||
}
|
||||
case *Array:
|
||||
w.data = append(w.data, byte(ArrayT))
|
||||
if err := w.writeArray(item, t.value, start); err != nil {
|
||||
|
@ -311,6 +319,12 @@ func (r *deserContext) decodeBinary() Item {
|
|||
return NewInterop(nil)
|
||||
}
|
||||
fallthrough
|
||||
case PointerT:
|
||||
if r.allowInvalid {
|
||||
pos := int(r.ReadVarUint())
|
||||
return NewPointerWithHash(pos, nil, util.Uint160{})
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
if t == InvalidT && r.allowInvalid {
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue