src/mining/mine.js
function mine(data, target, min, max) {
  let nonce = min;

  data.writeUInt32LE(nonce, 76, true);

  // The heart and soul of the miner: match the target.
  while (nonce <= max) {
    // Hash and test against the next target.
    // if (rcmp(digest.hash256(data), target) <= 0) // cfc
    // if (rcmp(powHash(data), target) <= 0) // ctl
    if (rcmp(calHash(data), target) <= 0)
      return nonce;

    // Increment the nonce to get a different hash.
    nonce++;

    // Update the raw buffer.
    data.writeUInt32LE(nonce, 76, true);
  }

  return -1;
}
function mine(data, target, min, max) {
  let nonce = min;

  data.writeUInt32LE(nonce, 76, true);

  // The heart and soul of the miner: match the target.
  while (nonce <= max) {
    // Hash and test against the next target.
    // if (rcmp(digest.hash256(data), target) <= 0) // cfc
    // if (rcmp(powHash(data), target) <= 0) // ctl
    if (rcmp(calHash(data), target) <= 0)
      return nonce;

    // Increment the nonce to get a different hash.
    nonce++;

    // Update the raw buffer.
    data.writeUInt32LE(nonce, 76, true);
  }

  return -1;
}
function mine ( data , target , min , max ) { let nonce = min ; data . writeUInt32LE ( nonce , 76 , true ) ; // The heart and soul of the miner: match the target. while ( nonce <= max ) { // Hash and test against the next target. // if (rcmp(digest.hash256(data), target) <= 0) // cfc // if (rcmp(powHash(data), target) <= 0) // ctl if ( rcmp ( calHash ( data ) , target ) <= 0 ) return nonce ; // Increment the nonce to get a different hash. nonce ++ ; // Update the raw buffer. data . writeUInt32LE ( nonce , 76 , true ) ; } return - 1 ; }
Hash until the nonce overflows.
@alias module:mining.mine
@param {Buffer} data
@param {Buffer} target - Big endian.
@param {Number} min
@param {Number} max
@returns {Number} Nonce or -1.
Hash until the nonce overflows .