Skip to content

Commit c3f8db7

Browse files
committed
payload: change signature Decode
To provide backwards compatibility, the Decode function in sphinx.go has been modified to accept an optional isMessage parameter. This is now not a breaking change.
1 parent bfdbdec commit c3f8db7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

payload.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ func (hp *HopPayload) Encode(w io.Writer) error {
8989
// Decode unpacks an encoded HopPayload from the passed reader into the target
9090
// HopPayload. The isMessage boolean should be set to true if we're parsing a
9191
// payload that is known to be for an onion message.
92-
func (hp *HopPayload) Decode(r io.Reader, isMessage bool) error {
92+
func (hp *HopPayload) Decode(r io.Reader, isMessage ...bool) error {
93+
// To preserve backwards compatibility, we'll default to isMessage being
94+
// false if it is not provided.
95+
isMsg := len(isMessage) > 0 && isMessage[0]
96+
9397
bufReader := bufio.NewReader(r)
9498

9599
// In order to properly parse the payload, we'll need to check the
@@ -101,7 +105,7 @@ func (hp *HopPayload) Decode(r io.Reader, isMessage bool) error {
101105
}
102106

103107
// Per BOLT 7, onion messages MUST use the TLV format.
104-
if isMessage {
108+
if isMsg {
105109
return decodeTLVHopPayload(hp, bufReader)
106110
}
107111

0 commit comments

Comments
 (0)