Beispiel #1
0
    {
        // We don't use baseline here to be more accurate
        $iCount = $iCount * pow(2, $this->config['difficulty'] - 16);
        $stmt = $this->mysqli->prepare("\n      SELECT MIN(b.id) AS id FROM\n      (\n        SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total\n        FROM {$this->table}, (SELECT @total := 0) AS a\n        WHERE our_result = 'Y'\n        AND id <= ? AND @total < ?\n        ORDER BY id DESC\n      ) AS b\n      WHERE total <= ?");
        if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && ($result = $stmt->get_result())) {
            return $result->fetch_object()->id;
        }
        return $this->sqlError();
    }
    /**
     * Fetch the lowest needed share ID from archive
     **/
    function getMinArchiveShareId($iCount)
    {
        // We don't use baseline here to be more accurate
        $iCount = $iCount * pow(2, $this->config['difficulty'] - 16);
        $stmt = $this->mysqli->prepare("\n      SELECT MIN(b.share_id) AS share_id FROM\n      (\n        SELECT share_id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total\n        FROM {$this->tableArchive}, (SELECT @total := 0) AS a\n        WHERE our_result = 'Y'\n        AND @total < ?\n        ORDER BY share_id DESC\n      ) AS b\n      WHERE total <= ?\n      ");
        if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && ($result = $stmt->get_result())) {
            return $result->fetch_object()->share_id;
        }
        return $this->sqlError();
    }
}
$share = new Share();
$share->setDebug($debug);
$share->setMysql($mysqli);
$share->setConfig($config);
$share->setUser($user);
$share->setBlock($block);
$share->setErrorCodes($aErrorCodes);