From d4b14873bfba2a41a4c062c34bb0e80bdd5cdc9e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 25 Feb 2017 00:26:13 +0100 Subject: [PATCH] cli: tool to compare wallet diff and computed one --- web/yaamp/commands/CoinCommand.php | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/web/yaamp/commands/CoinCommand.php b/web/yaamp/commands/CoinCommand.php index a9ee2a0..b4d8010 100644 --- a/web/yaamp/commands/CoinCommand.php +++ b/web/yaamp/commands/CoinCommand.php @@ -34,6 +34,7 @@ class CoinCommand extends CConsoleCommand echo "Yiimp coin command\n"; echo "Usage: yiimp coin delete - to delete with all related records\n"; echo " yiimp coin purge - to clean users and history \n"; + echo " yiimp coin diff - to check if wallet diff is standard\n"; echo " yiimp coin get \n"; echo " yiimp coin set \n"; echo " yiimp coin unset \n"; @@ -46,6 +47,9 @@ class CoinCommand extends CConsoleCommand } else if ($args[1] == 'purge') { return $this->purgeCoin($symbol); + } else if ($args[1] == 'diff') { + return $this->checkMiningDiff($symbol); + } else if ($args[1] == 'get') { return $this->getCoinSetting($args); @@ -125,6 +129,37 @@ class CoinCommand extends CConsoleCommand //////////////////////////////////////////////////////////////////////////////////// + /** + * Compare getminininginfo difficulty and computed one (from the target hash) + */ + public function checkMiningDiff($symbol) + { + $coins = new db_coins; + + if (!$coins instanceof CActiveRecord) + return; + + $coin = $coins->find(array('condition'=>'symbol=:sym', 'params'=>array(':sym'=>$symbol))); + if ($coin) + { + $remote = new WalletRPC($coin); + $tpl = $remote->getblocktemplate(); + $mnf = $remote->getmininginfo(); + if (empty($tpl)) echo "error ".json_encode($tpl); + + $target = arraySafeVal($tpl,"target",""); + $computed_diff = hash_to_difficulty($coin,$target); + $wallet_diff = arraySafeVal($mnf,"difficulty",0); + $factor = $computed_diff ? round($wallet_diff/$computed_diff,3) : 'NaN'; + + echo $coin->symbol.": network=".Itoa2(arraySafeVal($mnf,"networkhashps",0)*1000, 3)."H/s\n". + "bits=".arraySafeVal($tpl,"bits","")." target=$target\n". + "difficulty=$wallet_diff hash_to_difficulty(target)=$computed_diff factor=$factor\n"; + } + } + + //////////////////////////////////////////////////////////////////////////////////// + public function getCoinSetting($args) { if (count($args) < 3)