mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 17:51:33 +02:00
lnutil: add LogPubKey helper function
This captures a common pattern where we want to log a peer's public key along side each logging statement.
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package lnutils
|
package lnutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/btcsuite/btclog/v2"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,3 +39,14 @@ func NewSeparatorClosure() LogClosure {
|
|||||||
return strings.Repeat("=", 80)
|
return strings.Repeat("=", 80)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogPubKey returns a slog attribute for logging a public key in hex format.
|
||||||
|
func LogPubKey(key string, pubKey *btcec.PublicKey) slog.Attr {
|
||||||
|
// Handle nil pubkey gracefully, although callers should ideally prevent
|
||||||
|
// this.
|
||||||
|
if pubKey == nil {
|
||||||
|
return btclog.Fmt(key, "<nil>")
|
||||||
|
}
|
||||||
|
|
||||||
|
return btclog.Hex6(key, pubKey.SerializeCompressed())
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user