Skip to content

Commit

Permalink
server: remove deprecated code
Browse files Browse the repository at this point in the history
remove the following endpoints:
GET   /addresses/:address/transactions
GET   /blocks/:blockhash/transactions
GET   /balances
  • Loading branch information
adinael committed Jun 10, 2019
1 parent 9e30a31 commit 0b9ea97
Show file tree
Hide file tree
Showing 21 changed files with 3 additions and 561 deletions.
2 changes: 0 additions & 2 deletions server/app/com/xsn/explorer/data/BalanceDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}

Expand Down
12 changes: 0 additions & 12 deletions server/app/com/xsn/explorer/data/TransactionDataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions server/app/com/xsn/explorer/services/BalanceService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
31 changes: 0 additions & 31 deletions server/app/com/xsn/explorer/services/TransactionService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions server/app/controllers/AddressesController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions server/app/controllers/BalancesController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions server/app/controllers/BlocksController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit 0b9ea97

Please sign in to comment.