mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
added filter payloads for spv client compliance (#90)
* added filter payloads for spv client compliance * bumped version
This commit is contained in:
parent
2bc023b7e0
commit
34a37ff51d
2 changed files with 69 additions and 13 deletions
|
@ -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
|
||||
|
|
39
pkg/network/payload/merkleblock.go
Normal file
39
pkg/network/payload/merkleblock.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue