lnwire: modify Alias to only track the non-zero portion of wire msg
This commit modifies the Alias type to only hold the non-zero portion of the alias as encoded on the wire. Previously the entire 32-bytes would be read and stored, including the zeroes at the end used as padding. Within the constructor, we now parse the alias properly, discarding the trailing zeroes within the passed byte slice. Additionally, the .String() method of Alias will now also only print the non-zero prefix of the decoded alias.
This commit is contained in:
2 files changed
+34
-18
No files matched your search
+7
-3
@@ -6,12 +6,13 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"net"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/txscript"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
"net"
|
||||
)
|
||||
|
||||
// MaxSliceLength is the maximum allowed lenth for any opaque byte slices in
|
||||
@@ -379,7 +380,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
case Alias:
|
||||
if err := writeElements(w, ([32]byte)(e)); err != nil {
|
||||
if err := writeElements(w, ([32]byte)(e.data)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -720,8 +721,11 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
if err := readElements(r, &a); err != nil {
|
||||
return err
|
||||
}
|
||||
*e = (Alias)(a)
|
||||
|
||||
*e, err = newAlias(a[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Unknown type in readElement: %T", e)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user