Skip to content

Commit

Permalink
Merge pull request #1932 from ffranr/chainhash_json
Browse files Browse the repository at this point in the history
chainhash: JSON marshal hash as string
  • Loading branch information
guggero authored Dec 5, 2022
2 parents 52b6eb4 + 1d6e578 commit 718d268
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chaincfg/chainhash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package chainhash
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
)

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 718d268

Please sign in to comment.