2021-08-03 14:10:46 +00:00
|
|
|
package mpt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// EmptyNode represents an empty node.
|
2021-08-03 14:10:46 +00:00
|
|
|
type EmptyNode struct{}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// DecodeBinary implements the io.Serializable interface.
|
2021-08-03 14:10:46 +00:00
|
|
|
func (e EmptyNode) DecodeBinary(*io.BinReader) {
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// EncodeBinary implements the io.Serializable interface.
|
2021-08-03 14:10:46 +00:00
|
|
|
func (e EmptyNode) EncodeBinary(*io.BinWriter) {
|
|
|
|
}
|
|
|
|
|
2021-08-03 15:50:13 +00:00
|
|
|
// Size implements Node interface.
|
|
|
|
func (EmptyNode) Size() int { return 0 }
|
|
|
|
|
2021-08-03 14:10:46 +00:00
|
|
|
// MarshalJSON implements Node interface.
|
|
|
|
func (e EmptyNode) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte(`{}`), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements Node interface.
|
|
|
|
func (e EmptyNode) UnmarshalJSON(bytes []byte) error {
|
2023-04-03 10:34:24 +00:00
|
|
|
var m map[string]any
|
2021-08-03 14:10:46 +00:00
|
|
|
err := json.Unmarshal(bytes, &m)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(m) != 0 {
|
|
|
|
return errors.New("expected empty node")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash implements Node interface.
|
|
|
|
func (e EmptyNode) Hash() util.Uint256 {
|
|
|
|
panic("can't get hash of an EmptyNode")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type implements Node interface.
|
|
|
|
func (e EmptyNode) Type() NodeType {
|
|
|
|
return EmptyT
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bytes implements Node interface.
|
|
|
|
func (e EmptyNode) Bytes() []byte {
|
|
|
|
return nil
|
|
|
|
}
|
2021-08-27 13:58:27 +00:00
|
|
|
|
|
|
|
// Clone implements Node interface.
|
|
|
|
func (EmptyNode) Clone() Node { return EmptyNode{} }
|