| @@ 8-18 (lines=11) @@ | ||
| 5 | /** |
|
| 6 | * Get next block for round stats |
|
| 7 | **/ |
|
| 8 | public function getNextBlock($iHeight=0) { |
|
| 9 | $stmt = $this->mysqli->prepare(" |
|
| 10 | SELECT height |
|
| 11 | FROM " . $this->block->getTableName() . " |
|
| 12 | WHERE height > ? |
|
| 13 | ORDER BY height ASC |
|
| 14 | LIMIT 1"); |
|
| 15 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 16 | return $result->fetch_object()->height; |
|
| 17 | return $this->sqlError(); |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Get prev block for round stats |
|
| @@ 23-33 (lines=11) @@ | ||
| 20 | /** |
|
| 21 | * Get prev block for round stats |
|
| 22 | **/ |
|
| 23 | public function getPreviousBlock($iHeight=0) { |
|
| 24 | $stmt = $this->mysqli->prepare(" |
|
| 25 | SELECT height |
|
| 26 | FROM " . $this->block->getTableName() . " |
|
| 27 | WHERE height < ? |
|
| 28 | ORDER BY height DESC |
|
| 29 | LIMIT 1"); |
|
| 30 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 31 | return $result->fetch_object()->height; |
|
| 32 | return $this->sqlError(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * search for block height |
|
| @@ 38-48 (lines=11) @@ | ||
| 35 | /** |
|
| 36 | * search for block height |
|
| 37 | **/ |
|
| 38 | public function searchForBlockHeight($iHeight=0) { |
|
| 39 | $stmt = $this->mysqli->prepare(" |
|
| 40 | SELECT height |
|
| 41 | FROM " . $this->block->getTableName() . " |
|
| 42 | WHERE height >= ? |
|
| 43 | ORDER BY height ASC |
|
| 44 | LIMIT 1"); |
|
| 45 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 46 | return $result->fetch_object()->height; |
|
| 47 | return $this->sqlError(); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * get next block for stats paging |
|
| @@ 53-64 (lines=12) @@ | ||
| 50 | /** |
|
| 51 | * get next block for stats paging |
|
| 52 | **/ |
|
| 53 | public function getNextBlockForStats($iHeight=0, $limit=10) { |
|
| 54 | $stmt = $this->mysqli->prepare(" |
|
| 55 | SELECT MAX(x.height) AS height |
|
| 56 | FROM ( |
|
| 57 | SELECT height FROM " . $this->block->getTableName() . " |
|
| 58 | WHERE height >= ? |
|
| 59 | ORDER BY height ASC LIMIT ? |
|
| 60 | ) AS x"); |
|
| 61 | if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $iHeight, $limit) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 62 | return $result->fetch_object()->height; |
|
| 63 | return $this->sqlError(); |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Get details for block height |
|
| @@ 352-366 (lines=15) @@ | ||
| 349 | /** |
|
| 350 | * Fetch the lowest needed share ID from shares |
|
| 351 | **/ |
|
| 352 | function getMinimumShareId($iCount, $current_upstream) { |
|
| 353 | $stmt = $this->mysqli->prepare(" |
|
| 354 | SELECT MIN(b.id) AS id FROM |
|
| 355 | ( |
|
| 356 | SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total |
|
| 357 | FROM $this->table, (SELECT @total := 0) AS a |
|
| 358 | WHERE our_result = 'Y' |
|
| 359 | AND id <= ? AND @total < ? |
|
| 360 | ORDER BY id DESC |
|
| 361 | ) AS b |
|
| 362 | WHERE total <= ?"); |
|
| 363 | if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 364 | return $result->fetch_object()->id; |
|
| 365 | return $this->sqlError(); |
|
| 366 | } |
|
| 367 | ||
| 368 | /** |
|
| 369 | * Fetch the lowest needed share ID from archive |
|
| @@ 371-386 (lines=16) @@ | ||
| 368 | /** |
|
| 369 | * Fetch the lowest needed share ID from archive |
|
| 370 | **/ |
|
| 371 | function getMinArchiveShareId($iCount) { |
|
| 372 | $stmt = $this->mysqli->prepare(" |
|
| 373 | SELECT MIN(b.share_id) AS share_id FROM |
|
| 374 | ( |
|
| 375 | SELECT share_id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total |
|
| 376 | FROM $this->tableArchive, (SELECT @total := 0) AS a |
|
| 377 | WHERE our_result = 'Y' |
|
| 378 | AND @total < ? |
|
| 379 | ORDER BY share_id DESC |
|
| 380 | ) AS b |
|
| 381 | WHERE total <= ? |
|
| 382 | "); |
|
| 383 | if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 384 | return $result->fetch_object()->share_id; |
|
| 385 | return $this->sqlError(); |
|
| 386 | } |
|
| 387 | } |
|
| 388 | ||
| 389 | $share = new Share(); |
|
| @@ 47-63 (lines=17) @@ | ||
| 44 | * @param txid int Transaction ID to start from |
|
| 45 | * @param bool boolean True or False |
|
| 46 | **/ |
|
| 47 | public function setArchived($account_id, $txid) { |
|
| 48 | // Update all paid out transactions as archived |
|
| 49 | $stmt = $this->mysqli->prepare(" |
|
| 50 | UPDATE $this->table AS t |
|
| 51 | LEFT JOIN " . $this->block->getTableName() . " AS b |
|
| 52 | ON b.id = t.block_id |
|
| 53 | SET t.archived = 1 |
|
| 54 | WHERE t.archived = 0 |
|
| 55 | AND ( |
|
| 56 | ( t.account_id = ? AND t.id <= ? AND b.confirmations >= ? ) |
|
| 57 | OR ( t.account_id = ? AND t.id <= ? AND b.confirmations = -1 ) |
|
| 58 | OR ( t.account_id = ? AND t.id <= ? AND t.type IN ( 'Credit_PPS', 'Donation_PPS', 'Fee_PPS', 'TXFee', 'Debit_MP', 'Debit_AP' ) ) |
|
| 59 | )"); |
|
| 60 | if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiii', $account_id, $txid, $this->config['confirmations'], $account_id, $txid, $account_id, $txid) && $stmt->execute()) |
|
| 61 | return true; |
|
| 62 | return $this->sqlError(); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Fetch a transaction summary by type with total amounts |
|