mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
chainhash: JSON marshal hash as string
This commit is contained in:
parent
52b6eb46f1
commit
1d6e578c21
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user