From eb16a10c2eda0ff65a92fd85fbc8a973b13f5979 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Fri, 25 Aug 2023 07:40:20 -0400 Subject: [PATCH] Implement MarshalBinary and UnmarshalBinary for MerkleTreeHash --- merkletree/hash.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/merkletree/hash.go b/merkletree/hash.go index d200b40..4ddf9a2 100644 --- a/merkletree/hash.go +++ b/merkletree/hash.go @@ -28,11 +28,19 @@ func (h Hash) MarshalJSON() ([]byte, error) { return json.Marshal(h[:]) } +func (h Hash) MarshalBinary() ([]byte, error) { + return h[:], nil +} + func (h *Hash) UnmarshalJSON(b []byte) error { var hashBytes []byte if err := json.Unmarshal(b, &hashBytes); err != nil { return err } + return h.UnmarshalBinary(hashBytes) +} + +func (h *Hash) UnmarshalBinary(hashBytes []byte) error { if len(hashBytes) != HashLen { return fmt.Errorf("Merkle Tree hash has wrong length (should be %d bytes long, not %d)", HashLen, len(hashBytes)) }