route: return 0 fee from TotalFees for empty route.

Otherwise we would crash calling the method on empty routes.
This commit is contained in:
Johan T. Halseth 2019-05-28 11:03:14 +02:00
parent 28fdf9712d
commit f829d33d6f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -103,6 +103,10 @@ func (r *Route) HopFee(hopIndex int) lnwire.MilliSatoshi {
// the case of a one-hop payment, this value will be zero as we don't need to
// pay a fee to ourself.
func (r *Route) TotalFees() lnwire.MilliSatoshi {
if len(r.Hops) == 0 {
return 0
}
return r.TotalAmount - r.Hops[len(r.Hops)-1].AmtToForward
}