mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-12 10:30:49 +01:00
chainhash: JSON Unmarshal hash from appropriate string.
This commit is contained in:
parent
a18c2cfbf8
commit
72ea23ed1e
1 changed files with 15 additions and 0 deletions
|
@ -116,6 +116,21 @@ func (hash Hash) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(hash.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON parses the hash with JSON appropriate string value.
|
||||
func (hash *Hash) UnmarshalJSON(input []byte) error {
|
||||
var sh string
|
||||
err := json.Unmarshal(input, &sh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newHash, err := NewHashFromStr(sh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hash.SetBytes(newHash[:])
|
||||
}
|
||||
|
||||
// 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…
Add table
Reference in a new issue