htlcswitch/hop: move NetworkHop to hop.Network

This commit is contained in:
Conner Fromknecht 2019-08-30 14:05:53 -07:00
parent 866867a4b0
commit 83d2112e8b
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
5 changed files with 37 additions and 33 deletions

28
htlcswitch/hop/network.go Normal file
View File

@ -0,0 +1,28 @@
package hop
// Network indicates the blockchain network that is intended to be the next hop
// for a forwarded HTLC. The existence of this field within the ForwardingInfo
// struct enables the ability for HTLC to cross chain-boundaries at will.
type Network uint8
const (
// BitcoinNetwork denotes that an HTLC is to be forwarded along the
// Bitcoin link with the specified short channel ID.
BitcoinNetwork Network = iota
// LitecoinNetwork denotes that an HTLC is to be forwarded along the
// Litecoin link with the specified short channel ID.
LitecoinNetwork
)
// String returns the string representation of the target Network.
func (c Network) String() string {
switch c {
case BitcoinNetwork:
return "Bitcoin"
case LitecoinNetwork:
return "Litecoin"
default:
return "Kekcoin"
}
}

View File

@ -8,39 +8,12 @@ import (
"github.com/btcsuite/btcd/btcec"
"github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/tlv"
)
// NetworkHop indicates the blockchain network that is intended to be the next
// hop for a forwarded HTLC. The existence of this field within the
// ForwardingInfo struct enables the ability for HTLC to cross chain-boundaries
// at will.
type NetworkHop uint8
const (
// BitcoinHop denotes that an HTLC is to be forwarded along the Bitcoin
// link with the specified short channel ID.
BitcoinHop NetworkHop = iota
// LitecoinHop denotes that an HTLC is to be forwarded along the
// Litecoin link with the specified short channel ID.
LitecoinHop
)
// String returns the string representation of the target NetworkHop.
func (c NetworkHop) String() string {
switch c {
case BitcoinHop:
return "Bitcoin"
case LitecoinHop:
return "Litecoin"
default:
return "Kekcoin"
}
}
var (
// exitHop is a special "hop" which denotes that an incoming HTLC is
// meant to pay finally to the receiving node.
@ -59,7 +32,7 @@ var (
type ForwardingInfo struct {
// Network is the target blockchain network that the HTLC will travel
// over next.
Network NetworkHop
Network hop.Network
// NextHop is the channel ID of the next hop. The received HTLC should
// be forwarded to this particular channel in order to continue the
@ -199,7 +172,7 @@ func (r *sphinxHopIterator) ForwardingInstructions() (ForwardingInfo, error) {
}
return ForwardingInfo{
Network: BitcoinHop,
Network: hop.BitcoinNetwork,
NextHop: nextHop,
AmountToForward: lnwire.MilliSatoshi(amt),
OutgoingCTLV: cltv,

View File

@ -26,6 +26,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lntypes"
@ -4309,7 +4310,7 @@ func generateHtlcAndInvoice(t *testing.T,
htlcExpiry := testStartingHeight + testInvoiceCltvExpiry
hops := []ForwardingInfo{
{
Network: BitcoinHop,
Network: hop.BitcoinNetwork,
NextHop: exitHop,
AmountToForward: htlcAmt,
OutgoingCTLV: uint32(htlcExpiry),

View File

@ -23,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lnpeer"
@ -485,7 +486,7 @@ func (f *ForwardingInfo) decode(r io.Reader) error {
if _, err := r.Read(net[:]); err != nil {
return err
}
f.Network = NetworkHop(net[0])
f.Network = hop.Network(net[0])
if err := binary.Read(r, binary.BigEndian, &f.NextHop); err != nil {
return err

View File

@ -25,6 +25,7 @@ import (
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnpeer"
@ -680,7 +681,7 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
}
hops[i] = ForwardingInfo{
Network: BitcoinHop,
Network: hop.BitcoinNetwork,
NextHop: nextHop,
AmountToForward: amount,
OutgoingCTLV: timeLock,