forked from decred/dcrd
/
msggetcfilterv2.go
69 lines (58 loc) · 2.34 KB
/
msggetcfilterv2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2019-2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package wire
import (
"fmt"
"io"
"github.com/sebitt27/dcrd/chaincfg/chainhash"
)
// MsgGetCFilterV2 implements the Message interface and represents a decred
// getcfilterv2 message. It is used to request a version 2 committed gcs filter
// for a given block along with a proof that can be used to prove the filter is
// committed to by the block header. Note that the proof is only useful once
// the vote to enable header commitments is active. The filter is returned via
// a cfilterv2 message (MsgCFilterV2). Unknown blocks are ignored.
type MsgGetCFilterV2 struct {
BlockHash chainhash.Hash
}
// BtcDecode decodes r using the Decred protocol encoding into the receiver.
// This is part of the Message interface implementation.
func (msg *MsgGetCFilterV2) BtcDecode(r io.Reader, pver uint32) error {
const op = "MsgGetCFilterV2.BtcDecode"
if pver < CFilterV2Version {
msg := fmt.Sprintf("%s message invalid for protocol version %d",
msg.Command(), pver)
return messageError(op, ErrMsgInvalidForPVer, msg)
}
return readElement(r, &msg.BlockHash)
}
// BtcEncode encodes the receiver to w using the Decred protocol encoding.
// This is part of the Message interface implementation.
func (msg *MsgGetCFilterV2) BtcEncode(w io.Writer, pver uint32) error {
const op = "MsgGetCFilterV2.BtcEncode"
if pver < CFilterV2Version {
msg := fmt.Sprintf("%s message invalid for protocol version %d",
msg.Command(), pver)
return messageError(op, ErrMsgInvalidForPVer, msg)
}
return writeElement(w, &msg.BlockHash)
}
// Command returns the protocol command string for the message. This is part
// of the Message interface implementation.
func (msg *MsgGetCFilterV2) Command() string {
return CmdGetCFilterV2
}
// MaxPayloadLength returns the maximum length the payload can be for the
// receiver. This is part of the Message interface implementation.
func (msg *MsgGetCFilterV2) MaxPayloadLength(pver uint32) uint32 {
// Block hash.
return chainhash.HashSize
}
// NewMsgGetCFilterV2 returns a new Decred getcfilterv2 message that conforms
// to the Message interface using the passed parameters.
func NewMsgGetCFilterV2(blockHash *chainhash.Hash) *MsgGetCFilterV2 {
return &MsgGetCFilterV2{
BlockHash: *blockHash,
}
}