neoneo-go/pkg/network/payload/merkleblock.go
Roman Khimov 5bf00db2c9 io: move BinReader/BinWriter there, redo Serializable with it
The logic here is that we'll have all binary encoding/decoding done via our io
package, which simplifies error handling. This functionality doesn't belong to
util, so it's moved.

This also expands BufBinWriter with Reset() method to fit the needs of core
package.
2019-09-16 23:39:51 +03:00

37 lines
851 B
Go

package payload
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util"
)
// MerkleBlock represents a merkle block packet payload.
type MerkleBlock struct {
*core.BlockBase
TxCount int
Hashes []util.Uint256
Flags []byte
}
// DecodeBinary implements the Payload interface.
func (m *MerkleBlock) DecodeBinary(br *io.BinReader) error {
m.BlockBase = &core.BlockBase{}
if err := m.BlockBase.DecodeBinary(br); err != nil {
return err
}
m.TxCount = int(br.ReadVarUint())
n := br.ReadVarUint()
m.Hashes = make([]util.Uint256, n)
for i := 0; i < len(m.Hashes); i++ {
br.ReadLE(&m.Hashes[i])
}
m.Flags = br.ReadBytes()
return br.Err
}
// EncodeBinary implements the Payload interface.
func (m *MerkleBlock) EncodeBinary(bw *io.BinWriter) error {
return nil
}