MCPcopy Create free account
hub / github.com/chain/txvm / UnmarshalJSON

Method UnmarshalJSON

protocol/bc/hash.go:71–82  ·  view source on GitHub ↗

UnmarshalJSON satisfies the json.Unmarshaler interface. If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it decodes hex data from b into h.

(b []byte)

Source from the content-addressed store, hash-verified

69// If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it
70// decodes hex data from b into h.
71func (h *Hash) UnmarshalJSON(b []byte) error {
72 if bytes.Equal(b, []byte("null")) {
73 *h = Hash{}
74 return nil
75 }
76 var s string
77 err := json.Unmarshal(b, &s)
78 if err != nil {
79 return err
80 }
81 return h.UnmarshalText([]byte(s))
82}
83
84// Bytes returns the hash as a byte slice.
85func (h Hash) Bytes() []byte {

Callers 1

TestHashUnmarshalJSONFunction · 0.95

Calls 2

UnmarshalTextMethod · 0.95
EqualMethod · 0.80

Tested by 1

TestHashUnmarshalJSONFunction · 0.76