From a147665e96e498266a8267fd8ffd7c39370bbcd3 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 7 Jan 2020 23:34:50 +0100 Subject: [PATCH 1/3] fix utxo supply --- src/Controller/MainController.php | 56 +++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 9d60d04..b964a5a 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -661,7 +661,7 @@ class MainController extends AppController { $this->_jsonResponse(['success' => true, 'txs' => $txs]); } - protected function _gettxoutsetinfo() { + /*protected function _gettxoutsetinfo() { $now = new \DateTime('now', new \DateTimeZone('UTC')); $txOutSetInfo = new \stdClass(); $txOutSetInfo->time = $now->format('c'); @@ -684,7 +684,6 @@ class MainController extends AppController { } if ($shouldRefreshSet) { - $req = ['method' => 'gettxoutsetinfo', 'params' => []]; try { $res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req))); @@ -702,7 +701,7 @@ class MainController extends AppController { } return (isset($txOutSetInfo->tosi)) ? $txOutSetInfo->tosi : 'N/A'; - } + }*/ public function apistatus() { $this->autoRender = false; @@ -879,10 +878,20 @@ class MainController extends AppController { $reservedcommunity = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd']; $reservedoperational = ['r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL']; $reservedinstitutional = ['r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi']; - $reservedaux = ['bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', 'bCrboXVztuSbZzVToCWSsu1pEr2oxKHu9v', 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h']; + $reservedaux = [ + 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', + 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', + 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', + 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', + 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', + 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', + 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', + 'bCrboXVztuSbZzVToCWSsu1pEr2oxKHu9v', + 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h' + ]; $allAddresses = array_merge($reservedcommunity, $reservedoperational, $reservedinstitutional, $reservedaux); - $reservedtotal = $this->Addresses->find()->select(['id', 'balance' => 'SUM(balance)'])->where(['Addresses.address IN' => $allAddresses])->first(); + $reservedtotal = $this->Addresses->find()->select(['balance' => 'SUM(balance)'])->where(['Addresses.address IN' => $allAddresses])->first(); $circulating = $txoutsetinfo->total_amount - ($reservedtotal->balance); @@ -945,19 +954,6 @@ class MainController extends AppController { } } - // private function _gettxoutsetinfo() { - // $req = ['method' => 'gettxoutsetinfo', 'params' => []]; - // try { - // $res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req))); - // if (!isset($res->result)) { - // return 0; - // } - // return $res->result; - // } catch (\Exception $e) { - // return 'N/A'; - // } - // } - private static function curl_json_post($url, $data, $headers = []) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); @@ -1009,6 +1005,30 @@ class MainController extends AppController { return $claimIsBlocked; } + private function _gettxoutsetinfo() { + $cachedOutsetInfo = Cache::read('gettxoutsetinfo', 'api_requests'); + if ($cachedOutsetInfo !== false) { + $res = json_decode($cachedOutsetInfo); + if (!isset($res->result)) { + return 0; + } + return $res->result; + } + + $req = ['method' => 'gettxoutsetinfo', 'params' => []]; + try { + $response = self::curl_json_post(self::$rpcurl, json_encode($req)); + $res = json_decode($res); + if (!isset($res->result)) { + return 0; + } + Cache::write('gettxoutsetinfo', $response, 'api_requests'); + return $res->result; + } catch (\Exception $e) { + return 0; + } + } + private function _getBlockedList() { $cachedList = Cache::read('list_blocked', 'api_requests'); if ($cachedList !== false) { From 77ca91757b6ed3bb2e2682a52ec09c11ea25056f Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 7 Jan 2020 23:37:50 +0100 Subject: [PATCH 2/3] fix _gettxoutsetinfo return type --- src/Controller/MainController.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index b964a5a..3727c7c 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -893,9 +893,8 @@ class MainController extends AppController { $reservedtotal = $this->Addresses->find()->select(['balance' => 'SUM(balance)'])->where(['Addresses.address IN' => $allAddresses])->first(); - $circulating = $txoutsetinfo->total_amount - ($reservedtotal->balance); - - return $this->_jsonResponse(['success' => true, 'utxosupply' => ['total' => $txoutsetinfo->total_amount, 'circulating' => $circulating]]); + $circulating = (isset($txoutsetinfo) ? $txoutsetinfo->total_amount : 0) - ($reservedtotal->balance); + return $this->_jsonResponse(['success' => true, 'utxosupply' => ['total' => isset($txoutsetinfo) ? $txoutsetinfo->total_amount : 0, 'circulating' => $circulating]]); } protected function _formatHashRate($value) { @@ -1010,7 +1009,7 @@ class MainController extends AppController { if ($cachedOutsetInfo !== false) { $res = json_decode($cachedOutsetInfo); if (!isset($res->result)) { - return 0; + return null; } return $res->result; } @@ -1020,12 +1019,12 @@ class MainController extends AppController { $response = self::curl_json_post(self::$rpcurl, json_encode($req)); $res = json_decode($res); if (!isset($res->result)) { - return 0; + return null; } Cache::write('gettxoutsetinfo', $response, 'api_requests'); return $res->result; } catch (\Exception $e) { - return 0; + return null; } } From a7c1b9b346e5f2c009e58e2f135008ac0b59fb06 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 8 Jan 2020 08:04:00 +0100 Subject: [PATCH 3/3] update community, operational and institutional addresses --- src/Controller/MainController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 3727c7c..29660ea 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -875,9 +875,9 @@ class MainController extends AppController { $circulating = 0; $txoutsetinfo = $this->_gettxoutsetinfo(); - $reservedcommunity = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd']; - $reservedoperational = ['r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL']; - $reservedinstitutional = ['r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi']; + $reservedcommunity = ['rEqocTgdPdoD8NEbrECTUPfpquJ4zPVCJ8']; + $reservedoperational = ['r7hj61jdbGXcsccxw8UmEFCReZoCWLRr7t']; + $reservedinstitutional = ['rKaAUDxr24hHNNTQuNtRvNt8SGYJMdLXo3']; $reservedaux = [ 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2',