diff --git a/server/app/com/xsn/explorer/data/BalanceDataHandler.scala b/server/app/com/xsn/explorer/data/BalanceDataHandler.scala index d92732b4..b746b71e 100644 --- a/server/app/com/xsn/explorer/data/BalanceDataHandler.scala +++ b/server/app/com/xsn/explorer/data/BalanceDataHandler.scala @@ -17,8 +17,6 @@ trait BalanceDataHandler[F[_]] { def getBy(address: Address): F[Balance] - def getNonZeroBalances(query: PaginatedQuery, ordering: FieldOrdering[BalanceField]): F[PaginatedResult[Balance]] - def getHighestBalances(limit: Limit, lastSeenAddress: Option[Address]): F[List[Balance]] } diff --git a/server/app/com/xsn/explorer/data/TransactionDataHandler.scala b/server/app/com/xsn/explorer/data/TransactionDataHandler.scala index a5f61457..d1f88be2 100644 --- a/server/app/com/xsn/explorer/data/TransactionDataHandler.scala +++ b/server/app/com/xsn/explorer/data/TransactionDataHandler.scala @@ -12,12 +12,6 @@ import scala.language.higherKinds trait TransactionDataHandler[F[_]] { - def getBy( - address: Address, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): F[PaginatedResult[TransactionWithValues]] - def getBy( address: Address, limit: Limit, @@ -29,12 +23,6 @@ trait TransactionDataHandler[F[_]] { def getOutput(txid: TransactionId, index: Int): F[Transaction.Output] - def getByBlockhash( - blockhash: Blockhash, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): F[PaginatedResult[TransactionWithValues]] - def getByBlockhash( blockhash: Blockhash, limit: Limit, diff --git a/server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala b/server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala index 5ed70f50..2207f99c 100644 --- a/server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala +++ b/server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala @@ -42,17 +42,6 @@ class BalancePostgresDataHandler @Inject()(override val database: Database, bala Good(balance) } - override def getNonZeroBalances( - query: PaginatedQuery, - ordering: FieldOrdering[BalanceField] - ): ApplicationResult[PaginatedResult[Balance]] = withConnection { implicit conn => - val balances = balancePostgresDAO.getNonZeroBalances(query, ordering) - val total = balancePostgresDAO.countNonZeroBalances - val result = PaginatedResult(query.offset, query.limit, total, balances) - - Good(result) - } - override def getHighestBalances(limit: Limit, lastSeenAddress: Option[Address]): ApplicationResult[List[Balance]] = withConnection { implicit conn => val result = lastSeenAddress diff --git a/server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala b/server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala index a8f5e8e3..7dd98092 100644 --- a/server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala +++ b/server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala @@ -21,18 +21,6 @@ class TransactionPostgresDataHandler @Inject()( ) extends TransactionBlockingDataHandler with AnormPostgresDataHandler { - override def getBy( - address: Address, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): ApplicationResult[PaginatedResult[TransactionWithValues]] = withConnection { implicit conn => - val transactions = transactionPostgresDAO.getBy(address, paginatedQuery, ordering) - val total = transactionPostgresDAO.countBy(address) - val result = PaginatedResult(paginatedQuery.offset, paginatedQuery.limit, total, transactions) - - Good(result) - } - def getBy( address: Address, limit: Limit, @@ -58,18 +46,6 @@ class TransactionPostgresDataHandler @Inject()( Or.from(maybe, One(TransactionError.OutputNotFound(txid, index))) } - override def getByBlockhash( - blockhash: Blockhash, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): ApplicationResult[PaginatedResult[TransactionWithValues]] = withConnection { implicit conn => - val transactions = transactionPostgresDAO.getByBlockhash(blockhash, paginatedQuery, ordering) - val total = transactionPostgresDAO.countByBlockhash(blockhash) - val result = PaginatedResult(paginatedQuery.offset, paginatedQuery.limit, total, transactions) - - Good(result) - } - override def getByBlockhash( blockhash: Blockhash, limit: Limit, diff --git a/server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala b/server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala index 160336d1..38e29a45 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala @@ -62,30 +62,6 @@ class BalancePostgresDAO @Inject()(fieldOrderingSQLInterpreter: FieldOrderingSQL .as(parseBalance.*) } - def getNonZeroBalances(query: PaginatedQuery, ordering: FieldOrdering[BalanceField])( - implicit conn: Connection - ): List[Balance] = { - - val orderBy = fieldOrderingSQLInterpreter.toOrderByClause(ordering) - SQL( - s""" - |SELECT address, received, spent - |FROM balances - |WHERE address NOT IN ( - | SELECT address - | FROM hidden_addresses) AND - | (received - spent) > 0 - |$orderBy - |OFFSET {offset} - |LIMIT {limit} - """.stripMargin - ).on( - 'offset -> query.offset.int, - 'limit -> query.limit.int - ) - .as(parseBalance.*) - } - def count(implicit conn: Connection): Count = { val result = SQL( """ @@ -114,21 +90,6 @@ class BalancePostgresDAO @Inject()(fieldOrderingSQLInterpreter: FieldOrderingSQL .as(parseBalance.singleOpt) } - def countNonZeroBalances(implicit conn: Connection): Count = { - val result = SQL( - """ - |SELECT COUNT(*) - |FROM balances - |WHERE address NOT IN ( - | SELECT address - | FROM hidden_addresses) AND - | (received - spent) > 0 - """.stripMargin - ).as(SqlParser.scalar[Int].single) - - Count(result) - } - /** * Get the highest balances (excluding hidden_addresses). */ 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 197b7e2e..e1433465 100644 --- a/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala +++ b/server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala @@ -3,13 +3,12 @@ package com.xsn.explorer.data.anorm.dao import java.sql.Connection import anorm._ -import com.alexitc.playsonify.models.ordering.{FieldOrdering, OrderingCondition} -import com.alexitc.playsonify.models.pagination.{Count, Limit, PaginatedQuery} +import com.alexitc.playsonify.models.ordering.OrderingCondition +import com.alexitc.playsonify.models.pagination.{Count, Limit} import com.alexitc.playsonify.sql.FieldOrderingSQLInterpreter import com.xsn.explorer.config.ExplorerConfig import com.xsn.explorer.data.anorm.parsers.TransactionParsers._ import com.xsn.explorer.models._ -import com.xsn.explorer.models.fields.TransactionField import com.xsn.explorer.models.persisted.Transaction import com.xsn.explorer.models.values.{Address, Blockhash, TransactionId} import javax.inject.Inject @@ -257,75 +256,6 @@ class TransactionPostgresDAO @Inject()( } } - def getBy(address: Address, paginatedQuery: PaginatedQuery, ordering: FieldOrdering[TransactionField])( - implicit conn: Connection - ): List[TransactionWithValues] = { - - val orderBy = fieldOrderingSQLInterpreter.toOrderByClause(ordering) - - SQL( - s""" - |SELECT t.txid, t.blockhash, t.time, t.size, a.sent, a.received - |FROM transactions t - |INNER JOIN address_transaction_details a USING (txid) - |WHERE a.address = {address} - |$orderBy - |OFFSET {offset} - |LIMIT {limit} - """.stripMargin - ).on( - 'address -> address.string, - 'offset -> paginatedQuery.offset.int, - 'limit -> paginatedQuery.limit.int - ) - .as(parseTransactionWithValues.*) - } - - def countBy(address: Address)(implicit conn: Connection): Count = { - val result = SQL( - """ - | SELECT COUNT(*) - | FROM address_transaction_details - | WHERE address = {address} - """.stripMargin - ).on( - 'address -> address.string - ) - .as(SqlParser.scalar[Int].single) - - Count(result) - } - - def getByBlockhash(blockhash: Blockhash, paginatedQuery: PaginatedQuery, ordering: FieldOrdering[TransactionField])( - implicit conn: Connection - ): List[TransactionWithValues] = { - - val orderBy = fieldOrderingSQLInterpreter.toOrderByClause(ordering) - - /** - * TODO: The query is very slow while aggregating the spent and received values, - * it might be worth creating an index-like table to get the accumulated - * values directly. - */ - SQL( - s""" - |SELECT t.txid, blockhash, t.time, t.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 - |FROM transactions t JOIN blocks USING (blockhash) - |WHERE blockhash = {blockhash} - |$orderBy - |OFFSET {offset} - |LIMIT {limit} - """.stripMargin - ).on( - 'blockhash -> blockhash.string, - 'offset -> paginatedQuery.offset.int, - 'limit -> paginatedQuery.limit.int - ) - .as(parseTransactionWithValues.*) - } - def countByBlockhash(blockhash: Blockhash)(implicit conn: Connection): Count = { val result = SQL( """ diff --git a/server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala b/server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala index 7937b1bf..fac4745c 100644 --- a/server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala +++ b/server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala @@ -30,14 +30,6 @@ class BalanceFutureDataHandler @Inject()(blockingDataHandler: BalanceBlockingDat blockingDataHandler.getBy(address) } - override def getNonZeroBalances( - query: PaginatedQuery, - ordering: FieldOrdering[BalanceField] - ): FuturePaginatedResult[Balance] = Future { - - blockingDataHandler.getNonZeroBalances(query, ordering) - } - override def getHighestBalances( limit: pagination.Limit, lastSeenAddress: Option[Address] diff --git a/server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala b/server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala index 54247ad2..4ddf3e58 100644 --- a/server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala +++ b/server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala @@ -17,15 +17,6 @@ class TransactionFutureDataHandler @Inject()(blockingDataHandler: TransactionBlo implicit ec: DatabaseExecutionContext ) extends TransactionDataHandler[FutureApplicationResult] { - override def getBy( - address: Address, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): FuturePaginatedResult[TransactionWithValues] = Future { - - blockingDataHandler.getBy(address, paginatedQuery, ordering) - } - override def getBy( address: Address, limit: Limit, @@ -44,15 +35,6 @@ class TransactionFutureDataHandler @Inject()(blockingDataHandler: TransactionBlo blockingDataHandler.getOutput(txid, index) } - override def getByBlockhash( - blockhash: Blockhash, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): FuturePaginatedResult[TransactionWithValues] = Future { - - blockingDataHandler.getByBlockhash(blockhash, paginatedQuery, ordering) - } - override def getByBlockhash( blockhash: Blockhash, limit: Limit, diff --git a/server/app/com/xsn/explorer/services/BalanceService.scala b/server/app/com/xsn/explorer/services/BalanceService.scala index 9ccd0316..36ee995d 100644 --- a/server/app/com/xsn/explorer/services/BalanceService.scala +++ b/server/app/com/xsn/explorer/services/BalanceService.scala @@ -21,16 +21,6 @@ class BalanceService @Inject()( balanceFutureDataHandler: BalanceFutureDataHandler )(implicit ec: ExecutionContext) { - def get(paginatedQuery: PaginatedQuery, orderingQuery: OrderingQuery): FuturePaginatedResult[Balance] = { - val result = for { - validatedQuery <- paginatedQueryValidator.validate(paginatedQuery, 100).toFutureOr - ordering <- balanceOrderingParser.from(orderingQuery).toFutureOr - balances <- balanceFutureDataHandler.getNonZeroBalances(validatedQuery, ordering).toFutureOr - } yield balances - - result.toFuture - } - def getHighest( limit: Limit, lastSeenAddressString: Option[String] diff --git a/server/app/com/xsn/explorer/services/TransactionService.scala b/server/app/com/xsn/explorer/services/TransactionService.scala index 2cca3d63..9c9043e5 100644 --- a/server/app/com/xsn/explorer/services/TransactionService.scala +++ b/server/app/com/xsn/explorer/services/TransactionService.scala @@ -29,22 +29,6 @@ class TransactionService @Inject()( private val maxTransactionsPerQuery = 100 - def getTransactions( - addressString: String, - paginatedQuery: PaginatedQuery, - orderingQuery: OrderingQuery - ): FuturePaginatedResult[TransactionWithValues] = { - - val result = for { - address <- addressValidator.validate(addressString).toFutureOr - paginatedQuery <- paginatedQueryValidator.validate(paginatedQuery, maxTransactionsPerQuery).toFutureOr - ordering <- transactionOrderingParser.from(orderingQuery).toFutureOr - transactions <- transactionFutureDataHandler.getBy(address, paginatedQuery, ordering).toFutureOr - } yield transactions - - result.toFuture - } - def getLightWalletTransactions( addressString: String, limit: Limit, @@ -69,21 +53,6 @@ class TransactionService @Inject()( result.toFuture } - def getByBlockhash( - blockhashString: String, - paginatedQuery: PaginatedQuery, - orderingQuery: OrderingQuery - ): FuturePaginatedResult[TransactionWithValues] = { - val result = for { - blockhash <- blockhashValidator.validate(blockhashString).toFutureOr - validatedQuery <- paginatedQueryValidator.validate(paginatedQuery, maxTransactionsPerQuery).toFutureOr - order <- transactionOrderingParser.from(orderingQuery).toFutureOr - r <- transactionFutureDataHandler.getByBlockhash(blockhash, validatedQuery, order).toFutureOr - } yield r - - result.toFuture - } - def getByBlockhash( blockhashString: String, limit: Limit, diff --git a/server/app/controllers/AddressesController.scala b/server/app/controllers/AddressesController.scala index 19b7c0a3..ed37fe70 100644 --- a/server/app/controllers/AddressesController.scala +++ b/server/app/controllers/AddressesController.scala @@ -24,12 +24,6 @@ class AddressesController @Inject()( addressService.getBy(address) } - def getTransactions(address: String, offset: Int, limit: Int, ordering: String) = public { _ => - val paginatedQuery = PaginatedQuery(Offset(offset), Limit(limit)) - - transactionService.getTransactions(address, paginatedQuery, OrderingQuery(ordering)) - } - def getLightWalletTransactions(address: String, limit: Int, lastSeenTxid: Option[String], orderingCondition: String) = public { _ => transactionService.getLightWalletTransactions(address, Limit(limit), lastSeenTxid, orderingCondition) diff --git a/server/app/controllers/BalancesController.scala b/server/app/controllers/BalancesController.scala index 5d5d9780..5f0f056a 100644 --- a/server/app/controllers/BalancesController.scala +++ b/server/app/controllers/BalancesController.scala @@ -11,13 +11,6 @@ class BalancesController @Inject()(balanceService: BalanceService, cc: MyJsonCon import Codecs._ - def get(offset: Int, limit: Int, ordering: String) = public { _ => - val paginatedQuery = PaginatedQuery(Offset(offset), Limit(limit)) - val orderingQuery = OrderingQuery(ordering) - - balanceService.get(paginatedQuery, orderingQuery) - } - def getHighest(limit: Int, lastSeenAddress: Option[String]) = public { _ => balanceService.getHighest(Limit(limit), lastSeenAddress) } diff --git a/server/app/controllers/BlocksController.scala b/server/app/controllers/BlocksController.scala index 5d661c36..c9536449 100644 --- a/server/app/controllers/BlocksController.scala +++ b/server/app/controllers/BlocksController.scala @@ -84,12 +84,6 @@ class BlocksController @Inject()( .getOrElse(blockService.getRawBlock(query)) } - def getTransactions(blockhash: String, offset: Int, limit: Int, orderBy: String) = public { _ => - val query = PaginatedQuery(Offset(offset), Limit(limit)) - val ordering = OrderingQuery(orderBy) - transactionService.getByBlockhash(blockhash, query, ordering) - } - def getTransactionsV2(blockhash: String, limit: Int, lastSeenTxid: Option[String]) = public { _ => transactionService.getByBlockhash(blockhash, Limit(limit), lastSeenTxid) } diff --git a/server/conf/routes b/server/conf/routes index 6444cd25..4e121727 100644 --- a/server/conf/routes +++ b/server/conf/routes @@ -11,7 +11,6 @@ GET /transactions/:txid/raw controllers.TransactionsController.getRawTransa POST /transactions controllers.TransactionsController.sendRawTransaction() GET /addresses/:address controllers.AddressesController.getBy(address: String) -# GET /addresses/:address/transactions controllers.AddressesController.getTransactions(address: String, offset: Int ?= 0, limit: Int ?= 10, orderBy: String ?= "") GET /addresses/:address/tposcontracts controllers.AddressesController.getTPoSContracts(address: String) GET /v2/addresses/:address/transactions controllers.AddressesController.getLightWalletTransactions(address: String, limit: Int ?= 10, lastSeenTxid: Option[String], order: String ?= "desc") GET /addresses/:address/utxos controllers.AddressesController.getUnspentOutputs(address: String) @@ -23,13 +22,11 @@ GET /blocks/estimate-fee controllers.BlocksController.estimateFe GET /blocks/:query controllers.BlocksController.getDetails(query: String) GET /blocks/:query/raw controllers.BlocksController.getRawBlock(query: String) -# GET /blocks/:blockhash/transactions controllers.BlocksController.getTransactions(blockhash: String, offset: Int ?= 0, limit: Int ?= 10, orderBy: String ?= "") GET /v2/blocks/:blockhash/transactions controllers.BlocksController.getTransactionsV2(blockhash: String, limit: Int ?= 10, lastSeenTxid: Option[String]) GET /v2/blocks/:blockhash/light-wallet-transactions controllers.BlocksController.getLightTransactionsV2(blockhash: String, limit: Int ?= 10, lastSeenTxid: Option[String]) GET /stats controllers.StatisticsController.getStatus() -# GET /balances controllers.BalancesController.get(offset: Int ?= 0, limit: Int ?= 10, orderBy: String ?= "") GET /v2/balances controllers.BalancesController.getHighest(limit: Int ?= 10, lastSeenAddress: Option[String]) GET /masternodes controllers.MasternodesController.get(offset: Int ?= 0, limit: Int ?= 10, orderBy: String ?= "") diff --git a/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala index 74f1126a..baa8f530 100644 --- a/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/BalancePostgresDataHandlerSpec.scala @@ -113,34 +113,6 @@ class BalancePostgresDataHandlerSpec extends PostgresDataHandlerSpec { } } - "getNonZeroBalances" should { - val balances = List( - Balance( - address = DataHelper.createAddress("XiHW7SR56uPHeXKwcpeVsE4nUfkHv5RqE3"), - received = BigDecimal("0"), - spent = BigDecimal("0") - ) - ).sortBy(_.available).reverse - - def prepare() = { - clearDatabase() - - balances - .map(dataHandler.upsert) - .foreach(_.isGood mustEqual true) - } - - "ignore addresses with balance = 0" in { - prepare() - val query = PaginatedQuery(Offset(0), Limit(1)) - val expected = List.empty[Balance] - - val result = dataHandler.getNonZeroBalances(query, defaultOrdering) - result.map(_.data) mustEqual Good(expected) - result.get.total.int mustEqual balances.size - 1 - } - } - "getHighestBalances" should { val balances = List( diff --git a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala index e8bbc0b2..44b39a6c 100644 --- a/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala +++ b/server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala @@ -39,51 +39,6 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be prepareTransaction(dummyTransaction) } - "getBy address" should { - val address = randomAddress - val partialTransaction = randomTransaction(blockhash = block.hash, utxos = dummyTransaction.outputs) - val outputsForAddress = partialTransaction.outputs.map { _.copy(addresses = List(address)) } - val transaction = partialTransaction.copy(outputs = outputsForAddress) - val query = PaginatedQuery(Offset(0), Limit(10)) - - "find no results" in { - val expected = PaginatedResult(query.offset, query.limit, Count(0), List.empty) - val result = dataHandler.getBy(randomAddress, query, defaultOrdering) - - 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) - - val transactionWithValues = TransactionWithValues( - transaction.id, - transaction.blockhash, - transaction.time, - transaction.size, - received = transaction.outputs.filter(_.address contains address).map(_.value).sum, - sent = transaction.inputs.filter(_.address contains address).map(_.value).sum - ) - - val expected = PaginatedResult(query.offset, query.limit, Count(1), List(transactionWithValues)) - val result = dataHandler.getBy(address, query, defaultOrdering) - result mustEqual Good(expected) - } - } - "getUnspentOutputs" should { "return non-zero results" in { clearDatabase() @@ -152,119 +107,6 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be } } - "getByBlockhash" should { - val blockhash = randomBlockhash - - val transactions = List( - randomTransaction(blockhash = blockhash, utxos = dummyTransaction.outputs), - randomTransaction(blockhash = blockhash, utxos = dummyTransaction.outputs), - randomTransaction(blockhash = blockhash, utxos = dummyTransaction.outputs) - ) - - val block = randomBlock(blockhash = blockhash).copy(transactions = transactions.map(_.id)) - - "find no results" in { - val blockhash = randomBlockhash - val query = PaginatedQuery(Offset(0), Limit(10)) - val expected = PaginatedResult(query.offset, query.limit, Count(0), List.empty) - val result = dataHandler.getByBlockhash(blockhash, query, defaultOrdering) - - result mustEqual Good(expected) - } - - "find the right values" in { - createBlock(block, transactions) - - val query = PaginatedQuery(Offset(0), Limit(10)) - val result = dataHandler.getByBlockhash(blockhash, query, defaultOrdering).get - - result.total mustEqual Count(transactions.size) - result.offset mustEqual query.offset - result.limit mustEqual query.limit - result.data.size mustEqual transactions.size - } - - def testOrdering[B](field: TransactionField, orderingCondition: OrderingCondition)( - lt: (Transaction.HasIO, Transaction.HasIO) => Boolean - ) = { - createBlock(block, transactions) - - val ordering = FieldOrdering(field, orderingCondition) - val query = PaginatedQuery(Offset(0), Limit(10)) - - val expected = transactions.sortWith(lt).map(_.id) - val result = dataHandler.getByBlockhash(blockhash, query, ordering).get.data - - result.map(_.id) mustEqual expected - } - - "allow to sort by txid" in { - testOrdering(TransactionField.TransactionId, OrderingCondition.AscendingOrder) { - case (a, b) => a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by txid - descending" in { - testOrdering(TransactionField.TransactionId, OrderingCondition.DescendingOrder) { - case (a, b) => a.id.string.compareTo(b.id.string) > 0 - } - } - - "allow to sort by time" in { - testOrdering(TransactionField.Time, OrderingCondition.AscendingOrder) { - case (a, b) => - if (a.time < b.time) true - else if (a.time > b.time) false - else a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by time - descending" in { - testOrdering(TransactionField.Time, OrderingCondition.DescendingOrder) { - case (a, b) => - if (a.time < b.time) false - else if (a.time > b.time) true - else a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by sent" in { - testOrdering(TransactionField.Sent, OrderingCondition.AscendingOrder) { - case (a, b) => - if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) true - else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) false - else a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by sent - descending" in { - testOrdering(TransactionField.Sent, OrderingCondition.DescendingOrder) { - case (a, b) => - if (a.inputs.map(_.value).sum < b.inputs.map(_.value).sum) false - else if (a.inputs.map(_.value).sum > b.inputs.map(_.value).sum) true - else a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by received" in { - testOrdering(TransactionField.Received, OrderingCondition.AscendingOrder) { - case (a, b) => - if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) true - else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) false - else a.id.string.compareTo(b.id.string) < 0 - } - } - - "allow to sort by received - descending" in { - testOrdering(TransactionField.Received, OrderingCondition.DescendingOrder) { - case (a, b) => - if (a.outputs.map(_.value).sum < b.outputs.map(_.value).sum) false - else if (a.outputs.map(_.value).sum > b.outputs.map(_.value).sum) true - else a.id.string.compareTo(b.id.string) < 0 - } - } - } - "getBy with scroll" should { val address = randomAddress val blockhash = randomBlockhash diff --git a/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala b/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala index 7c006904..983e4e75 100644 --- a/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala +++ b/server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala @@ -20,11 +20,6 @@ class BalanceDummyDataHandler extends BalanceBlockingDataHandler { override def getBy(address: Address): ApplicationResult[Balance] = ??? - override def getNonZeroBalances( - query: PaginatedQuery, - ordering: FieldOrdering[BalanceField] - ): ApplicationResult[PaginatedResult[Balance]] = ??? - override def getHighestBalances( limit: pagination.Limit, lastSeenAddress: Option[Address] diff --git a/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala b/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala index 31ec3a96..f99a31ff 100644 --- a/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala +++ b/server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala @@ -12,12 +12,6 @@ import com.xsn.explorer.models.values.{Address, Blockhash, TransactionId} class TransactionDummyDataHandler extends TransactionBlockingDataHandler { - override def getBy( - address: Address, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? - override def getBy( address: Address, limit: pagination.Limit, @@ -29,12 +23,6 @@ class TransactionDummyDataHandler extends TransactionBlockingDataHandler { override def getOutput(txid: TransactionId, index: Int): ApplicationResult[Transaction.Output] = ??? - override def getByBlockhash( - blockhash: Blockhash, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): ApplicationResult[PaginatedResult[TransactionWithValues]] = ??? - override def getByBlockhash( blockhash: Blockhash, limit: pagination.Limit, diff --git a/server/test/controllers/AddressesControllerSpec.scala b/server/test/controllers/AddressesControllerSpec.scala index c78e9f51..50ad225a 100644 --- a/server/test/controllers/AddressesControllerSpec.scala +++ b/server/test/controllers/AddressesControllerSpec.scala @@ -56,18 +56,6 @@ class AddressesControllerSpec extends MyAPISpec { private val customTransactionDataHandler = new TransactionDummyDataHandler { - override def getBy( - address: Address, - paginatedQuery: PaginatedQuery, - ordering: FieldOrdering[TransactionField] - ): ApplicationResult[PaginatedResult[TransactionWithValues]] = { - if (address == addressForTransactions) { - Good(PaginatedResult(paginatedQuery.offset, paginatedQuery.limit, Count(1), List(addressTransaction))) - } else { - Good(PaginatedResult(paginatedQuery.offset, paginatedQuery.limit, Count(0), List.empty)) - } - } - override def getUnspentOutputs(address: Address): ApplicationResult[List[Transaction.Output]] = { if (address == addressForUtxos) { Good(utxosResponse) diff --git a/server/test/controllers/BalancesControllerSpec.scala b/server/test/controllers/BalancesControllerSpec.scala index 031d0df4..94e68c72 100644 --- a/server/test/controllers/BalancesControllerSpec.scala +++ b/server/test/controllers/BalancesControllerSpec.scala @@ -1,17 +1,10 @@ package controllers -import com.alexitc.playsonify.core.ApplicationResult -import com.alexitc.playsonify.models.ordering.FieldOrdering -import com.alexitc.playsonify.models.pagination._ import com.xsn.explorer.data.BalanceBlockingDataHandler import com.xsn.explorer.helpers.{BalanceDummyDataHandler, DataHelper} -import com.xsn.explorer.models.fields.BalanceField import com.xsn.explorer.models.persisted.Balance import controllers.common.MyAPISpec -import org.scalactic.Good import play.api.inject.bind -import play.api.libs.json.JsValue -import play.api.test.Helpers._ class BalancesControllerSpec extends MyAPISpec { @@ -38,53 +31,10 @@ class BalancesControllerSpec extends MyAPISpec { ) ).sortBy(_.available).reverse - val dataHandler = new BalanceDummyDataHandler { - - override def getNonZeroBalances( - query: PaginatedQuery, - ordering: FieldOrdering[BalanceField] - ): ApplicationResult[PaginatedResult[Balance]] = { - val filtered = balances.filter(_.available > 0) - val list = filtered.drop(query.offset.int).take(query.limit.int) - val result = - PaginatedResult(offset = query.offset, limit = query.limit, total = Count(filtered.size), data = list) - - Good(result) - } - } + val dataHandler = new BalanceDummyDataHandler {} val application = guiceApplicationBuilder .overrides(bind[BalanceBlockingDataHandler].to(dataHandler)) .build() - "GET /balances" should { - "get the richest addresses" in { - pending - - val query = PaginatedQuery(Offset(1), Limit(2)) - val expected1 = balances(1) - val expected2 = balances(2) - val response = GET(s"/balances?offset=${query.offset.int}&limit=${query.limit.int}") - - status(response) mustEqual OK - - val json = contentAsJson(response) - (json \ "total").as[Int] mustEqual balances.size - (json \ "offset").as[Int] mustEqual query.offset.int - (json \ "limit").as[Int] mustEqual query.limit.int - - val list = (json \ "data").as[List[JsValue]] - list.size mustEqual 2 - - (list(0) \ "address").as[String] mustEqual expected1.address.string - (list(0) \ "available").as[BigDecimal] mustEqual expected1.available - (list(0) \ "received").as[BigDecimal] mustEqual expected1.received - (list(0) \ "spent").as[BigDecimal] mustEqual expected1.spent - - (list(1) \ "address").as[String] mustEqual expected2.address.string - (list(1) \ "available").as[BigDecimal] mustEqual expected2.available - (list(1) \ "received").as[BigDecimal] mustEqual expected2.received - (list(1) \ "spent").as[BigDecimal] mustEqual expected2.spent - } - } } diff --git a/server/test/controllers/BlocksControllerSpec.scala b/server/test/controllers/BlocksControllerSpec.scala index 4c9a4fef..8062755d 100644 --- a/server/test/controllers/BlocksControllerSpec.scala +++ b/server/test/controllers/BlocksControllerSpec.scala @@ -258,52 +258,6 @@ class BlocksControllerSpec extends MyAPISpec { } } - "GET /blocks/:blockhash/transactions" should { - "return the transactions for the given block" in { - pending - - val blockhash = Blockhash.from("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7").get - - val result = { - val transactions = BlockLoader - .getRPC(blockhash.string) - .transactions - .map(_.string) - .map(TransactionLoader.get) - .map { tx => - TransactionWithValues( - id = tx.id, - blockhash = blockhash, - time = tx.time, - size = tx.size, - sent = tx.vin.collect { case x: TransactionVIN.HasValues => x }.map(_.value).sum, - received = tx.vout.map(_.value).sum - ) - } - - val page = PaginatedResult(Offset(0), Limit(10), Count(transactions.size), transactions.take(5)) - - Good(page) - } - - when( - transactionDataHandlerMock - .getByBlockhash(eqTo(blockhash), any[PaginatedQuery], any[FieldOrdering[TransactionField]]) - ).thenReturn(result) - val response = GET(s"/blocks/$blockhash/transactions") - - status(response) mustEqual OK - - val json = contentAsJson(response) - (json \ "total").as[Int] mustEqual 1 - (json \ "offset").as[Int] mustEqual 0 - (json \ "limit").as[Int] mustEqual 10 - - val data = (json \ "data").as[List[JsValue]] - data.size mustEqual 1 - } - } - "GET /v2/blocks/:blockhash/light-wallet-transactions" should { "return the transactions" in { val blockhash = Blockhash.from("000003fb382f6892ae96594b81aa916a8923c70701de4e7054aac556c7271ef7").get