diff --git a/cronjobs/ledger.php b/cronjobs/ledger.php new file mode 100644 index 00000000..da62f08e --- /dev/null +++ b/cronjobs/ledger.php @@ -0,0 +1,25 @@ + 120 AND l.confirmed = 0; +$ledger->confirmTransactions(); diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php index 015d5590..6bc52a45 100644 --- a/public/include/autoloader.inc.php +++ b/public/include/autoloader.inc.php @@ -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'); diff --git a/public/include/classes/ledger.class.php b/public/include/classes/ledger.class.php new file mode 100644 index 00000000..65bc8f46 --- /dev/null +++ b/public/include/classes/ledger.class.php @@ -0,0 +1,57 @@ +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);