diff --git a/pkg/network/message.go b/pkg/network/message.go index 6c5b7902a..ba8f7380d 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -49,19 +49,23 @@ type CommandType string // Valid protocol commands used to send between nodes. const ( - CMDVersion CommandType = "version" - CMDVerack CommandType = "verack" - CMDGetAddr CommandType = "getaddr" - CMDAddr CommandType = "addr" - CMDGetHeaders CommandType = "getheaders" - CMDHeaders CommandType = "headers" - CMDGetBlocks CommandType = "getblocks" - CMDInv CommandType = "inv" - CMDGetData CommandType = "getdata" - CMDBlock CommandType = "block" - CMDTX CommandType = "tx" - CMDConsensus CommandType = "consensus" - CMDUnknown CommandType = "unknown" + CMDVersion CommandType = "version" + CMDVerack CommandType = "verack" + CMDGetAddr CommandType = "getaddr" + CMDAddr CommandType = "addr" + CMDGetHeaders CommandType = "getheaders" + CMDHeaders CommandType = "headers" + CMDGetBlocks CommandType = "getblocks" + CMDInv CommandType = "inv" + CMDGetData CommandType = "getdata" + CMDBlock CommandType = "block" + CMDTX CommandType = "tx" + CMDConsensus CommandType = "consensus" + CMDUnknown CommandType = "unknown" + CMDFilterAdd CommandType = "filteradd" + CMDFilterClear CommandType = "filterclear" + CMDFilterLoad CommandType = "filterload" + CMDMerkleBlock CommandType = "merkleblock" ) // NewMessage returns a new message with the given payload. @@ -119,6 +123,14 @@ func (m *Message) CommandType() CommandType { return CMDTX case "consensus": return CMDConsensus + case "merkleblock": + return CMDMerkleBlock + case "filterload": + return CMDFilterLoad + case "filteradd": + return CMDFilterAdd + case "filterclear": + return CMDFilterClear default: return CMDUnknown } @@ -198,6 +210,11 @@ func (m *Message) decodePayload(r io.Reader) error { if err := p.DecodeBinary(buf); err != nil { return err } + case CMDMerkleBlock: + p = &payload.MerkleBlock{} + if err := p.DecodeBinary(buf); err != nil { + return err + } } m.Payload = p diff --git a/pkg/network/payload/merkleblock.go b/pkg/network/payload/merkleblock.go new file mode 100644 index 000000000..bf46bbe81 --- /dev/null +++ b/pkg/network/payload/merkleblock.go @@ -0,0 +1,39 @@ +package payload + +import ( + "encoding/binary" + "io" + + "github.com/CityOfZion/neo-go/pkg/core" + "github.com/CityOfZion/neo-go/pkg/util" +) + +type MerkleBlock struct { + *core.BlockBase + TxCount int + Hashes []util.Uint256 + Flags []byte +} + +func (m *MerkleBlock) DecodeBinary(r io.Reader) error { + m.BlockBase = &core.BlockBase{} + if err := m.BlockBase.DecodeBinary(r); err != nil { + return err + } + + m.TxCount = int(util.ReadVarUint(r)) + n := util.ReadVarUint(r) + m.Hashes = make([]util.Uint256, n) + for i := 0; i < len(m.Hashes); i++ { + if err := binary.Read(r, binary.LittleEndian, &m.Hashes[i]); err != nil { + return err + } + } + var err error + m.Flags, err = util.ReadVarBytes(r) + return err +} + +func (m *MerkleBlock) EncodeBinary(w io.Writer) error { + return nil +}