backend: detect and assign category of PoS blocks

category "stake" while immature, "generated" after

Only shown in the dashboard...
This commit is contained in:
Tanguy Pruvot 2016-02-27 02:17:07 +01:00
parent 5460cb205d
commit 3b32d4b987
5 changed files with 55 additions and 13 deletions

View file

@ -85,6 +85,11 @@ function BackendBlockFind1()
debuglog("{$coin->symbol} orphan {$db_block->height} after ".(time() - $db_block->time)." seconds");
continue;
}
else if ($coin->rpcencoding == 'POS' && arraySafeVal($block,'nonce') == 0) {
$db_block->category = 'stake';
$db_block->save();
continue;
}
$tx = $remote->gettransaction($block['tx'][0]);
if(!$tx || !isset($tx['details']) || !isset($tx['details'][0]))
@ -94,6 +99,7 @@ function BackendBlockFind1()
continue;
}
$db_block->txhash = $block['tx'][0];
$db_block->category = 'immature'; //$tx['details'][0]['category'];
$db_block->amount = $tx['details'][0]['amount'];
@ -114,7 +120,7 @@ function BackendBlocksUpdate()
// debuglog(__METHOD__);
$t1 = microtime(true);
$list = getdbolist('db_blocks', "category='immature' order by time");
$list = getdbolist('db_blocks', "category IN ('immature','stake') order by time");
foreach($list as $block)
{
$coin = getdbo('db_coins', $block->coin_id);
@ -128,6 +134,12 @@ function BackendBlocksUpdate()
if(empty($block->txhash))
{
$blockext = $remote->getblock($block->blockhash);
if ($coin->rpcencoding == 'POS' && arraySafeVal($blockext,'nonce') == 0) {
$block->category = 'stake';
$block->save();
}
if(!$blockext || !isset($blockext['tx'][0])) continue;
$block->txhash = $blockext['tx'][0];
@ -138,23 +150,37 @@ function BackendBlocksUpdate()
$block->confirmations = $tx['confirmations'];
$category = $block->category;
if($block->confirmations == -1) {
$block->category = 'orphan';
$category = 'orphan';
$block->amount = 0;
}
else if(isset($tx['details']) && isset($tx['details'][0]))
$block->category = $tx['details'][0]['category'];
$category = $tx['details'][0]['category'];
else if(isset($tx['category']))
$block->category = $tx['category'];
$category = $tx['category'];
// PoS blocks
if ($block->category == 'stake') {
if ($category == 'generate') {
$block->category = 'generated';
} else if ($category == 'orphan') {
$block->category = 'orphan';
}
$block->save();
continue;
}
// PoW blocks
$block->category = $category;
$block->save();
if($block->category == 'generate')
if($category == 'generate')
dborun("update earnings set status=1, mature_time=UNIX_TIMESTAMP() where blockid=$block->id");
else if($block->category != 'immature')
else if($category != 'immature')
dborun("delete from earnings where blockid=$block->id");
}

View file

@ -56,6 +56,9 @@ foreach($db_blocks as $db_block)
$coin = getdbo('db_coins', $db_block->coin_id);
if(!$coin) continue;
if($db_block->category == 'stake' && !$this->admin) continue;
if($db_block->category == 'generated' && !$this->admin) continue; // mature stake income
// $remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
// $blockext = $remote->getblock($db_block->blockhash);
@ -96,11 +99,17 @@ foreach($db_blocks as $db_block)
echo "Orphan";
else if($db_block->category == 'immature')
echo "Immature ($db_block->confirmations)";
echo "Immature ({$db_block->confirmations})";
else if($db_block->category == 'generate')
echo 'Confirmed';
else if($db_block->category == 'stake')
echo "Stake ({$db_block->confirmations})";
else if($db_block->category == 'generated')
echo 'Stake';
echo "</td>";
echo "<td>$db_block->difficulty</td>";

View file

@ -130,7 +130,7 @@ if($coin->enable)
else
echo "<td>[&nbsp;&nbsp;&nbsp;&nbsp;]</td>";
echo '<td><b><a href="/site/coin?id='.$coin->id.'">'.$coin->name.'</a></b></td>';
echo '<td><b><a href="/site/block?id='.$coin->id.'">'.$coin->name.'</a></b></td>';
echo '<td width="60"><b>'.$coin->symbol.'</b></td>';
echo '<td>'.$coin->algo.'</td>';

View file

@ -527,16 +527,22 @@ foreach($db_blocks as $db_block)
echo '<td align="right" style="font-size: .8em">';
if($db_block->category == 'orphan')
echo '<span style="padding: 2px; color: white; background-color: #d9534f;">Orphan</span>';
echo '<span class="block orphan" style="padding: 2px; color: white; background-color: #d9534f;">Orphan</span>';
else if($db_block->category == 'immature')
echo '<span style="padding: 2px; color: white; background-color: #f0ad4e">Immature ('.$db_block->confirmations.')</span>';
echo '<span class="block immature" style="padding: 2px; color: white; background-color: #f0ad4e">Immature ('.$db_block->confirmations.')</span>';
else if($db_block->category == 'stake')
echo '<span class="block stake" style="padding: 2px; color: white; background-color: #a0a0a0">Stake ('.$db_block->confirmations.')</span>';
else if($db_block->category == 'generated')
echo '<span class="block staked" style="padding: 2px; color: white; background-color: #a0a0a0">Confirmed</span>';
else if($db_block->category == 'generate')
echo '<span style="padding: 2px; color: white; background-color: #5cb85c">Confirmed</span>';
echo '<span class="block generate" style="padding: 2px; color: white; background-color: #5cb85c">Confirmed</span>';
else if($db_block->category == 'new')
echo '<span style="padding: 2px; color: white; background-color: #ad4ef0">New</span>';
echo '<span class="block new" style="padding: 2px; color: white; background-color: #ad4ef0">New</span>';
echo '</td>';
echo '</tr>';

View file

@ -21,7 +21,8 @@ if($algo == 'all')
else {
// $db_blocks = getdbolist('db_blocks', "algo=:algo ORDER BY time DESC LIMIT :count", array(':algo'=>$algo, ':count'=>$count));
$criteria = new CDbCriteria();
$criteria->condition = 'blocks.algo=:algo AND IFNULL(coin.visible,1)=1'; // ifnull for rental
$criteria->condition = "blocks.algo=:algo AND IFNULL(coin.visible,1)=1"; // ifnull for rental
$criteria->condition .= " AND blocks.category NOT IN ('stake','generated')";
$criteria->params = array(':algo'=>$algo);
$criteria->limit = $count;
$criteria->order = 'blocks.time DESC';