github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/network/payload/merkleblock.go (about) 1 package payload 2 3 import ( 4 "errors" 5 6 "github.com/nspcc-dev/neo-go/pkg/core/block" 7 "github.com/nspcc-dev/neo-go/pkg/io" 8 "github.com/nspcc-dev/neo-go/pkg/util" 9 ) 10 11 // MerkleBlock represents a merkle block packet payload. 12 type MerkleBlock struct { 13 *block.Header 14 TxCount int 15 Hashes []util.Uint256 16 Flags []byte 17 } 18 19 // DecodeBinary implements the Serializable interface. 20 func (m *MerkleBlock) DecodeBinary(br *io.BinReader) { 21 m.Header = &block.Header{} 22 m.Header.DecodeBinary(br) 23 24 txCount := int(br.ReadVarUint()) 25 if txCount > block.MaxTransactionsPerBlock { 26 br.Err = block.ErrMaxContentsPerBlock 27 return 28 } 29 m.TxCount = txCount 30 br.ReadArray(&m.Hashes, m.TxCount) 31 if txCount != len(m.Hashes) { 32 br.Err = errors.New("invalid tx count") 33 } 34 m.Flags = br.ReadVarBytes((txCount + 7) / 8) 35 } 36 37 // EncodeBinary implements the Serializable interface. 38 func (m *MerkleBlock) EncodeBinary(bw *io.BinWriter) { 39 m.Header.EncodeBinary(bw) 40 41 bw.WriteVarUint(uint64(m.TxCount)) 42 bw.WriteArray(m.Hashes) 43 bw.WriteVarBytes(m.Flags) 44 }