From c8a8d3b9d006c4b14a625949e4eeb465e2b62a87 Mon Sep 17 00:00:00 2001 From: pxgamer Date: Fri, 12 Oct 2018 11:55:24 +0100 Subject: [PATCH] Add apiDoc comments for the sanity endpoint --- api.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/api.php b/api.php index 2743c64..8dccc6a 100755 --- a/api.php +++ b/api.php @@ -423,8 +423,8 @@ if ($q == "getAddress") { api_err("Invalid destination alias"); } } - - + + $public_key = san($data['public_key']); if (!$acc->valid_key($public_key)) { @@ -454,7 +454,7 @@ if ($q == "getAddress") { if ($date > time() + 86400) { api_err("Invalid Date"); } - + $message=$data['message']; if (strlen($message) > 128) { api_err("The message must be less than 128 chars"); @@ -472,7 +472,7 @@ if ($q == "getAddress") { if ($val < 0.00000001) { api_err("Invalid value"); } - + // set alias if ($version==3) { $fee=10; @@ -632,7 +632,7 @@ if ($q == "getAddress") { $public_key=san($data['public_key']); $signature=san($data['signature']); $data=$data['data']; - + api_echo(ec_verify($data, $signature, $public_key)); } elseif ($q == "masternodes") { /** @@ -662,7 +662,7 @@ if ($q == "getAddress") { * * @apiSuccess {string} data alias */ - + $public_key = $data['public_key']; $account = $data['account']; if (!empty($public_key) && strlen($public_key) < 32) { @@ -671,18 +671,29 @@ if ($q == "getAddress") { if (!empty($public_key)) { $account = $acc->get_address($public_key); } - + if (empty($account)) { api_err("Invalid account id"); } $account = san($account); - + api_echo($acc->account2alias($account)); } elseif ($q === 'sanity') { + /** + * @api {get} /api.php?q=sanity 20. sanity + * @apiName sanity + * @apiGroup API + * @apiDescription Returns details about the node's sanity process. + * + * @apiSuccess {object} data A collection of data about the sanity process. + * @apiSuccess {boolean} data.sanity_running Whether the sanity process is currently running. + * @apiSuccess {number} data.last_sanity The timestamp for the last time the sanity process was run. + * @apiSuccess {boolean} data.sanity_sync Whether the sanity process is currently synchronising. + */ $sanity = file_exists(__DIR__.'/tmp/sanity-lock'); - $lastSanity = $db->single("SELECT val FROM config WHERE cfg='sanity_last'"); - $sanitySync = $db->single("SELECT val FROM config WHERE cfg='sanity_sync'"); + $lastSanity = (int)$db->single("SELECT val FROM config WHERE cfg='sanity_last'"); + $sanitySync = (bool)$db->single("SELECT val FROM config WHERE cfg='sanity_sync'"); api_echo(['sanity_running' => $sanity, 'last_sanity' => $lastSanity, 'sanity_sync' => $sanitySync]); } elseif ($q=="node-info"){ $dbversion=$db->single("SELECT val FROM config WHERE cfg='dbversion'"); @@ -692,7 +703,7 @@ if ($q == "getAddress") { $mns=$db->single("SELECT COUNT(1) FROM masternode"); $mempool=$db->single("SELECT COUNT(1) FROM mempool"); api_echo(["hostname"=>$hostname, "version"=>VERSION,"dbversion"=>$dbversion, "accounts"=>$acc, "transactions"=>$tr, "mempool"=>$mempool, "masternodes"=>$mns]); - + } else { api_err("Invalid request"); }