convert transaction to string

This commit is contained in:
Mark Spanbroek 2024-12-18 10:19:09 +01:00
parent 0fff583d58
commit ad3cfdbec5
5 changed files with 21 additions and 1 deletions

View File

@ -12,3 +12,5 @@ import ./blocks/hashing
export hashing.hash
export hashing.id
export hashing.`==`
export hashing.`$`

View File

@ -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

View File

@ -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

View File

@ -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 =

View File

@ -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 &= ")"