Merge pull request #1932 from ffranr/chainhash_json

chainhash: JSON marshal hash as string
This commit is contained in:
Oliver Gugger 2022-12-05 15:09:06 +01:00 committed by GitHub
commit 718d268a8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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) {