lnwire: use color.RGBA instead of custom type in NodeAnnouncment

This commit is contained in:
Olaoluwa Osuntokun 2017-12-02 18:23:05 -08:00
parent 724adb158c
commit 4b6ada98d6
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 14 additions and 19 deletions

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"image/color"
"io" "io"
"math" "math"
@ -355,8 +356,8 @@ func writeElement(w io.Writer, element interface{}) error {
return err return err
} }
} }
case RGB: case color.RGBA:
if err := writeElements(w, e.red, e.green, e.blue); err != nil { if err := writeElements(w, e.R, e.G, e.B); err != nil {
return err return err
} }
@ -689,11 +690,11 @@ func readElement(r io.Reader, element interface{}) error {
} }
*e = addresses *e = addresses
case *RGB: case *color.RGBA:
err := readElements(r, err := readElements(r,
&e.red, &e.R,
&e.green, &e.G,
&e.blue, &e.B,
) )
if err != nil { if err != nil {
return err return err

@ -3,6 +3,7 @@ package lnwire
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"image/color"
"math" "math"
"math/big" "math/big"
"math/rand" "math/rand"
@ -404,10 +405,10 @@ func TestLightningWireProtocol(t *testing.T) {
Features: randRawFeatureVector(r), Features: randRawFeatureVector(r),
Timestamp: uint32(r.Int31()), Timestamp: uint32(r.Int31()),
Alias: a, Alias: a,
RGBColor: RGB{ RGBColor: color.RGBA{
red: uint8(r.Int31()), R: uint8(r.Int31()),
green: uint8(r.Int31()), G: uint8(r.Int31()),
blue: uint8(r.Int31()), B: uint8(r.Int31()),
}, },
// TODO(roasbeef): proper gen rand addrs // TODO(roasbeef): proper gen rand addrs
Addresses: testAddrs, Addresses: testAddrs,

@ -3,6 +3,7 @@ package lnwire
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"image/color"
"io" "io"
"net" "net"
"unicode/utf8" "unicode/utf8"
@ -15,14 +16,6 @@ var (
endPort uint16 = 49151 endPort uint16 = 49151
) )
// RGB is used to represent the "color" of a particular node encoded as a 24
// bit value.
type RGB struct {
red uint8
green uint8
blue uint8
}
// NodeAlias a hex encoded UTF-8 string that may be displayed as an alternative // NodeAlias a hex encoded UTF-8 string that may be displayed as an alternative
// to the node's ID. Notice that aliases are not unique and may be freely // to the node's ID. Notice that aliases are not unique and may be freely
// chosen by the node operators. // chosen by the node operators.
@ -69,7 +62,7 @@ type NodeAnnouncement struct {
// RGBColor is used to customize their node's appearance in maps and // RGBColor is used to customize their node's appearance in maps and
// graphs // graphs
RGBColor RGB RGBColor color.RGBA
// Alias is used to customize their node's appearance in maps and // Alias is used to customize their node's appearance in maps and
// graphs // graphs