Browse Source

server: Update the "GET /addresses/:address/transactions"

Now it returns the transaction values where the address was involved.
prometheus-integration
Alexis Hernandez 7 years ago
parent
commit
4355a0347f
  1. 4
      server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala
  2. 7
      server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala

4
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

7
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

Loading…
Cancel
Save