2017-05-01 17:46:53 +03:00
|
|
|
package htlcswitch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/hex"
|
|
|
|
|
|
|
|
"github.com/btcsuite/golangcrypto/ripemd160"
|
|
|
|
"github.com/roasbeef/btcutil"
|
|
|
|
)
|
|
|
|
|
2017-05-01 19:58:08 +03:00
|
|
|
// HopID represents the id which is used by propagation subsystem in order to
|
2017-05-01 17:46:53 +03:00
|
|
|
// identify lightning network node.
|
|
|
|
// TODO(andrew.shvv) remove after switching to the using channel id.
|
2017-05-01 19:58:08 +03:00
|
|
|
type HopID [ripemd160.Size]byte
|
2017-05-01 17:46:53 +03:00
|
|
|
|
2017-05-01 19:58:08 +03:00
|
|
|
// 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
|
2017-05-01 17:46:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// String returns string representation of hop id.
|
2017-05-01 19:58:08 +03:00
|
|
|
func (h HopID) String() string {
|
2017-05-01 17:46:53 +03:00
|
|
|
return hex.EncodeToString(h[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsEqual checks does the two hop ids are equal.
|
2017-05-01 19:58:08 +03:00
|
|
|
func (h HopID) IsEqual(h2 HopID) bool {
|
2017-05-01 17:46:53 +03:00
|
|
|
return bytes.Equal(h[:], h2[:])
|
|
|
|
}
|