Merge pull request #6 from TheSerapher/findblock-update
adding more output to findblocks
This commit is contained in:
commit
0eab903670
@ -22,25 +22,36 @@ limitations under the License.
|
||||
require_once('shared.inc.php');
|
||||
|
||||
// Fetch our last block found from the DB as a starting point
|
||||
$strLastBlockHash = $block->getLast()->blockhash;
|
||||
$strLastBlockHash = @$block->getLast()->blockhash;
|
||||
if (!$strLastBlockHash) {
|
||||
$strLastBlockHash = '';
|
||||
}
|
||||
|
||||
try {
|
||||
if ( $bitcoin->can_connect() === true ){
|
||||
$aTransactions = $bitcoin->query('listsinceblock', $strLastBlockHash);
|
||||
} catch (Exception $e) {
|
||||
echo "Unable to connect to bitcoin RPC\n";
|
||||
$iDifficulty = $bitcoin->query('getdifficulty');
|
||||
} else {
|
||||
echo "Aborted: " . $bitcoin->can_connect() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime\t\t\tStatus\n";
|
||||
|
||||
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
||||
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
||||
$aBlockInfo = $bitcoin->query('getblock', $aData['blockhash']);
|
||||
$aData['height'] = $aBlockInfo['height'];
|
||||
if ( ! $block->addBlock($aData) ) {
|
||||
echo "Failed to add block: " . $aData['height'] , "\n";
|
||||
echo "Error : " . $block->getError() . "\n";
|
||||
$aData['difficulty'] = $iDifficulty;
|
||||
echo substr($aData['blockhash'], 0, 15) . "...\t" .
|
||||
$aData['height'] . "\t" .
|
||||
$aData['amount'] . "\t" .
|
||||
$aData['confirmations'] . "\t\t" .
|
||||
$aData['difficulty'] . "\t" .
|
||||
strftime("%Y-%m-%d %H:%M:%S", $aData['time']) . "\t";
|
||||
if ( $block->addBlock($aData) ) {
|
||||
echo "Added\n";
|
||||
} else {
|
||||
echo "Failed" . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ class Block {
|
||||
private $sError = '';
|
||||
private $table = 'blocks';
|
||||
// This defines each block
|
||||
public $height, $blockhash, $confirmations, $difficulty, $time;
|
||||
public $height, $blockhash, $confirmations, $time, $accounted;
|
||||
|
||||
public function __construct($debug, $mysqli, $salt) {
|
||||
$this->debug = $debug;
|
||||
@ -35,12 +35,24 @@ class Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addBlock($block) {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (height, blockhash, confirmations, amount, time) VALUES (?, ?, ?, ?, ?)");
|
||||
public function getAll($order='DESC') {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table ORDER BY height $order");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('isidi', $block['height'], $block['blockhash'], $block['confirmations'], $block['amount'], $block['time']);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addBlock($block) {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (height, blockhash, confirmations, amount, difficulty, time) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('isiddi', $block['height'], $block['blockhash'], $block['confirmations'], $block['amount'], $block['difficulty'], $block['time']);
|
||||
if (!$stmt->execute()) {
|
||||
$this->debug->append("Failed to execute statement: " . $stmt->error);
|
||||
$this->setErrorMessage($stmt->error);
|
||||
$stmt->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user