func (d *Device) updateCurrentWork() { var w *Work if d.hasWork { // If we already have work, we just need to check if there's new one // without blocking if there's not. select { case w = <-d.newWork: default: return } } else { // If we don't have work, we block until we do. We need to watch for // quit events too. select { case w = <-d.newWork: case <-d.quit: return } } d.hasWork = true d.work = *w // Set nonce2 binary.BigEndian.PutUint32(d.work.Data[128+4*nonce2Word:], uint32(d.index)) // Reset the hash state copy(d.midstate[:], blake256.IV256[:]) // Hash the two first blocks blake256.Block(d.midstate[:], d.work.Data[0:64], 512) blake256.Block(d.midstate[:], d.work.Data[64:128], 1024) // Convert the next block to uint32 array. for i := 0; i < 16; i++ { d.lastBlock[i] = binary.BigEndian.Uint32(d.work.Data[128+i*4:]) } }
func (d *Device) foundCandidate(nonce1 uint32, nonce0 uint32) { // Construct the final block header data := make([]byte, 192) copy(data, d.work.Data[:]) binary.BigEndian.PutUint32(data[128+4*nonce1Word:], nonce1) binary.BigEndian.PutUint32(data[128+4*nonce0Word:], nonce0) // Perform the final hash block to get the hash var state [8]uint32 copy(state[:], d.midstate[:]) blake256.Block(state[:], data[128:192], 1440) var hash [32]byte for i := 0; i < 8; i++ { binary.BigEndian.PutUint32(hash[i*4:], state[i]) } if hashSmaller(hash[:], d.work.Target[:]) { minrLog.Infof("Found hash!! %s", hex.EncodeToString(hash[:])) d.workDone <- data } }