github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/mpt/empty.go (about) 1 package mpt 2 3 import ( 4 "encoding/json" 5 "errors" 6 7 "github.com/nspcc-dev/neo-go/pkg/io" 8 "github.com/nspcc-dev/neo-go/pkg/util" 9 ) 10 11 // EmptyNode represents an empty node. 12 type EmptyNode struct{} 13 14 // DecodeBinary implements the io.Serializable interface. 15 func (e EmptyNode) DecodeBinary(*io.BinReader) { 16 } 17 18 // EncodeBinary implements the io.Serializable interface. 19 func (e EmptyNode) EncodeBinary(*io.BinWriter) { 20 } 21 22 // Size implements Node interface. 23 func (EmptyNode) Size() int { return 0 } 24 25 // MarshalJSON implements Node interface. 26 func (e EmptyNode) MarshalJSON() ([]byte, error) { 27 return []byte(`{}`), nil 28 } 29 30 // UnmarshalJSON implements Node interface. 31 func (e EmptyNode) UnmarshalJSON(bytes []byte) error { 32 var m map[string]any 33 err := json.Unmarshal(bytes, &m) 34 if err != nil { 35 return err 36 } 37 if len(m) != 0 { 38 return errors.New("expected empty node") 39 } 40 return nil 41 } 42 43 // Hash implements Node interface. 44 func (e EmptyNode) Hash() util.Uint256 { 45 panic("can't get hash of an EmptyNode") 46 } 47 48 // Type implements Node interface. 49 func (e EmptyNode) Type() NodeType { 50 return EmptyT 51 } 52 53 // Bytes implements Node interface. 54 func (e EmptyNode) Bytes() []byte { 55 return nil 56 } 57 58 // Clone implements Node interface. 59 func (EmptyNode) Clone() Node { return EmptyNode{} }