Skip to content

Commit

Permalink
chainhash: JSON marshal hash as string
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Dec 2, 2022
1 parent 52b6eb4 commit 1d6e578
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 1d6e578

Please sign in to comment.