channeldb: refactor InvoiceRef.String() with all optional fields

This commit is contained in:
Conner Fromknecht 2021-03-24 19:48:41 -07:00
parent 174d577524
commit 7bed359296
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 12 additions and 4 deletions

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"strings"
"time" "time"
"github.com/lightningnetwork/lnd/channeldb/kvdb" "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. // String returns a human-readable representation of an InvoiceRef.
func (r InvoiceRef) String() string { func (r InvoiceRef) String() string {
if r.payAddr != nil { var ids []string
return fmt.Sprintf("(pay_hash=%v, pay_addr=%x)", r.payHash, *r.payAddr) 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. // ContractState describes the state the invoice is in.

@ -47,7 +47,7 @@ func (i invoiceUpdateCtx) setID() *[32]byte {
// log logs a message specific to this update context. // log logs a message specific to this update context.
func (i *invoiceUpdateCtx) log(s string) { func (i *invoiceUpdateCtx) log(s string) {
log.Debugf("Invoice%v: %v, amt=%v, expiry=%v, circuit=%v, mpp=%v, "+ 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) i.mpp, i.amp)
} }