From 2fd4eb62fda49e1f6d43772b6276ca80bb1bfbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Wed, 14 Aug 2024 15:04:20 -0400 Subject: [PATCH] chore: print WakuMessageHash as hex strings (#2969) --- waku/waku_core/message/digest.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/waku/waku_core/message/digest.nim b/waku/waku_core/message/digest.nim index 1d4d122816..cb4f5b0141 100644 --- a/waku/waku_core/message/digest.nim +++ b/waku/waku_core/message/digest.nim @@ -8,6 +8,17 @@ import ../topics, ./message type WakuMessageHash* = array[32, byte] +func shortLog*(hash: WakuMessageHash): string = + ## Returns compact string representation of ``WakuMessageHash``. + var hexhash = newStringOfCap(13) + hexhash &= hash.toOpenArray(0, 1).to0xHex() + hexhash &= "..." + hexhash &= hash.toOpenArray(hash.len - 2, hash.high).toHex() + hexhash + +func `$`*(hash: WakuMessageHash): string = + shortLog(hash) + const EmptyWakuMessageHash*: WakuMessageHash = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,