diff --git a/api.php b/api.php index e8185d9..198bfcb 100755 --- a/api.php +++ b/api.php @@ -712,6 +712,7 @@ if ($q == "getAddress") { * @apiSuccess {number} data.transactions The number of transactions known by the node. * @apiSuccess {number} data.mempool The number of transactions in the mempool. * @apiSuccess {number} data.masternodes The number of masternodes known by the node. + * @apiSuccess {number} data.peers The number of valid peers. */ $dbVersion = $db->single("SELECT val FROM config WHERE cfg='dbversion'"); $hostname = $db->single("SELECT val FROM config WHERE cfg='hostname'"); @@ -719,7 +720,7 @@ if ($q == "getAddress") { $tr = $db->single("SELECT COUNT(1) FROM transactions"); $masternodes = $db->single("SELECT COUNT(1) FROM masternode"); $mempool = $db->single("SELECT COUNT(1) FROM mempool"); - + $peers = $db->single("SELECT COUNT(1) FROM peers WHERE blacklisted $hostname, 'version' => VERSION, @@ -728,7 +729,38 @@ if ($q == "getAddress") { 'transactions' => $tr, 'mempool' => $mempool, 'masternodes' => $masternodes, + 'peers' => $peers ]); +} elseif ($q === 'checkAddress') { + /** + * @api {get} /api.php?q=checkAddress 22. checkAddress + * @apiName node-info + * @apiGroup API + * @apiDescription Checks the validity of an address. + * + * @apiParam {string} account Account id / address + * @apiParam {string} [public_key] Public key + * + * @apiSuccess {boolean} data True if the address is valid, false otherwise. + */ + + $address=$data['account']; + $public_key=$data['public_key']; + $acc = new Account(); + if (!$acc->valid($address)) { + api_err(false); + } + + $dst_b = base58_decode($address); + if (strlen($dst_b) != 64) { + api_err(false); + } + if (!empty($public_key)) { + if($acc->get_address($public_key)!=$address){ + api_err(false); + } + } + api_echo(true); } else { api_err("Invalid request"); } diff --git a/doc/api_data.js b/doc/api_data.js index 754125c..1acf343 100644 --- a/doc/api_data.js +++ b/doc/api_data.js @@ -1015,6 +1015,50 @@ define({ "api": [ "filename": "./api.php", "groupTitle": "API" }, + { + "type": "get", + "url": "/api.php?q=checkAddress", + "title": "22. checkAddress", + "name": "node_info", + "group": "API", + "description": "

Checks the validity of an address.

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "string", + "optional": false, + "field": "account", + "description": "

Account id / address

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "public_key", + "description": "

Public key

" + } + ] + } + }, + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "type": "boolean", + "optional": false, + "field": "data", + "description": "

True if the address is valid, false otherwise.

" + } + ] + } + }, + "version": "0.0.0", + "filename": "./api.php", + "groupTitle": "API" + }, { "type": "get", "url": "/api.php?q=node-info", @@ -1080,6 +1124,13 @@ define({ "api": [ "optional": false, "field": "data.masternodes", "description": "

The number of masternodes known by the node.

" + }, + { + "group": "Success 200", + "type": "number", + "optional": false, + "field": "data.peers", + "description": "

The number of valid peers.

" } ] } @@ -1301,34 +1352,6 @@ define({ "api": [ "filename": "./api.php", "groupTitle": "API" }, - { - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "optional": false, - "field": "varname1", - "description": "

No type.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "varname2", - "description": "

With type.

" - } - ] - } - }, - "type": "", - "url": "", - "version": "0.0.0", - "filename": "./doc/main.js", - "group": "C__Users_owen_voke_Documents_GitHub_php_arionum_node_doc_main_js", - "groupTitle": "C__Users_owen_voke_Documents_GitHub_php_arionum_node_doc_main_js", - "name": "" - }, { "type": "php util.php", "url": "balance", @@ -1835,5 +1858,33 @@ define({ "api": [ "version": "0.0.0", "filename": "./util.php", "groupTitle": "UTIL" + }, + { + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "optional": false, + "field": "varname1", + "description": "

No type.

" + }, + { + "group": "Success 200", + "type": "String", + "optional": false, + "field": "varname2", + "description": "

With type.

" + } + ] + } + }, + "type": "", + "url": "", + "version": "0.0.0", + "filename": "./doc/main.js", + "group": "_github_node_doc_main_js", + "groupTitle": "_github_node_doc_main_js", + "name": "" } ] }); diff --git a/doc/api_data.json b/doc/api_data.json index c5a722d..f9bb35a 100644 --- a/doc/api_data.json +++ b/doc/api_data.json @@ -1015,6 +1015,50 @@ "filename": "./api.php", "groupTitle": "API" }, + { + "type": "get", + "url": "/api.php?q=checkAddress", + "title": "22. checkAddress", + "name": "node_info", + "group": "API", + "description": "

Checks the validity of an address.

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "string", + "optional": false, + "field": "account", + "description": "

Account id / address

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "public_key", + "description": "

Public key

" + } + ] + } + }, + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "type": "boolean", + "optional": false, + "field": "data", + "description": "

True if the address is valid, false otherwise.

" + } + ] + } + }, + "version": "0.0.0", + "filename": "./api.php", + "groupTitle": "API" + }, { "type": "get", "url": "/api.php?q=node-info", @@ -1080,6 +1124,13 @@ "optional": false, "field": "data.masternodes", "description": "

The number of masternodes known by the node.

" + }, + { + "group": "Success 200", + "type": "number", + "optional": false, + "field": "data.peers", + "description": "

The number of valid peers.

" } ] } @@ -1301,34 +1352,6 @@ "filename": "./api.php", "groupTitle": "API" }, - { - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "optional": false, - "field": "varname1", - "description": "

No type.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "varname2", - "description": "

With type.

" - } - ] - } - }, - "type": "", - "url": "", - "version": "0.0.0", - "filename": "./doc/main.js", - "group": "C__Users_owen_voke_Documents_GitHub_php_arionum_node_doc_main_js", - "groupTitle": "C__Users_owen_voke_Documents_GitHub_php_arionum_node_doc_main_js", - "name": "" - }, { "type": "php util.php", "url": "balance", @@ -1835,5 +1858,33 @@ "version": "0.0.0", "filename": "./util.php", "groupTitle": "UTIL" + }, + { + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "optional": false, + "field": "varname1", + "description": "

No type.

" + }, + { + "group": "Success 200", + "type": "String", + "optional": false, + "field": "varname2", + "description": "

With type.

" + } + ] + } + }, + "type": "", + "url": "", + "version": "0.0.0", + "filename": "./doc/main.js", + "group": "_github_node_doc_main_js", + "groupTitle": "_github_node_doc_main_js", + "name": "" } ] diff --git a/doc/api_project.js b/doc/api_project.js index 7485b95..dab4369 100644 --- a/doc/api_project.js +++ b/doc/api_project.js @@ -1,14 +1,13 @@ define({ - "name": "Arionum Node", + "name": "", "version": "0.0.0", - "description": "The Arionum Node API and utility documentation.", - "title": "Arionum Node", + "description": "", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2018-10-12T11:08:47.065Z", + "time": "2018-11-05T09:41:33.896Z", "url": "http://apidocjs.com", "version": "0.17.6" } diff --git a/doc/api_project.json b/doc/api_project.json index b9f6676..45b3f2d 100644 --- a/doc/api_project.json +++ b/doc/api_project.json @@ -1,14 +1,13 @@ { - "name": "Arionum Node", + "name": "", "version": "0.0.0", - "description": "The Arionum Node API and utility documentation.", - "title": "Arionum Node", + "description": "", "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2018-10-12T11:08:47.065Z", + "time": "2018-11-05T09:41:33.896Z", "url": "http://apidocjs.com", "version": "0.17.6" }