Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions modules/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 3 additions & 33 deletions modules/functions_rpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}