mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
6b21ad9922
Everywhere including examples, external interop APIs, bindings generators code and in other valuable places. A couple of `interface{}` usages are intentionally left in the CHANGELOG.md, documentation and tests.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package mpt
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
)
|
|
|
|
// EmptyNode represents an empty node.
|
|
type EmptyNode struct{}
|
|
|
|
// DecodeBinary implements the io.Serializable interface.
|
|
func (e EmptyNode) DecodeBinary(*io.BinReader) {
|
|
}
|
|
|
|
// EncodeBinary implements the io.Serializable interface.
|
|
func (e EmptyNode) EncodeBinary(*io.BinWriter) {
|
|
}
|
|
|
|
// Size implements Node interface.
|
|
func (EmptyNode) Size() int { return 0 }
|
|
|
|
// MarshalJSON implements Node interface.
|
|
func (e EmptyNode) MarshalJSON() ([]byte, error) {
|
|
return []byte(`{}`), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements Node interface.
|
|
func (e EmptyNode) UnmarshalJSON(bytes []byte) error {
|
|
var m map[string]any
|
|
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
|
|
}
|
|
|
|
// Clone implements Node interface.
|
|
func (EmptyNode) Clone() Node { return EmptyNode{} }
|