Add mining rewards to getBlockTransactions

This commit is contained in:
bogdanadnan
2019-02-07 21:03:23 +02:00
parent d03cd9e9f6
commit 12fa045ba3
4 changed files with 27 additions and 4 deletions

10
api.php
View File

@@ -343,6 +343,7 @@ if ($q == "getAddress") {
* *
* @apiParam {numeric} [height] Block Height * @apiParam {numeric} [height] Block Height
* @apiParam {string} [block] Block id * @apiParam {string} [block] Block id
* @apiParam {boolean} [includeMiningRewards] Include mining rewards
* *
* @apiSuccess {string} block Block ID * @apiSuccess {string} block Block ID
* @apiSuccess {numeric} confirmations Number of confirmations * @apiSuccess {numeric} confirmations Number of confirmations
@@ -361,7 +362,14 @@ if ($q == "getAddress") {
*/ */
$height = san($data['height']); $height = san($data['height']);
$block = san($data['block']); $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) { if ($ret === false) {
api_err("Invalid block"); api_err("Invalid block");
} else { } else {

View File

@@ -548,6 +548,13 @@ define({ "api": [
"optional": true, "optional": true,
"field": "block", "field": "block",
"description": "<p>Block id</p>" "description": "<p>Block id</p>"
},
{
"group": "Parameter",
"type": "boolean",
"optional": true,
"field": "includeMiningRewards",
"description": "<p>Include mining rewards</p>"
} }
] ]
} }

View File

@@ -548,6 +548,13 @@
"optional": true, "optional": true,
"field": "block", "field": "block",
"description": "<p>Block id</p>" "description": "<p>Block id</p>"
},
{
"group": "Parameter",
"type": "boolean",
"optional": true,
"field": "includeMiningRewards",
"description": "<p>Include mining rewards</p>"
} }
] ]
} }

View File

@@ -601,7 +601,7 @@ class Transaction
} }
// return the transactions for a specific block id or height // 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; global $db;
$block = new Block(); $block = new Block();
@@ -612,10 +612,11 @@ class Transaction
if (empty($id) && empty($height)) { if (empty($id) && empty($height)) {
return false; return false;
} }
$version_limit = $includeMiningRewards ? 0 : 1;
if (!empty($id)) { 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 { } 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 = []; $res = [];
foreach ($r as $x) { foreach ($r as $x) {