From 1edc128b61e439a0bcdeb9b285b4db8e4f84fe6b Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Fri, 21 Dec 2018 15:51:36 +0100 Subject: [PATCH] Address balance API --- src/Controller/MainController.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 055dc98..148537d 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -731,6 +731,7 @@ class MainController extends AppController { public function apiaddrbalance($base58address = null) { $this->autoRender = false; $this->loadModel('Addresses'); + $this->loadModel('TransactionAddress'); if (!isset($base58address)) { return $this->_jsonError('Base58 address not specified.', 400); @@ -740,12 +741,8 @@ class MainController extends AppController { if (!$address) { return $this->_jsonError('Could not find address.', 400); } - $conn = ConnectionManager::get('default'); - $stmt = $conn->execute(sprintf( - 'SELECT TA.debit_amount, TA.credit_amount, ' . - 'FROM transaction_address TA' . - 'WHERE TA.address_id = ?'), [$address->id]); - $transaction_addresses = $stmt->fetchAll(\PDO::FETCH_OBJ); + + $transaction_addresses = $this->TransactionAddress->find()->where(['address_id' => $address->id])->toArray(); $balance = 0; foreach($transaction_addresses as $ta) { $balance += $ta->credit_amount;