func (pow *ProofOfWork) workOnCore(ctx context.Context, start, step uint64, found chan uint64) {
	var hashInt big.Int

	// Hash must be less than this
	target := big.NewInt(1)
	target = target.Lsh(target, uint(256-pow.Bits))

	var counter uint64 = start
	for counter < math.MaxInt64 {
		select {
		case <-ctx.Done():
			// Break when context is cancelled (other go thread has found our proof)
			return
		default:
			// 1st round of SHA256
			hash := sha256.Sum256(bytes.Join([][]byte{
				[]byte(pow.Data),
				intToHex(counter),
			}, []byte{}))

			// 2nd round of SHA256
			hash = sha256.Sum256(hash[:])
			hashInt.SetBytes(hash[:])

			// Is it less than our target, then we have done our work
			if hashInt.Cmp(target) == -1 {
				found <- counter
				return
			}
		}

		counter += step
	}
}
// workOnCore does hashing on a core, starting at start and increasing with step each time until
// the context is cancelled (completed), or we found the proof, in which case we send it to the
// channel.
workOnCore does hashing on a core, starting at start and increasing with step each time until
the context is cancelled (completed), or we found the proof, in which case we send it to the
channel.
// workOnCore does hashing on a core starting at start and increasing with step each time until // the context is cancelled ( completed ) or we found the proof in which case we send it to the // channel .
func (pow *ProofOfWork) workOnCore(ctx context.Context, start, step uint64, found chan uint64) {
	var hashInt big.Int
	target := big.NewInt(1)
	target = target.Lsh(target, uint(256-pow.Bits))
	var counter uint64 = start
	for counter < math.MaxInt64 {
		select {
		case <-ctx.Done():
			return
		default:
			hash := sha256.Sum256(bytes.Join([][]byte{
				[]byte(pow.Data),
				intToHex(counter),
			}, []byte{}))
			hash = sha256.Sum256(hash[:])
			hashInt.SetBytes(hash[:])
			if hashInt.Cmp(target) == -1 {
				found <- counter
				return
			}
		}
		counter += step
	}
}
func ( pow * ProofOfWork ) workOnCore ( ctx context . Context , start , step uint64 , found chan uint64 ) { var hashInt big . Int target := big . NewInt ( 1 ) target = target . Lsh ( target , uint ( 256 - pow . Bits ) ) var counter uint64 = start for counter < math . MaxInt64 { select { case <- ctx . Done ( ) : return default : hash := sha256 . Sum256 ( bytes . Join ( [ ] [ ] byte { [ ] byte ( pow . Data ) , intToHex ( counter ) , } , [ ] byte { } ) ) hash = sha256 . Sum256 ( hash [ : ] ) hashInt . SetBytes ( hash [ : ] ) if hashInt . Cmp ( target ) == - 1 { found <- counter return } } counter += step } }
workOnCore does hashing on a core, starting at start and increasing with step each time until
the context is cancelled (completed), or we found the proof, in which case we send it to the
channel.
workOnCore does hashing on a core starting at start and increasing with step each time until the context is cancelled ( completed ) or we found the proof in which case we send it to the channel .
// Hash must be less than this // Break when context is cancelled (other go thread has found our proof) // 1st round of SHA256 // 2nd round of SHA256 // Is it less than our target, then we have done our work