forked from ltcsuite/ltcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msggetmwebutxos.go
100 lines (82 loc) · 2.77 KB
/
msggetmwebutxos.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2024 The ltcsuite 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/ltcmweb/ltcd/chaincfg/chainhash"
)
type MwebNetUtxoType byte
const (
MwebNetUtxoFull MwebNetUtxoType = iota
MwebNetUtxoHashOnly
MwebNetUtxoCompact
)
// MsgGetMwebUtxos implements the Message interface and represents a litecoin
// getmwebutxos message which is used to request a batch of MWEB UTXOs.
//
// This message was not added until protocol version MwebLightClientVersion.
type MsgGetMwebUtxos struct {
BlockHash chainhash.Hash
StartIndex uint64
NumRequested uint16
OutputFormat MwebNetUtxoType
}
// BtcDecode decodes r using the litecoin protocol encoding into the receiver.
// This is part of the Message interface implementation.
func (msg *MsgGetMwebUtxos) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
if pver < MwebLightClientVersion {
str := fmt.Sprintf("getmwebutxos message invalid for protocol "+
"version %d", pver)
return messageError("MsgGetMwebUtxos.BtcDecode", str)
}
err := readElement(r, &msg.BlockHash)
if err != nil {
return err
}
msg.StartIndex, err = ReadVarInt(r, pver)
if err != nil {
return err
}
return readElements(r, &msg.NumRequested, &msg.OutputFormat)
}
// BtcEncode encodes the receiver to w using the litecoin protocol encoding.
// This is part of the Message interface implementation.
func (msg *MsgGetMwebUtxos) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error {
if pver < MwebLightClientVersion {
str := fmt.Sprintf("getmwebutxos message invalid for protocol "+
"version %d", pver)
return messageError("MsgGetMwebUtxos.BtcEncode", str)
}
err := writeElement(w, &msg.BlockHash)
if err != nil {
return err
}
err = WriteVarInt(w, pver, msg.StartIndex)
if err != nil {
return err
}
return writeElements(w, msg.NumRequested, msg.OutputFormat)
}
// Command returns the protocol command string for the message. This is part
// of the Message interface implementation.
func (msg *MsgGetMwebUtxos) Command() string {
return CmdGetMwebUtxos
}
// MaxPayloadLength returns the maximum length the payload can be for the
// receiver. This is part of the Message interface implementation.
func (msg *MsgGetMwebUtxos) MaxPayloadLength(pver uint32) uint32 {
return MaxBlockPayload
}
// NewMsgGetMwebUtxos returns a new litecoin getmwebutxos message that conforms to
// the Message interface. See MsgGetMwebUtxos for details.
func NewMsgGetMwebUtxos(blockHash chainhash.Hash, startIndex uint64,
numRequested uint16, outputFormat MwebNetUtxoType) *MsgGetMwebUtxos {
return &MsgGetMwebUtxos{
BlockHash: blockHash,
StartIndex: startIndex,
NumRequested: numRequested,
OutputFormat: outputFormat,
}
}