routing: Route String() method

This commit is contained in:
Joost Jager 2019-01-25 10:44:21 +01:00
parent 35003bd87c
commit 3db48dc53f
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -3,6 +3,8 @@ package route
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"strconv"
"strings"
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
@ -180,3 +182,20 @@ func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) {
return &path, nil return &path, nil
} }
// String returns a human readable representation of the route.
func (r *Route) String() string {
var b strings.Builder
for i, hop := range r.Hops {
if i > 0 {
b.WriteString(",")
}
b.WriteString(strconv.FormatUint(hop.ChannelID, 10))
}
return fmt.Sprintf("amt=%v, fees=%v, tl=%v, chans=%v",
r.TotalAmount-r.TotalFees(), r.TotalFees(), r.TotalTimeLock,
b.String(),
)
}