From ad3cfdbec50c846efa7cd4b7ba333791077d8e16 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 18 Dec 2024 10:19:09 +0100 Subject: [PATCH] convert transaction to string --- codexvalidator/blocks.nim | 2 ++ codexvalidator/blocks/blck.nim | 3 ++- codexvalidator/blocks/hashing.nim | 6 ++++++ codexvalidator/hashing.nim | 2 ++ codexvalidator/transaction/transaction.nim | 9 +++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/codexvalidator/blocks.nim b/codexvalidator/blocks.nim index bed76b4..32b7c05 100644 --- a/codexvalidator/blocks.nim +++ b/codexvalidator/blocks.nim @@ -12,3 +12,5 @@ import ./blocks/hashing export hashing.hash export hashing.id +export hashing.`==` +export hashing.`$` diff --git a/codexvalidator/blocks/blck.nim b/codexvalidator/blocks/blck.nim index 4efb5a4..c457e5f 100644 --- a/codexvalidator/blocks/blck.nim +++ b/codexvalidator/blocks/blck.nim @@ -1,4 +1,4 @@ -from pkg/mysticeti import CommitteeMember, `==` +from pkg/mysticeti import CommitteeMember, `==`, `$` import ../basics import ../transaction import ../hashing @@ -6,6 +6,7 @@ import ./blockid export mysticeti.CommitteeMember export mysticeti.`==` +export mysticeti.`$` type Block* = ref object author*: CommitteeMember diff --git a/codexvalidator/blocks/hashing.nim b/codexvalidator/blocks/hashing.nim index fe3d0b4..89c66df 100644 --- a/codexvalidator/blocks/hashing.nim +++ b/codexvalidator/blocks/hashing.nim @@ -16,3 +16,9 @@ func id*(b: Block): BlockId = b.round, hash(b) ) + +func `==`*(a, b: Block): bool = + a.hash == b.hash + +func `$`*(b: Block): string = + $b.id diff --git a/codexvalidator/hashing.nim b/codexvalidator/hashing.nim index 500accf..007080a 100644 --- a/codexvalidator/hashing.nim +++ b/codexvalidator/hashing.nim @@ -1,6 +1,8 @@ import pkg/nimcrypto/sha2 import pkg/nimcrypto/hash +export hash.`$` + type Hash* = MDigest[256] func hash*(_: type Hash, bytes: openArray[byte]): Hash = diff --git a/codexvalidator/transaction/transaction.nim b/codexvalidator/transaction/transaction.nim index 5b63c42..88628ed 100644 --- a/codexvalidator/transaction/transaction.nim +++ b/codexvalidator/transaction/transaction.nim @@ -73,3 +73,12 @@ func `==`*(a, b: Transaction): bool = a.proof == b.proof of TransactionKind.missingProof: true + +func `$`*(transaction: Transaction): string = + result &= "Transaction(" + result &= "version: " & $transaction.version + result &= ", kind: " & $transaction.kind + result &= ", proofInput: " & $transaction.proofInput + if transaction.kind == TransactionKind.storageProof: + result &= ", proof: " & $transaction.proof + result &= ")"