Add mining rewards to getBlockTransactions
This commit is contained in:
10
api.php
10
api.php
@@ -343,6 +343,7 @@ if ($q == "getAddress") {
|
||||
*
|
||||
* @apiParam {numeric} [height] Block Height
|
||||
* @apiParam {string} [block] Block id
|
||||
* @apiParam {boolean} [includeMiningRewards] Include mining rewards
|
||||
*
|
||||
* @apiSuccess {string} block Block ID
|
||||
* @apiSuccess {numeric} confirmations Number of confirmations
|
||||
@@ -361,7 +362,14 @@ if ($q == "getAddress") {
|
||||
*/
|
||||
$height = san($data['height']);
|
||||
$block = san($data['block']);
|
||||
$ret = $trx->get_transactions($height, $block);
|
||||
$includeMiningRewards = san($data['includeMiningRewards'] ?? '');
|
||||
if(empty($includeMiningRewards) || $includeMiningRewards == '0' || $includeMiningRewards == 'false')
|
||||
$includeMiningRewards = false;
|
||||
else
|
||||
$includeMiningRewards = true;
|
||||
|
||||
$ret = $trx->get_transactions($height, $block, $includeMiningRewards);
|
||||
|
||||
if ($ret === false) {
|
||||
api_err("Invalid block");
|
||||
} else {
|
||||
|
||||
@@ -548,6 +548,13 @@ define({ "api": [
|
||||
"optional": true,
|
||||
"field": "block",
|
||||
"description": "<p>Block id</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"field": "includeMiningRewards",
|
||||
"description": "<p>Include mining rewards</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -548,6 +548,13 @@
|
||||
"optional": true,
|
||||
"field": "block",
|
||||
"description": "<p>Block id</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"field": "includeMiningRewards",
|
||||
"description": "<p>Include mining rewards</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ class Transaction
|
||||
}
|
||||
|
||||
// return the transactions for a specific block id or height
|
||||
public function get_transactions($height = "", $id = "")
|
||||
public function get_transactions($height = "", $id = "", $includeMiningRewards = false)
|
||||
{
|
||||
global $db;
|
||||
$block = new Block();
|
||||
@@ -612,10 +612,11 @@ class Transaction
|
||||
if (empty($id) && empty($height)) {
|
||||
return false;
|
||||
}
|
||||
$version_limit = $includeMiningRewards ? 0 : 1;
|
||||
if (!empty($id)) {
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:id AND version>0", [":id" => $id]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE block=:id AND version >= :version", [":id" => $id, ":version" => $version_limit]);
|
||||
} else {
|
||||
$r = $db->run("SELECT * FROM transactions WHERE height=:height AND version>0", [":height" => $height]);
|
||||
$r = $db->run("SELECT * FROM transactions WHERE height=:height AND version >= :version", [":height" => $height, ":version" => $version_limit]);
|
||||
}
|
||||
$res = [];
|
||||
foreach ($r as $x) {
|
||||
|
||||
Reference in New Issue
Block a user