From 149601dda7b05e090b8cd6acbae3688acdaf5e9f Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sun, 28 Apr 2019 22:58:05 -0600 Subject: [PATCH] server: Allow storing empty addresses on transaction inputs/outputs --- .../anorm/dao/TransactionInputPostgresDAO.scala | 2 +- .../anorm/dao/TransactionOutputPostgresDAO.scala | 2 +- .../data/TransactionPostgresDataHandlerSpec.scala | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala b/server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala index 2f91395..811a998 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala @@ -35,7 +35,7 @@ class TransactionInputPostgresDAO { |INSERT INTO transaction_inputs | (txid, index, from_txid, from_output_index, value, addresses) |VALUES - | ({txid}, {index}, {from_txid}, {from_output_index}, {value}, ARRAY[{addresses}]) + | ({txid}, {index}, {from_txid}, {from_output_index}, {value}, ARRAY[{addresses}]::TEXT[]) """.stripMargin, params.head, params.tail: _* diff --git a/server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala b/server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala index 51fdcbc..2fc3aca 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala @@ -61,7 +61,7 @@ class TransactionOutputPostgresDAO { |INSERT INTO transaction_outputs | (txid, index, value, addresses, hex_script) |VALUES - | ({txid}, {index}, {value}, ARRAY[{addresses}], {hex_script}) + | ({txid}, {index}, {value}, ARRAY[{addresses}]::TEXT[], {hex_script}) """.stripMargin, params.head, params.tail: _* diff --git a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala index c19413d..703b8ad 100644 --- a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala @@ -52,6 +52,19 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be result mustEqual Good(expected) } + "find no results - no address involved" in { + val tx = transaction.copy( + inputs = transaction.inputs.map(_.copy(addresses = List.empty)), + outputs = transaction.outputs.map(_.copy(addresses = List.empty)) + ) + upsertTransaction(tx) + + val expected = PaginatedResult(query.offset, query.limit, Count(0), List.empty) + val result = dataHandler.getBy(randomAddress, query, defaultOrdering) + + result mustEqual Good(expected) + } + "find the right values" in { upsertTransaction(transaction)