From 7bed359296a9207091ad201081761130b6ddea1b Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 24 Mar 2021 19:48:41 -0700 Subject: [PATCH] channeldb: refactor InvoiceRef.String() with all optional fields --- channeldb/invoices.go | 14 +++++++++++--- invoices/update.go | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 613960bf..5a607ce9 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "strings" "time" "github.com/lightningnetwork/lnd/channeldb/kvdb" @@ -295,10 +296,17 @@ func (r InvoiceRef) SetID() *[32]byte { // String returns a human-readable representation of an InvoiceRef. func (r InvoiceRef) String() string { - if r.payAddr != nil { - return fmt.Sprintf("(pay_hash=%v, pay_addr=%x)", r.payHash, *r.payAddr) + var ids []string + if r.payHash != nil { + ids = append(ids, fmt.Sprintf("pay_hash=%v", *r.payHash)) } - return fmt.Sprintf("(pay_hash=%v)", r.payHash) + if r.payAddr != nil { + ids = append(ids, fmt.Sprintf("pay_addr=%x", *r.payAddr)) + } + if r.setID != nil { + ids = append(ids, fmt.Sprintf("set_id=%x", *r.setID)) + } + return fmt.Sprintf("(%s)", strings.Join(ids, ", ")) } // ContractState describes the state the invoice is in. diff --git a/invoices/update.go b/invoices/update.go index 45435ca8..c6569143 100644 --- a/invoices/update.go +++ b/invoices/update.go @@ -47,7 +47,7 @@ func (i invoiceUpdateCtx) setID() *[32]byte { // log logs a message specific to this update context. func (i *invoiceUpdateCtx) log(s string) { log.Debugf("Invoice%v: %v, amt=%v, expiry=%v, circuit=%v, mpp=%v, "+ - "amp=%v", i.hash[:], s, i.amtPaid, i.expiry, i.circuitKey, + "amp=%v", i.invoiceRef(), s, i.amtPaid, i.expiry, i.circuitKey, i.mpp, i.amp) }