adding future ledger cronjob for transaction confirmations
This commit is contained in:
parent
a995ab640d
commit
cbfcff3ba1
25
cronjobs/ledger.php
Normal file
25
cronjobs/ledger.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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');
|
||||
|
||||
// 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;
|
||||
$ledger->confirmTransactions();
|
||||
@ -9,4 +9,5 @@ require_once(CLASS_DIR . '/user.class.php');
|
||||
require_once(CLASS_DIR . '/block.class.php');
|
||||
require_once(CLASS_DIR . '/share.class.php');
|
||||
require_once(CLASS_DIR . '/statistics.class.php');
|
||||
require_once(CLASS_DIR . '/ledger.class.php');
|
||||
require_once(CLASS_DIR . '/settings.class.php');
|
||||
|
||||
57
public/include/classes/ledger.class.php
Normal file
57
public/include/classes/ledger.class.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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 confirmTransactions() {
|
||||
// Confirm all outstanding transactions
|
||||
$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);
|
||||
Loading…
Reference in New Issue
Block a user