From 3b32d4b9872b0ffc3abc15ea10ff8009a3e6af4f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 27 Feb 2016 02:17:07 +0100 Subject: [PATCH] backend: detect and assign category of PoS blocks category "stake" while immature, "generated" after Only shown in the dashboard... --- web/yaamp/core/backend/blocks.php | 38 ++++++++++++++++--- web/yaamp/modules/site/block_results.php | 11 +++++- web/yaamp/modules/site/coin_results.php | 2 +- web/yaamp/modules/site/common_results.php | 14 +++++-- .../modules/site/results/found_results.php | 3 +- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/web/yaamp/core/backend/blocks.php b/web/yaamp/core/backend/blocks.php index 32cf69b..a9d868f 100644 --- a/web/yaamp/core/backend/blocks.php +++ b/web/yaamp/core/backend/blocks.php @@ -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"); } diff --git a/web/yaamp/modules/site/block_results.php b/web/yaamp/modules/site/block_results.php index ad6443c..a18ca71 100644 --- a/web/yaamp/modules/site/block_results.php +++ b/web/yaamp/modules/site/block_results.php @@ -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 ""; echo "$db_block->difficulty"; diff --git a/web/yaamp/modules/site/coin_results.php b/web/yaamp/modules/site/coin_results.php index 2cca73b..dbfe6aa 100644 --- a/web/yaamp/modules/site/coin_results.php +++ b/web/yaamp/modules/site/coin_results.php @@ -130,7 +130,7 @@ if($coin->enable) else echo "[    ]"; -echo ''.$coin->name.''; +echo ''.$coin->name.''; echo ''.$coin->symbol.''; echo ''.$coin->algo.''; diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index c7e0fc2..1a1cb28 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -527,16 +527,22 @@ foreach($db_blocks as $db_block) echo ''; if($db_block->category == 'orphan') - echo 'Orphan'; + echo 'Orphan'; else if($db_block->category == 'immature') - echo 'Immature ('.$db_block->confirmations.')'; + echo 'Immature ('.$db_block->confirmations.')'; + + else if($db_block->category == 'stake') + echo 'Stake ('.$db_block->confirmations.')'; + + else if($db_block->category == 'generated') + echo 'Confirmed'; else if($db_block->category == 'generate') - echo 'Confirmed'; + echo 'Confirmed'; else if($db_block->category == 'new') - echo 'New'; + echo 'New'; echo ''; echo ''; diff --git a/web/yaamp/modules/site/results/found_results.php b/web/yaamp/modules/site/results/found_results.php index c97077a..594683c 100644 --- a/web/yaamp/modules/site/results/found_results.php +++ b/web/yaamp/modules/site/results/found_results.php @@ -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';