Merge pull request #44 from bogdanadnan/master

Add mining rewards to getBlockTransactions
This commit is contained in:
arionum
2019-03-24 09:37:01 +02:00
committed by GitHub
4 changed files with 26 additions and 4 deletions

View File

@@ -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,13 @@ if ($q == "getAddress") {
*/
$height = san($data['height']);
$block = san($data['block']);
$ret = $trx->get_transactions($height, $block);
$includeMiningRewards = (
isset($data['includeMiningRewards']) &&
!($data['includeMiningRewards'] === '0' || $data['includeMiningRewards'] === 'false')
);
$ret = $trx->get_transactions($height, $block, $includeMiningRewards);
if ($ret === false) {
api_err("Invalid block");
} else {

View File

@@ -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>"
}
]
}

View File

@@ -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>"
}
]
}

View File

@@ -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;
}
$versionLimit = $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" => $versionLimit]);
} 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" => $versionLimit]);
}
$res = [];
foreach ($r as $x) {