forked from btcsuite/btcd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6102e12
commit b8c3be7
Showing
7 changed files
with
216 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2017 The btcsuite developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package wire | ||
|
||
import ( | ||
"fmt" | ||
"github.com/btcsuite/fastsha256" | ||
"io" | ||
) | ||
|
||
const ( | ||
// MaxCFilterHeaderDataSize is the maximum byte size of a committed | ||
// filter header. | ||
MaxCFilterHeaderDataSize = fastsha256.Size | ||
) | ||
type MsgCFilterHeader struct { | ||
Data []byte | ||
} | ||
|
||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver. | ||
// This is part of the Message interface implementation. | ||
func (msg *MsgCFilterHeader) BtcDecode(r io.Reader, pver uint32) error { | ||
var err error | ||
msg.Data, err = ReadVarBytes(r, pver, MaxCFilterHeaderDataSize, | ||
"cf header data") | ||
return err | ||
} | ||
|
||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding. | ||
// This is part of the Message interface implementation. | ||
func (msg *MsgCFilterHeader) BtcEncode(w io.Writer, pver uint32) error { | ||
size := len(msg.Data) | ||
if size > MaxCFilterHeaderDataSize { | ||
str := fmt.Sprintf("cf header size too large for message " + | ||
"[size %v, max %v]", size, MaxCFilterHeaderDataSize) | ||
return messageError("MsgCFilterHeader.BtcEncode", str) | ||
} | ||
|
||
return WriteVarBytes(w, pver, msg.Data) | ||
} | ||
|
||
// Command returns the protocol command string for the message. This is part | ||
// of the Message interface implementation. | ||
func (msg *MsgCFilterHeader) Command() string { | ||
return CmdCFilterHeader | ||
} | ||
|
||
// MaxPayloadLength returns the maximum length the payload can be for the | ||
// receiver. This is part of the Message interface implementation. | ||
func (msg *MsgCFilterHeader) MaxPayloadLength(pver uint32) uint32 { | ||
return uint32(VarIntSerializeSize(MaxCFilterHeaderDataSize)) + | ||
MaxCFilterHeaderDataSize | ||
} | ||
|
||
// NewMsgFilterAdd returns a new bitcoin cfilterheader message that conforms to | ||
// the Message interface. See MsgCFilterHeader for details. | ||
func NewMsgCFilterHeader(data []byte) *MsgCFilterHeader { | ||
return &MsgCFilterHeader{ | ||
Data: data, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2017 The btcsuite developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package wire | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
) | ||
|
||
type MsgGetCFilterHeader struct { | ||
ProtocolVersion uint32 | ||
BlockHash chainhash.Hash | ||
Extended bool | ||
} | ||
|
||
func (msg *MsgGetCFilterHeader) BtcDecode(r io.Reader, pver uint32) error { | ||
err := readElement(r, &msg.BlockHash) | ||
if err != nil { | ||
return err | ||
} | ||
return readElement(r, &msg.Extended) | ||
} | ||
|
||
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding. | ||
// This is part of the Message interface implementation. | ||
func (msg *MsgGetCFilterHeader) BtcEncode(w io.Writer, pver uint32) error { | ||
err := writeElement(w, &msg.BlockHash) | ||
if err != nil { | ||
return err | ||
} | ||
return writeElement(w, &msg.Extended) | ||
} | ||
|
||
// Command returns the protocol command string for the message. This is part | ||
// of the Message interface implementation. | ||
func (msg *MsgGetCFilterHeader) Command() string { | ||
return CmdGetCFilterHeader | ||
} | ||
|
||
// MaxPayloadLength returns the maximum length the payload can be for the | ||
// receiver. This is part of the Message interface implementation. | ||
func (msg *MsgGetCFilterHeader) MaxPayloadLength(pver uint32) uint32 { | ||
// Protocol version 4 bytes + block hash + Extended flag. | ||
return 4 + chainhash.HashSize + 1 | ||
} | ||
|
||
// NewMsgGetCFilterHeader returns a new bitcoin getcfilterheader message that | ||
// conforms to the Message interface using the passed parameters and defaults | ||
// for the remaining fields. | ||
func NewMsgGetCFilterHeader(blockHash *chainhash.Hash, extended bool) *MsgGetCFilterHeader { | ||
return &MsgGetCFilterHeader{ | ||
ProtocolVersion: ProtocolVersion, | ||
BlockHash: *blockHash, | ||
Extended: extended, | ||
} | ||
} |