From 3db48dc53f989324eac8c01f31b76caceda42ec5 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 25 Jan 2019 10:44:21 +0100 Subject: [PATCH] routing: Route String() method --- routing/route/route.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/routing/route/route.go b/routing/route/route.go index 2cd04684..ad639b53 100644 --- a/routing/route/route.go +++ b/routing/route/route.go @@ -3,6 +3,8 @@ package route import ( "encoding/binary" "fmt" + "strconv" + "strings" "github.com/btcsuite/btcd/btcec" sphinx "github.com/lightningnetwork/lightning-onion" @@ -180,3 +182,20 @@ func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) { 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(), + ) +}