diff --git a/api.php b/api.php index 34e6180..dd58f75 100644 --- a/api.php +++ b/api.php @@ -32,12 +32,15 @@ $data->nanoNodeAccountShort = truncateAddress($data->nanoNodeAccount); $data->nanoNodeAccountUrl = getAccountUrl($data->nanoNodeAccount, $blockExplorer); + // -- Get Telemetry from nano node + $telemetry = getTelemetry($ch); + // -- Get Version String from nano node and node monitor - $version = getVersion($ch); - $data->version = $version->{'node_vendor'}; - $data->store_version = (int) $version->{'store_version'} ?: 0; - $data->protocol_version = (int) $version->{'protocol_version'} ?: 0; - $data->store_vendor = (string) $version->{'store_vendor'} ?: ''; + $majorVersion = (int) $telemetry->{'major_version'}; + $minorVersion = (int) $telemetry->{'minor_version'}; + $patchVersion = (int) $telemetry->{'patch_version'}; + $data->version = 'Nano v'.$majorVersion.'.'.$minorVersion.'.'.$patchVersion; + $data->protocol_version = (int) $telemetry->{'protocol_version'} ?: 0; // Cache the github query for latest node version global $nodeVersionCache; @@ -54,23 +57,20 @@ return $nodeVersionData; }); $latestVersion = $nodeVersionData->latestNodeReleaseVersion; - $data->newNodeVersionAvailable = isNewNodeVersionAvailable(formatVersion($data->version), $latestVersion, $currency); + $data->newNodeVersionAvailable = isNewNodeVersionAvailable($majorVersion.'.'.$minorVersion, $latestVersion, $currency); $data->nodeMonitorVersion = PROJECT_VERSION; - // -- Get get current block from nano_node - $rpcBlockCount = getBlockCount($ch); - $data->currentBlock = (int) $rpcBlockCount->{'count'}; - $data->uncheckedBlocks = (int) $rpcBlockCount->{'unchecked'}; - $data->cementedBlocks = (int) $rpcBlockCount->{'cemented'} ?: 0; + // -- Get current block from nano_node + $data->currentBlock = (int) $telemetry->{'block_count'}; + $data->uncheckedBlocks = (int) $telemetry->{'unchecked_count'}; + $data->cementedBlocks = (int) $telemetry->{'cemented_count'} ?: 0; if ($currency == 'nano') { $data->blockSync = getSyncStatus($data->currentBlock); } // -- Get number of peers from nano_node - $rpcPeers = getPeers($ch); - $peers = (array) $rpcPeers->{'peers'}; - $data->numPeers = count($peers); + $data->numPeers = (int) $telemetry->{'peer_count'}; // -- Get confirmation info from nano_node. Average time, blocks used, time span and percentiles // -- over last X min (set by CONFIRMATION_TIME_LIMIT) or max 2048 blocks which is a node limitation @@ -166,7 +166,7 @@ $data->currencySymbol = currencySymbol($currency); // active_difficulty - $data->active_difficulty = getActiveDifficulty($ch); + $data->active_difficulty = (string) $telemetry->{'active_difficulty'}; // node statistics // maybe we get more stats later diff --git a/modules/functions.php b/modules/functions.php index ab80fc4..54adfad 100644 --- a/modules/functions.php +++ b/modules/functions.php @@ -174,7 +174,7 @@ function getLatestNodeReleaseVersion() $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.github.com/repos/nanocurrency/raiblocks/releases/latest', + CURLOPT_URL => 'https://api.github.com/repos/nanocurrency/nano-node/releases/latest', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, @@ -209,13 +209,6 @@ function getLatestNodeReleaseVersion() return ''; } -// gets the number from the version string -function formatVersion($rawversion){ - $formattedVersion = explode(' ', $rawversion); - - return $formattedVersion[1]; -} - // get a string with information about the // current version and possible updates function isNewNodeVersionAvailable($currentVersion, $latestVersion, $currency) diff --git a/modules/functions_rpc.php b/modules/functions_rpc.php index 104a347..c8c2658 100644 --- a/modules/functions_rpc.php +++ b/modules/functions_rpc.php @@ -25,31 +25,11 @@ function postCurl($ch, $data) return json_decode($resp); } -// get version string from nano_node -function getVersion($ch) +// get telemetry from nano_node +function getTelemetry($ch) { // get version string - $data = array("action" => "version"); - - // post curl - return postCurl($ch, $data); -} - -// get block count from nano_node -function getBlockCount($ch) -{ - // get block count - $data = array("action" => "block_count", "include_cemented" => "true"); - - // post curl - return postCurl($ch, $data); -} - -// get number of peers -function getPeers($ch) -{ - // get peers - $data = array("action" => "peers"); + $data = array("action" => "telemetry"); // post curl return postCurl($ch, $data); @@ -122,13 +102,3 @@ function getUptime($ch) // post curl return postCurl($ch, $data); } - -// get active difficulty -function getActiveDifficulty($ch) -{ - // get uptime - $data = array("action" => "active_difficulty"); - - // post curl - return postCurl($ch, $data); -}