diff --git a/api.php b/api.php index ee716c8..94a7429 100755 --- a/api.php +++ b/api.php @@ -482,6 +482,37 @@ elseif($q=="getTransactions"){ $res=$db->single("SELECT COUNT(1) FROM mempool"); api_echo($res); +} elseif($q=='randomNumber'){ +/** + * @api {get} /api.php?q=randomNumber 16. randomNumber + * @apiName randomNumber + * @apiGroup API + * @apiDescription Returns a random number based on an ARO block id. + * + * @apiParam {numeric} height The height of the block on which the random number will be based on (should be a future block when starting) + * @apiParam {numeric} min Minimum number (default 1) + * @apiParam {numeric} max Maximum number + * @apiParam {string} seed A seed to generate different numbers for each use cases. + * @apiSuccess {numeric} data The random number + */ + + $height=san($_GET['height']); + $max=intval($_GET['max']); + if(empty($_GET['min'])) $min=1; + else $min=intval($_GET['min']); + + $blk=$db->single("SELECT id FROM blocks WHERE height=:h",array(":h"=>$height)); + if($blk===false) api_err("Unknown block. Future?"); + $base=hash("sha256",$blk.$_GET['seed']); + + $seed1=hexdec(substr($base,0,12)); + // generate random numbers based on the seed + mt_srand($seed1,MT_RAND_MT19937 ); + $res=mt_rand($min, $max); + api_echo($res); + + + } else { api_err("Invalid request"); } diff --git a/doc/api_data.js b/doc/api_data.js index 052e013..d6b50a6 100644 --- a/doc/api_data.js +++ b/doc/api_data.js @@ -420,7 +420,7 @@ define({ "api": [ "group": "Success 200", "type": "numeric", "optional": false, - "field": "confirmation", + "field": "confirmations", "description": "

Number of confirmations

" }, { @@ -771,7 +771,7 @@ define({ "api": [ "group": "Success 200", "type": "numeric", "optional": false, - "field": "confirmations", + "field": "confirmation", "description": "

Number of confirmations

" }, { @@ -889,6 +889,64 @@ define({ "api": [ "filename": "./api.php", "groupTitle": "API" }, + { + "type": "get", + "url": "/api.php?q=randomNumber", + "title": "16. randomNumber", + "name": "randomNumber", + "group": "API", + "description": "

Returns a random number based on an ARO block id.

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "height", + "description": "

The height of the block on which the random number will be based on (should be a future block when starting)

" + }, + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "min", + "description": "

Minimum number (default 1)

" + }, + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "max", + "description": "

Maximum number

" + }, + { + "group": "Parameter", + "type": "string", + "optional": false, + "field": "seed", + "description": "

A seed to generate different numbers for each use cases.

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

The random number

" + } + ] + } + }, + "version": "0.0.0", + "filename": "./api.php", + "groupTitle": "API" + }, { "type": "get", "url": "/api.php?q=send", diff --git a/doc/api_data.json b/doc/api_data.json index 30770db..ea1fcdb 100644 --- a/doc/api_data.json +++ b/doc/api_data.json @@ -420,7 +420,7 @@ "group": "Success 200", "type": "numeric", "optional": false, - "field": "confirmation", + "field": "confirmations", "description": "

Number of confirmations

" }, { @@ -889,6 +889,64 @@ "filename": "./api.php", "groupTitle": "API" }, + { + "type": "get", + "url": "/api.php?q=randomNumber", + "title": "16. randomNumber", + "name": "randomNumber", + "group": "API", + "description": "

Returns a random number based on an ARO block id.

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "height", + "description": "

The height of the block on which the random number will be based on (should be a future block when starting)

" + }, + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "min", + "description": "

Minimum number (default 1)

" + }, + { + "group": "Parameter", + "type": "numeric", + "optional": false, + "field": "max", + "description": "

Maximum number

" + }, + { + "group": "Parameter", + "type": "string", + "optional": false, + "field": "seed", + "description": "

A seed to generate different numbers for each use cases.

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

The random number

" + } + ] + } + }, + "version": "0.0.0", + "filename": "./api.php", + "groupTitle": "API" + }, { "type": "get", "url": "/api.php?q=send", diff --git a/doc/api_project.js b/doc/api_project.js index 8fdce80..657dda9 100644 --- a/doc/api_project.js +++ b/doc/api_project.js @@ -7,7 +7,7 @@ define({ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2018-02-22T16:13:41.713Z", + "time": "2018-05-09T23:01:25.347Z", "url": "http://apidocjs.com", "version": "0.17.6" } diff --git a/doc/api_project.json b/doc/api_project.json index d526897..361fb2b 100644 --- a/doc/api_project.json +++ b/doc/api_project.json @@ -7,7 +7,7 @@ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2018-02-22T16:13:41.713Z", + "time": "2018-05-09T23:01:25.347Z", "url": "http://apidocjs.com", "version": "0.17.6" }