Difficulty returns the leading Zero **bit** count of Hash in binary. return -1 indicate the Hash pointer is nil.
()
| 116 | // Difficulty returns the leading Zero **bit** count of Hash in binary. |
| 117 | // return -1 indicate the Hash pointer is nil. |
| 118 | func (h *Hash) Difficulty() (difficulty int) { |
| 119 | if h == nil { |
| 120 | return -1 |
| 121 | } |
| 122 | |
| 123 | for i := range *h { |
| 124 | v := (*h)[HashSize-i-1] |
| 125 | if v != byte(0) { |
| 126 | difficulty = 8 * i |
| 127 | difficulty += bits.LeadingZeros8(v) |
| 128 | return |
| 129 | } |
| 130 | } |
| 131 | return HashSize * 8 |
| 132 | } |
| 133 | |
| 134 | // MarshalJSON implements the json.Marshaler interface. |
| 135 | func (h Hash) MarshalJSON() ([]byte, error) { |
no outgoing calls