mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-19 05:33:36 +01:00
chainhash: JSON marshal hash as string
This commit is contained in:
parent
52b6eb46f1
commit
1d6e578c21
@ -8,6 +8,7 @@ package chainhash
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,6 +111,11 @@ func (hash *Hash) IsEqual(target *Hash) bool {
|
|||||||
return *hash == *target
|
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
|
// NewHash returns a new Hash from a byte slice. An error is returned if
|
||||||
// the number of bytes passed in is not HashSize.
|
// the number of bytes passed in is not HashSize.
|
||||||
func NewHash(newHash []byte) (*Hash, error) {
|
func NewHash(newHash []byte) (*Hash, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user