chainhash: JSON marshal hash as string

This commit is contained in:
ffranr 2022-12-02 19:30:41 +00:00
parent 52b6eb46f1
commit 1d6e578c21
No known key found for this signature in database
GPG Key ID: B1F8848557AA29D2

View File

@ -8,6 +8,7 @@ package chainhash
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
)
@ -110,6 +111,11 @@ func (hash *Hash) IsEqual(target *Hash) bool {
return *hash == *target
}
// MarshalJSON serialises the hash as a JSON appropriate string value.
func (hash Hash) MarshalJSON() ([]byte, error) {
return json.Marshal(hash.String())
}
// NewHash returns a new Hash from a byte slice. An error is returned if
// the number of bytes passed in is not HashSize.
func NewHash(newHash []byte) (*Hash, error) {