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
|
@ -62,6 +62,10 @@ const (
|
||||||
CMDTX CommandType = "tx"
|
CMDTX CommandType = "tx"
|
||||||
CMDConsensus CommandType = "consensus"
|
CMDConsensus CommandType = "consensus"
|
||||||
CMDUnknown CommandType = "unknown"
|
CMDUnknown CommandType = "unknown"
|
||||||
|
CMDFilterAdd CommandType = "filteradd"
|
||||||
|
CMDFilterClear CommandType = "filterclear"
|
||||||
|
CMDFilterLoad CommandType = "filterload"
|
||||||
|
CMDMerkleBlock CommandType = "merkleblock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMessage returns a new message with the given payload.
|
// NewMessage returns a new message with the given payload.
|
||||||
|
@ -119,6 +123,14 @@ func (m *Message) CommandType() CommandType {
|
||||||
return CMDTX
|
return CMDTX
|
||||||
case "consensus":
|
case "consensus":
|
||||||
return CMDConsensus
|
return CMDConsensus
|
||||||
|
case "merkleblock":
|
||||||
|
return CMDMerkleBlock
|
||||||
|
case "filterload":
|
||||||
|
return CMDFilterLoad
|
||||||
|
case "filteradd":
|
||||||
|
return CMDFilterAdd
|
||||||
|
case "filterclear":
|
||||||
|
return CMDFilterClear
|
||||||
default:
|
default:
|
||||||
return CMDUnknown
|
return CMDUnknown
|
||||||
}
|
}
|
||||||
|
@ -198,6 +210,11 @@ func (m *Message) decodePayload(r io.Reader) error {
|
||||||
if err := p.DecodeBinary(buf); err != nil {
|
if err := p.DecodeBinary(buf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case CMDMerkleBlock:
|
||||||
|
p = &payload.MerkleBlock{}
|
||||||
|
if err := p.DecodeBinary(buf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Payload = p
|
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