2021-07-30 13:57:42 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
)
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// MPTData represents a set of serialized MPT nodes.
|
2021-07-30 13:57:42 +00:00
|
|
|
type MPTData struct {
|
|
|
|
Nodes [][]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements io.Serializable.
|
|
|
|
func (d *MPTData) EncodeBinary(w *io.BinWriter) {
|
|
|
|
w.WriteVarUint(uint64(len(d.Nodes)))
|
|
|
|
for _, n := range d.Nodes {
|
|
|
|
w.WriteVarBytes(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements io.Serializable.
|
|
|
|
func (d *MPTData) DecodeBinary(r *io.BinReader) {
|
|
|
|
sz := r.ReadVarUint()
|
|
|
|
if sz == 0 {
|
|
|
|
r.Err = errors.New("empty MPT nodes list")
|
|
|
|
return
|
|
|
|
}
|
2024-08-30 18:41:02 +00:00
|
|
|
for range sz {
|
2021-07-30 13:57:42 +00:00
|
|
|
d.Nodes = append(d.Nodes, r.ReadVarBytes())
|
|
|
|
if r.Err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|