lnd.xprv/htlcswitch/iterator.go
Andrey Samokhvalov b86409cdb3 htlcswitch: recreate hlcswitch from scratch
This commit gives the start for making the htlc manager and htlc switch
testable. The testability of htlc switch have been achieved by mocking
all external subsystems. The concrete list of updates:

1. create standalone package for htlc switch.
2. add "ChannelLink" interface, which represent the previous htlc link.
3. add "Peer" interface, which represent the remote node inside our
subsystem.
4. add htlc switch config to htlc switch susbystem, which stores the
handlers which are not elongs to any of the above interfaces.

With this commit we are able test htlc switch even without having
the concrete implementation of Peer, ChannelLink structures, they will
be added later.
2017-05-31 11:06:08 -07:00

32 lines
776 B
Go

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[:])
}