From 07afcad6ded2189f046c251d068c1c6cd7f9393f Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Mon, 1 May 2017 17:46:53 +0300 Subject: [PATCH] htlcswitch: add hop id Add hop id structure wich represent the next lnd node in sphinx payment route. This structure will be removed when we switch to use the channel id as the pointers to the htlc update. --- htlcswitch/iterator.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 htlcswitch/iterator.go diff --git a/htlcswitch/iterator.go b/htlcswitch/iterator.go new file mode 100644 index 00000000..0a9152ed --- /dev/null +++ b/htlcswitch/iterator.go @@ -0,0 +1,31 @@ +package htlcswitch + +import ( + "bytes" + "encoding/hex" + + "github.com/btcsuite/golangcrypto/ripemd160" + "github.com/roasbeef/btcutil" +) + +// hopID represents the id which is used by propagation subsystem in order to +// identify lightning network node. +// TODO(andrew.shvv) remove after switching to the using channel id. +type hopID [ripemd160.Size]byte + +// newHopID creates new instance of hop form node public key. +func newHopID(pubKey []byte) hopID { + var routeId hopID + copy(routeId[:], btcutil.Hash160(pubKey)) + return routeId +} + +// String returns string representation of hop id. +func (h hopID) String() string { + return hex.EncodeToString(h[:]) +} + +// IsEqual checks does the two hop ids are equal. +func (h hopID) IsEqual(h2 hopID) bool { + return bytes.Equal(h[:], h2[:]) +}