added filter payloads for spv client compliance (#90)

* added filter payloads for spv client compliance

* bumped version
This commit is contained in:
Anthony De Meulemeester 2018-08-10 16:32:49 +02:00 committed by GitHub
parent 2bc023b7e0
commit 34a37ff51d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 13 deletions

View file

@ -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

View file

@ -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
}