implemented transactions, PPS payouts and Transactions displayed on the website
This commit is contained in:
parent
37618e9b71
commit
4a7b51d9eb
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Copyright:: 2013, Sebastian Grewe
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Include all settings and classes
|
|
||||||
require_once('shared.inc.php');
|
|
||||||
|
|
||||||
// Confirm any outstanding credits
|
|
||||||
$ledger->confirmCredits();
|
|
||||||
@ -44,15 +44,20 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
|||||||
$aData['invalid'] . "\t" .
|
$aData['invalid'] . "\t" .
|
||||||
$aData['percentage'] . "\t" .
|
$aData['percentage'] . "\t" .
|
||||||
$aData['payout'] . "\t";
|
$aData['payout'] . "\t";
|
||||||
if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) {
|
|
||||||
echo "Stats Failed" . "\n";
|
// Do all database updates for statistics and payouts
|
||||||
}
|
$strStatus = "OK";
|
||||||
|
// if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
|
||||||
|
// $strStatus = "Stats Failed";
|
||||||
|
if (!$transaction->addCredit($aData['id'], $aData['payout'], $aBlock['id']))
|
||||||
|
$strStatus = "Transaction Failed";
|
||||||
|
echo "$strStatus\n";
|
||||||
}
|
}
|
||||||
echo "------------------------------------------------------------------------\n\n";
|
echo "------------------------------------------------------------------------\n\n";
|
||||||
|
|
||||||
// Now that we have all shares counted internally let's update the tables
|
// Now that we have all shares counted internally let's update the tables
|
||||||
// Set shares as counted and mark block as accounted for
|
// Set shares as counted and mark block as accounted for
|
||||||
// $share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime);
|
$share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||||
// $block->setAccounted($aBlock['blockhash']);
|
$block->setAccounted($aBlock['blockhash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,5 +9,5 @@ require_once(CLASS_DIR . '/user.class.php');
|
|||||||
require_once(CLASS_DIR . '/block.class.php');
|
require_once(CLASS_DIR . '/block.class.php');
|
||||||
require_once(CLASS_DIR . '/share.class.php');
|
require_once(CLASS_DIR . '/share.class.php');
|
||||||
require_once(CLASS_DIR . '/statistics.class.php');
|
require_once(CLASS_DIR . '/statistics.class.php');
|
||||||
require_once(CLASS_DIR . '/ledger.class.php');
|
require_once(CLASS_DIR . '/transaction.class.php');
|
||||||
require_once(CLASS_DIR . '/settings.class.php');
|
require_once(CLASS_DIR . '/settings.class.php');
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Make sure we are called from index.php
|
|
||||||
if (!defined('SECURITY'))
|
|
||||||
die('Hacking attempt');
|
|
||||||
|
|
||||||
class Ledger {
|
|
||||||
private $sError = '';
|
|
||||||
private $table = 'blocks';
|
|
||||||
// This defines each block
|
|
||||||
public $height, $blockhash, $confirmations, $difficulty, $time;
|
|
||||||
|
|
||||||
public function __construct($debug, $mysqli, $salt) {
|
|
||||||
$this->debug = $debug;
|
|
||||||
$this->mysqli = $mysqli;
|
|
||||||
$this->debug->append("Instantiated Ledger class", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get and set methods
|
|
||||||
private function setErrorMessage($msg) {
|
|
||||||
$this->sError = $msg;
|
|
||||||
}
|
|
||||||
public function getError() {
|
|
||||||
return $this->sError;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function confirmCredits() {
|
|
||||||
$stmt = $this->mysqli->prepare("UPDATE
|
|
||||||
ledger AS l
|
|
||||||
INNER JOIN blocks as b ON l.assocBlock = b.height
|
|
||||||
SET l.confirmed = 1
|
|
||||||
WHERE b.confirmations > 120
|
|
||||||
AND l.confirmed = 0");
|
|
||||||
if ($this->checkStmt($stmt)) {
|
|
||||||
if (!$stmt->execute()) {
|
|
||||||
$this->debug->append("Failed to execute statement: " . $stmt->error);
|
|
||||||
$stmt->close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$stmt->close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkStmt($bState) {
|
|
||||||
if ($bState ===! true) {
|
|
||||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
|
||||||
$this->setErrorMessage('Internal application Error');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ledger = new Ledger($debug, $mysqli, SALT);
|
|
||||||
@ -25,9 +25,9 @@ class Statistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function updateShareStatistics($aStats, $iBlockId) {
|
public function updateShareStatistics($aStats, $iBlockId) {
|
||||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?, ?)");
|
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
|
||||||
if ($this->checkStmt($stmt)) {
|
if ($this->checkStmt($stmt)) {
|
||||||
$stmt->bind_param('iiiddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId);
|
$stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId);
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
95
public/include/classes/transaction.class.php
Normal file
95
public/include/classes/transaction.class.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Make sure we are called from index.php
|
||||||
|
if (!defined('SECURITY'))
|
||||||
|
die('Hacking attempt');
|
||||||
|
|
||||||
|
class Transaction {
|
||||||
|
private $sError = '';
|
||||||
|
private $table = 'transactions';
|
||||||
|
// This defines each block
|
||||||
|
public $account_id;
|
||||||
|
|
||||||
|
public function __construct($debug, $mysqli) {
|
||||||
|
$this->debug = $debug;
|
||||||
|
$this->mysqli = $mysqli;
|
||||||
|
$this->debug->append("Instantiated Ledger class", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get and set methods
|
||||||
|
private function setErrorMessage($msg) {
|
||||||
|
$this->sError = $msg;
|
||||||
|
}
|
||||||
|
public function getError() {
|
||||||
|
return $this->sError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCredit($account_id, $amount, $block_id) {
|
||||||
|
$strType = 'Credit';
|
||||||
|
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type) VALUES (?, ?, ?, ?)");
|
||||||
|
echo $this->mysqli->error;
|
||||||
|
if ($this->checkStmt($stmt)) {
|
||||||
|
$stmt->bind_param("idis", $account_id, $amount, $block_id, $strType);
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
$stmt->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirmCredits() {
|
||||||
|
$stmt = $this->mysqli->prepare("UPDATE
|
||||||
|
ledger AS l
|
||||||
|
INNER JOIN blocks as b ON l.assocBlock = b.height
|
||||||
|
SET l.confirmed = 1
|
||||||
|
WHERE b.confirmations > 120
|
||||||
|
AND l.confirmed = 0");
|
||||||
|
if ($this->checkStmt($stmt)) {
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
$this->debug->append("Failed to execute statement: " . $stmt->error);
|
||||||
|
$stmt->close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransactions($account_id, $start=0) {
|
||||||
|
$stmt = $this->mysqli->prepare("
|
||||||
|
SELECT
|
||||||
|
t.id AS id,
|
||||||
|
t.type AS type,
|
||||||
|
t.amount AS amount,
|
||||||
|
t.sendAddress AS sendAddress,
|
||||||
|
t.timestamp AS timestamp,
|
||||||
|
b.height AS height,
|
||||||
|
b.confirmations AS confirmations
|
||||||
|
FROM transactions AS t
|
||||||
|
LEFT JOIN blocks AS b ON t.block_id = b.id
|
||||||
|
WHERE t.account_id = ?
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT ? , 30");
|
||||||
|
if ($this->checkStmt($stmt)) {
|
||||||
|
if(!$stmt->bind_param('ii', $account_id, $start)) return false;
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
return $result->fetch_all(MYSQLI_ASSOC);
|
||||||
|
}
|
||||||
|
$this->debug->append('Unable to fetch transactions');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkStmt($bState) {
|
||||||
|
if ($bState ===! true) {
|
||||||
|
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||||
|
$this->setErrorMessage('Internal application Error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = new Transaction($debug, $mysqli);
|
||||||
@ -4,7 +4,7 @@
|
|||||||
if (!defined('SECURITY')) die('Hacking attempt');
|
if (!defined('SECURITY')) die('Hacking attempt');
|
||||||
if (!$_SESSION['AUTHENTICATED']) header('Location: index.php?page=home');
|
if (!$_SESSION['AUTHENTICATED']) header('Location: index.php?page=home');
|
||||||
|
|
||||||
$aTransactions = $user->getTransactions($_SESSION['USERDATA']['id']);
|
$aTransactions = $transaction->getTransactions($_SESSION['USERDATA']['id']);
|
||||||
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
|
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
|
||||||
|
|
||||||
$smarty->assign('TRANSACTIONS', $aTransactions);
|
$smarty->assign('TRANSACTIONS', $aTransactions);
|
||||||
|
|||||||
@ -19,14 +19,16 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody style="font-size:12px;">
|
<tbody style="font-size:12px;">
|
||||||
{section transaction $TRANSACTIONS}
|
{section transaction $TRANSACTIONS}
|
||||||
|
{if (($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= 120) or $TRANSACTIONS[transaction].type != 'Credit')}
|
||||||
<tr class="{cycle values="odd,even"}">
|
<tr class="{cycle values="odd,even"}">
|
||||||
<td>{$TRANSACTIONS[transaction].id}</td>
|
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||||
<td>{$TRANSACTIONS[transaction].timestamp}</td>
|
<td>{$TRANSACTIONS[transaction].timestamp}</td>
|
||||||
<td>{$TRANSACTIONS[transaction].transType}</td>
|
<td>{$TRANSACTIONS[transaction].type}</td>
|
||||||
<td>{$TRANSACTIONS[transaction].sendAddress}</td>
|
<td>{$TRANSACTIONS[transaction].sendAddress}</td>
|
||||||
<td>{if $TRANSACTIONS[transaction].assocBlock == 0}n/a{else}{$TRANSACTIONS[transaction].assocBlock}{/if}</td>
|
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
|
||||||
<td><font color="{if $TRANSACTIONS[transaction].transType == Credit}green{else}red{/if}">{$TRANSACTIONS[transaction].amount}</td>
|
<td><font color="{if $TRANSACTIONS[transaction].type == Credit}green{else}red{/if}">{$TRANSACTIONS[transaction].amount}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{/if}
|
||||||
{/section}
|
{/section}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -38,27 +40,31 @@
|
|||||||
<table cellpadding="1" cellspacing="1" width="98%" class="sortable">
|
<table cellpadding="1" cellspacing="1" width="98%" class="sortable">
|
||||||
<thead style="font-size:13px;">
|
<thead style="font-size:13px;">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Block #</th>
|
<th class="header" style="cursor: pointer;">TX #</th>
|
||||||
<th>Estimated Reward</th>
|
<th class="header" style="cursor: pointer;">Date</th>
|
||||||
<th>Valid Shares</th>
|
<th class="header" style="cursor: pointer;">TX Type</th>
|
||||||
<th>Donation / Fee</th>
|
<th class="header" style="cursor: pointer;">Payment Address</th>
|
||||||
<th>Validity</th>
|
<th class="header" style="cursor: pointer;">Block #</th>
|
||||||
|
<th class="header" style="cursor: pointer;">Amount</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody style="font-size:12px;">
|
<tbody style="font-size:12px;">
|
||||||
<tr>
|
{section transaction $TRANSACTIONS}
|
||||||
<td>TODO</td>
|
{if $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < 120}
|
||||||
<td>TODO</td>
|
<tr class="{cycle values="odd,even"}">
|
||||||
<td>TODO</td>
|
<td>{$TRANSACTIONS[transaction].id}</td>
|
||||||
<td>TODO</td>
|
<td>{$TRANSACTIONS[transaction].timestamp}</td>
|
||||||
<td>TODO</td>
|
<td>{$TRANSACTIONS[transaction].type}</td>
|
||||||
|
<td>{$TRANSACTIONS[transaction].sendAddress}</td>
|
||||||
|
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
|
||||||
|
<td><font color="{if $TRANSACTIONS[transaction].type == Credit}green{else}red{/if}">{$TRANSACTIONS[transaction].amount}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{assign var="sum" value="`$sum+$TRANSACTIONS[transaction].amount`"}
|
||||||
|
{/if}
|
||||||
|
{/section}
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>Unconfirmed Totals:</b></td>
|
<td colspan="5"><b>Unconfirmed Totals:</b></td>
|
||||||
<td><b>0.00000000</b></td>
|
<td><b>{$sum}</b></td>
|
||||||
<td></td>
|
|
||||||
<td><b>0.00000000</b></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user