From 9f8fa3d8ed92e823fcb244b902944b1322772fc2 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Thu, 12 Jan 2023 17:50:18 +0100 Subject: [PATCH] lncli: more descriptive htlc failure case This commit clarifies the htlc failure case in the lncli payment command, by using the cardinal number as well as 'hop' in the failure message. [skip ci] --- cmd/lncli/cmd_payments.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/lncli/cmd_payments.go b/cmd/lncli/cmd_payments.go index cb6b88b55..923f65b4c 100644 --- a/cmd/lncli/cmd_payments.go +++ b/cmd/lncli/cmd_payments.go @@ -762,9 +762,9 @@ func formatPayment(ctxc context.Context, payment *lnrpc.Payment, state := htlc.Status.String() if htlc.Failure != nil { state = fmt.Sprintf( - "%v @ %v", + "%v @ %s hop", htlc.Failure.Code, - htlc.Failure.FailureSourceIndex, + ordinalNumber(htlc.Failure.FailureSourceIndex), ) } @@ -1650,3 +1650,17 @@ var clearCode = fmt.Sprintf("%c[%dA%c[2K", ESC, 1, ESC) func clearLines(count int) { _, _ = fmt.Print(strings.Repeat(clearCode, count)) } + +// ordinalNumber returns the ordinal number as a string of a number. +func ordinalNumber(num uint32) string { + switch num { + case 1: + return "1st" + case 2: + return "2nd" + case 3: + return "3rd" + default: + return fmt.Sprintf("%dth", num) + } +}