Code Duplication    Length = 7-7 lines in 5 locations

include/classes/share.class.php 5 locations

@@ 285-291 (lines=7) @@
282
283
    // Stratum supported blockhash solution entry
284
    $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM $this->table WHERE solution = ? LIMIT 1");
285
    if ($this->checkStmt($stmt) && $stmt->bind_param('s', $aBlock['hash']) && $stmt->execute() && $result = $stmt->get_result()) {
286
      $this->oUpstream = $result->fetch_object();
287
      $this->share_type = 'stratum_blockhash';
288
      if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
289
        return true;
290
    }
291
292
    // Stratum scrypt hash check
293
    $scrypt_hash = swapEndian(bin2hex(Scrypt::calc($header_bin, $header_bin, 1024, 1, 1, 32)));
294
    $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM $this->table WHERE solution = ? LIMIT 1");
@@ 295-301 (lines=7) @@
292
    // Stratum scrypt hash check
293
    $scrypt_hash = swapEndian(bin2hex(Scrypt::calc($header_bin, $header_bin, 1024, 1, 1, 32)));
294
    $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM $this->table WHERE solution = ? LIMIT 1");
295
    if ($this->checkStmt($stmt) && $stmt->bind_param('s', $scrypt_hash) && $stmt->execute() && $result = $stmt->get_result()) {
296
      $this->oUpstream = $result->fetch_object();
297
      $this->share_type = 'stratum_solution';
298
      if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
299
        return true;
300
    }
301
302
    // Failed to fetch via startum solution, try pushpoold
303
    // Fallback to pushpoold solution type
304
    $ppheader = sprintf('%08d', $aBlock['version']) . word_reverse($aBlock['previousblockhash']) . word_reverse($aBlock['merkleroot']) . dechex($aBlock['time']) . $aBlock['bits'] . dechex($aBlock['nonce']);
@@ 306-312 (lines=7) @@
303
    // Fallback to pushpoold solution type
304
    $ppheader = sprintf('%08d', $aBlock['version']) . word_reverse($aBlock['previousblockhash']) . word_reverse($aBlock['merkleroot']) . dechex($aBlock['time']) . $aBlock['bits'] . dechex($aBlock['nonce']);
305
    $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM $this->table WHERE solution LIKE CONCAT(?, '%') LIMIT 1");
306
    if ($this->checkStmt($stmt) && $stmt->bind_param('s', $ppheader) && $stmt->execute() && $result = $stmt->get_result()) {
307
      $this->oUpstream = $result->fetch_object();
308
      $this->share_type = 'pp_solution';
309
      if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
310
        return true;
311
    }
312
313
    // Still no match, try upstream result with timerange
314
    $stmt = $this->mysqli->prepare("
315
      SELECT
@@ 323-329 (lines=7) @@
320
      AND UNIX_TIMESTAMP(time) >= ?
321
      AND UNIX_TIMESTAMP(time) <= ( ? + 60 )
322
      ORDER BY id ASC LIMIT 1");
323
    if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $last, $aBlock['time'], $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) {
324
      $this->oUpstream = $result->fetch_object();
325
      $this->share_type = 'upstream_share';
326
      if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
327
        return true;
328
    }
329
330
    // We failed again, now we take ANY result matching the timestamp
331
    $stmt = $this->mysqli->prepare("
332
      SELECT
@@ 339-345 (lines=7) @@
336
      AND id > ?
337
      AND UNIX_TIMESTAMP(time) >= ?
338
      ORDER BY id ASC LIMIT 1");
339
    if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) {
340
      $this->oUpstream = $result->fetch_object();
341
      $this->share_type = 'any_share';
342
      if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
343
        return true;
344
    }
345
    $this->setErrorMessage($this->getErrorMsg('E0052', $aBlock['height']));
346
    return false;
347
  }
348