From 4b6ada98d6404a27f85a360e743bbea66cfb9c0e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 2 Dec 2017 18:23:05 -0800 Subject: [PATCH] lnwire: use color.RGBA instead of custom type in NodeAnnouncment --- lnwire/lnwire.go | 13 +++++++------ lnwire/lnwire_test.go | 9 +++++---- lnwire/node_announcement.go | 11 ++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index ce9ead46..92e693c4 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "fmt" + "image/color" "io" "math" @@ -355,8 +356,8 @@ func writeElement(w io.Writer, element interface{}) error { return err } } - case RGB: - if err := writeElements(w, e.red, e.green, e.blue); err != nil { + case color.RGBA: + if err := writeElements(w, e.R, e.G, e.B); err != nil { return err } @@ -689,11 +690,11 @@ func readElement(r io.Reader, element interface{}) error { } *e = addresses - case *RGB: + case *color.RGBA: err := readElements(r, - &e.red, - &e.green, - &e.blue, + &e.R, + &e.G, + &e.B, ) if err != nil { return err diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index f78e2c4d..f94176f4 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -3,6 +3,7 @@ package lnwire import ( "bytes" "encoding/hex" + "image/color" "math" "math/big" "math/rand" @@ -404,10 +405,10 @@ func TestLightningWireProtocol(t *testing.T) { Features: randRawFeatureVector(r), Timestamp: uint32(r.Int31()), Alias: a, - RGBColor: RGB{ - red: uint8(r.Int31()), - green: uint8(r.Int31()), - blue: uint8(r.Int31()), + RGBColor: color.RGBA{ + R: uint8(r.Int31()), + G: uint8(r.Int31()), + B: uint8(r.Int31()), }, // TODO(roasbeef): proper gen rand addrs Addresses: testAddrs, diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index 7cc13972..9e9ce0cf 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -3,6 +3,7 @@ package lnwire import ( "bytes" "fmt" + "image/color" "io" "net" "unicode/utf8" @@ -15,14 +16,6 @@ var ( 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 // to the node's ID. Notice that aliases are not unique and may be freely // chosen by the node operators. @@ -69,7 +62,7 @@ type NodeAnnouncement struct { // RGBColor is used to customize their node's appearance in maps and // graphs - RGBColor RGB + RGBColor color.RGBA // Alias is used to customize their node's appearance in maps and // graphs