lnwire: refactor Encode to use specific writers - I

This commit takes 10 types of messages and refactors their Encode method
to use specific writers. The following commits will refactor the rest.
This commit is contained in:
yyforyongyu
2021-06-18 15:03:43 +08:00
parent f04410c546
commit 563ff7266a
10 changed files with 158 additions and 58 deletions

View File

@@ -65,9 +65,19 @@ func (c *ClosingSigned) Decode(r io.Reader, pver uint32) error {
//
// This is part of the lnwire.Message interface.
func (c *ClosingSigned) Encode(w *bytes.Buffer, pver uint32) error {
return WriteElements(
w, c.ChannelID, c.FeeSatoshis, c.Signature, c.ExtraData,
)
if err := WriteChannelID(w, c.ChannelID); err != nil {
return err
}
if err := WriteSatoshi(w, c.FeeSatoshis); err != nil {
return err
}
if err := WriteSig(w, c.Signature); err != nil {
return err
}
return WriteBytes(w, c.ExtraData)
}
// MsgType returns the integer uniquely identifying this message type on the