From 7410645ca8b0779a43a3ad3ebb737ee529d1ba33 Mon Sep 17 00:00:00 2001 From: Arionum Date: Thu, 15 Feb 2018 01:10:49 +0200 Subject: [PATCH] transactions limit api --- api.php | 3 ++- include/account.inc.php | 6 ++++-- util.php | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api.php b/api.php index fd48c88..e0a4ffe 100755 --- a/api.php +++ b/api.php @@ -68,8 +68,9 @@ elseif($q=="getPendingBalance"){ } elseif($q=="getTransactions"){ $account=san($data['account']); + $limit=intval($data['limit']); $transactions=$acc->get_mempool_transactions($account); - $transactions=array_merge($transactions, $acc->get_transactions($account)); + $transactions=array_merge($transactions, $acc->get_transactions($account,$limit)); api_echo($transactions); } diff --git a/include/account.inc.php b/include/account.inc.php index 36f4391..ea3d958 100755 --- a/include/account.inc.php +++ b/include/account.inc.php @@ -88,12 +88,14 @@ class Account { return number_format($rez,8,".",""); } - public function get_transactions($id){ + public function get_transactions($id,$limit=100){ global $db; $block=new Block; $current=$block->current(); $public_key=$this->public_key($id); - $res=$db->run("SELECT * FROM transactions WHERE dst=:dst or public_key=:src ORDER by height DESC LIMIT 100",array(":src"=>$public_key, ":dst"=>$id)); + $limit=intval($limit); + if($limit>100||$limit<1) $limit=100; + $res=$db->run("SELECT * FROM transactions WHERE dst=:dst or public_key=:src ORDER by height DESC LIMIT :limit",array(":src"=>$public_key, ":dst"=>$id, ":limit"=>$limit)); $transactions=array(); foreach($res as $x){ diff --git a/util.php b/util.php index 12d3081..e88875f 100755 --- a/util.php +++ b/util.php @@ -135,6 +135,11 @@ echo "Mempool size: $res\n"; $res=$db->single("SELECT balance FROM accounts WHERE id=:id OR public_key=:id2 LIMIT 1",array(":id"=>$id, ":id2"=>$id)); echo "Balance: ".number_format($res)."\n"; +}elseif($cmd=="block"){ + $id=san($argv[2]); + $res=$db->row("SELECT * FROM blocks WHERE id=:id OR height=:id2 LIMIT 1",array(":id"=>$id, ":id2"=>$id)); + + var_dump($res); } else { echo "Invalid command\n";