From 4355a0347f5a722ed006d84d467a6a730ec0a201 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 23 Jun 2018 17:25:37 -0500 Subject: [PATCH] server: Update the "GET /addresses/:address/transactions" Now it returns the transaction values where the address was involved. --- .../explorer/data/anorm/dao/TransactionPostgresDAO.scala | 4 ++-- .../explorer/data/TransactionPostgresDataHandlerSpec.scala | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala b/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala index bb04f3f..b8cc713 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala @@ -83,8 +83,8 @@ class TransactionPostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderi SQL( s""" |SELECT t.txid, blockhash, time, size, - | (SELECT COALESCE(SUM(value), 0) FROM transaction_inputs WHERE txid = t.txid) AS sent, - | (SELECT COALESCE(SUM(value), 0) FROM transaction_outputs WHERE txid = t.txid) AS received + | (SELECT COALESCE(SUM(value), 0) FROM transaction_inputs WHERE txid = t.txid AND address = {address}) AS sent, + | (SELECT COALESCE(SUM(value), 0) FROM transaction_outputs WHERE txid = t.txid AND address = {address}) AS received |FROM transactions t |WHERE t.txid IN ( | SELECT txid diff --git a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala index 2203fea..27c0bb5 100644 --- a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala @@ -85,14 +85,15 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec { val address = createAddress("XxQ7j37LfuXgsLd5DZAwFKhT3s2ZMkW86F") val inputs = List( Transaction.Input(0, None, None), - Transaction.Input(1, Some(BigDecimal(100)), Some(address)) + Transaction.Input(1, Some(BigDecimal(100)), Some(address)), + Transaction.Input(2, Some(BigDecimal(200)), Some(createAddress("XxQ7j37LfuXgsLD5DZAwFKhT3s2ZMkW86F"))) ) val outputs = List( Transaction.Output(0, BigDecimal(50), address, None, None), Transaction.Output( 1, - BigDecimal(150), + BigDecimal(250), createAddress("Xbh5pJdBNm8J9PxnEmwVcuQKRmZZ7DkpcF"), None, None) ) @@ -118,7 +119,7 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec { val transactionWithValues = TransactionWithValues( transaction.id, transaction.blockhash, transaction.time, transaction.size, sent = 100, - received = 200) + received = 50) val expected = PaginatedResult(query.offset, query.limit, Count(1), List(transactionWithValues)) dataHandler.upsert(transaction).isGood mustEqual true