Browse Source

server: Move the Address value to the values package

master
Alexis Hernandez 6 years ago
parent
commit
a1737b9710
  1. 2
      server/app/com/xsn/explorer/data/BalanceDataHandler.scala
  2. 1
      server/app/com/xsn/explorer/data/TransactionDataHandler.scala
  3. 2
      server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala
  4. 2
      server/app/com/xsn/explorer/data/anorm/LedgerPostgresDataHandler.scala
  5. 1
      server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala
  6. 2
      server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala
  7. 1
      server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala
  8. 1
      server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala
  9. 1
      server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala
  10. 3
      server/app/com/xsn/explorer/data/anorm/parsers/CommonParsers.scala
  11. 1
      server/app/com/xsn/explorer/data/anorm/parsers/TransactionParsers.scala
  12. 2
      server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala
  13. 1
      server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala
  14. 39
      server/app/com/xsn/explorer/models/Address.scala
  15. 1
      server/app/com/xsn/explorer/models/BlockReward.scala
  16. 1
      server/app/com/xsn/explorer/models/TransactionValue.scala
  17. 3
      server/app/com/xsn/explorer/models/persisted/AddressTransactionDetails.scala
  18. 2
      server/app/com/xsn/explorer/models/persisted/Balance.scala
  19. 3
      server/app/com/xsn/explorer/models/persisted/Transaction.scala
  20. 2
      server/app/com/xsn/explorer/models/request/GetLatestTransactionRequest.scala
  21. 3
      server/app/com/xsn/explorer/models/rpc/Masternode.scala
  22. 3
      server/app/com/xsn/explorer/models/rpc/ScriptPubKey.scala
  23. 3
      server/app/com/xsn/explorer/models/rpc/TransactionVIN.scala
  24. 2
      server/app/com/xsn/explorer/models/rpc/TransactionVOUT.scala
  25. 2
      server/app/com/xsn/explorer/services/AddressService.scala
  26. 3
      server/app/com/xsn/explorer/services/BalanceService.scala
  27. 1
      server/app/com/xsn/explorer/services/TransactionService.scala
  28. 1
      server/app/com/xsn/explorer/services/XSNService.scala
  29. 1
      server/app/com/xsn/explorer/services/logic/BlockLogic.scala
  30. 2
      server/app/com/xsn/explorer/services/logic/TransactionLogic.scala
  31. 2
      server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala
  32. 2
      server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala
  33. 3
      server/test/com/xsn/explorer/helpers/DataGenerator.scala
  34. 3
      server/test/com/xsn/explorer/helpers/DataHelper.scala
  35. 1
      server/test/com/xsn/explorer/helpers/DummyXSNService.scala
  36. 1
      server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala
  37. 1
      server/test/com/xsn/explorer/models/AddressSpec.scala
  38. 3
      server/test/com/xsn/explorer/models/rpc/ScriptPubKeySpec.scala
  39. 1
      server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala
  40. 1
      server/test/controllers/AddressesControllerSpec.scala
  41. 3
      server/test/controllers/MasternodesControllerSpec.scala

2
server/app/com/xsn/explorer/data/BalanceDataHandler.scala

@ -4,8 +4,8 @@ import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ordering.FieldOrdering
import com.alexitc.playsonify.models.pagination.{Limit, PaginatedQuery, PaginatedResult}
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
import scala.language.higherKinds

1
server/app/com/xsn/explorer/data/TransactionDataHandler.scala

@ -6,6 +6,7 @@ import com.alexitc.playsonify.models.pagination.{Limit, PaginatedQuery, Paginate
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
import scala.language.higherKinds

2
server/app/com/xsn/explorer/data/anorm/BalancePostgresDataHandler.scala

@ -7,8 +7,8 @@ import com.xsn.explorer.data.BalanceBlockingDataHandler
import com.xsn.explorer.data.anorm.dao.BalancePostgresDAO
import com.xsn.explorer.errors.BalanceUnknownError
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
import javax.inject.Inject
import org.scalactic.{Good, One, Or}
import play.api.db.Database

2
server/app/com/xsn/explorer/data/anorm/LedgerPostgresDataHandler.scala

@ -8,7 +8,7 @@ import com.xsn.explorer.data.LedgerBlockingDataHandler
import com.xsn.explorer.data.anorm.dao.{AggregatedAmountPostgresDAO, BalancePostgresDAO, BlockPostgresDAO, TransactionPostgresDAO}
import com.xsn.explorer.errors.{PostgresForeignKeyViolationError, PreviousBlockMissingError, RepeatedBlockHeightError}
import com.xsn.explorer.models.persisted.{Balance, Block, Transaction}
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.util.Extensions.ListOptionExt
import javax.inject.Inject
import org.scalactic.Good

1
server/app/com/xsn/explorer/data/anorm/TransactionPostgresDataHandler.scala

@ -8,6 +8,7 @@ import com.xsn.explorer.data.anorm.dao.{TransactionOutputPostgresDAO, Transactio
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
import javax.inject.Inject
import org.scalactic.Good
import play.api.db.Database

2
server/app/com/xsn/explorer/data/anorm/dao/BalancePostgresDAO.scala

@ -8,8 +8,8 @@ import com.alexitc.playsonify.models.pagination.{Count, Limit, PaginatedQuery}
import com.alexitc.playsonify.sql.FieldOrderingSQLInterpreter
import com.xsn.explorer.data.anorm.parsers.BalanceParsers._
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
import javax.inject.Inject
import org.slf4j.LoggerFactory

1
server/app/com/xsn/explorer/data/anorm/dao/TransactionInputPostgresDAO.scala

@ -6,6 +6,7 @@ import anorm._
import com.xsn.explorer.data.anorm.parsers.TransactionParsers._
import com.xsn.explorer.models._
import com.xsn.explorer.models.persisted.Transaction
import com.xsn.explorer.models.values.Address
import org.slf4j.LoggerFactory
class TransactionInputPostgresDAO {

1
server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala

@ -6,6 +6,7 @@ import anorm._
import com.xsn.explorer.data.anorm.parsers.TransactionParsers._
import com.xsn.explorer.models._
import com.xsn.explorer.models.persisted.Transaction
import com.xsn.explorer.models.values.Address
import org.slf4j.LoggerFactory
class TransactionOutputPostgresDAO {

1
server/app/com/xsn/explorer/data/anorm/dao/TransactionPostgresDAO.scala

@ -10,6 +10,7 @@ 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
import javax.inject.Inject
import org.slf4j.LoggerFactory

3
server/app/com/xsn/explorer/data/anorm/parsers/CommonParsers.scala

@ -1,7 +1,8 @@
package com.xsn.explorer.data.anorm.parsers
import anorm.SqlParser.{int, long, str}
import com.xsn.explorer.models.{Address, Blockhash, Size}
import com.xsn.explorer.models.values._
import com.xsn.explorer.models.{Blockhash, Size}
object CommonParsers {

1
server/app/com/xsn/explorer/data/anorm/parsers/TransactionParsers.scala

@ -4,6 +4,7 @@ import anorm.SqlParser.{get, str}
import anorm.~
import com.xsn.explorer.models._
import com.xsn.explorer.models.persisted.{AddressTransactionDetails, Transaction}
import com.xsn.explorer.models.values._
object TransactionParsers {

2
server/app/com/xsn/explorer/data/async/BalanceFutureDataHandler.scala

@ -7,8 +7,8 @@ import com.alexitc.playsonify.models.pagination.PaginatedQuery
import com.xsn.explorer.data.{BalanceBlockingDataHandler, BalanceDataHandler}
import com.xsn.explorer.executors.DatabaseExecutionContext
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
import javax.inject.Inject
import scala.concurrent.Future

1
server/app/com/xsn/explorer/data/async/TransactionFutureDataHandler.scala

@ -8,6 +8,7 @@ import com.xsn.explorer.executors.DatabaseExecutionContext
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
import javax.inject.Inject
import scala.concurrent.Future

39
server/app/com/xsn/explorer/models/Address.scala

@ -1,39 +0,0 @@
package com.xsn.explorer.models
import com.alexitc.playsonify.models.WrappedString
import javax.xml.bind.DatatypeConverter
import play.api.libs.json._
import scala.util.Try
class Address private (val string: String) extends AnyVal with WrappedString
object Address {
private val pattern = "^[a-zA-Z0-9]{34,64}$".r.pattern
def from(string: String): Option[Address] = {
if (pattern.matcher(string).matches()) {
Some(new Address(string))
} else {
None
}
}
def fromHex(hex: String): Option[Address] = {
Try { DatatypeConverter.parseHexBinary(hex) }
.map { bytes => new String(bytes) }
.toOption
.flatMap(from)
}
implicit val reads: Reads[Address] = Reads { json =>
json.validate[String].flatMap { string =>
from(string)
.map(JsSuccess.apply(_))
.getOrElse {
JsError.apply("Invalid address")
}
}
}
}

1
server/app/com/xsn/explorer/models/BlockReward.scala

@ -1,5 +1,6 @@
package com.xsn.explorer.models
import com.xsn.explorer.models.values.Address
import play.api.libs.json.{Json, Writes}
case class BlockReward(address: Address, value: BigDecimal)

1
server/app/com/xsn/explorer/models/TransactionValue.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models
import com.xsn.explorer.models.rpc.TransactionVOUT
import com.xsn.explorer.models.values.Address
import play.api.libs.json.{Json, Writes}
case class TransactionValue(address: Address, value: BigDecimal)

3
server/app/com/xsn/explorer/models/persisted/AddressTransactionDetails.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.persisted
import com.xsn.explorer.models.{Address, TransactionId}
import com.xsn.explorer.models.TransactionId
import com.xsn.explorer.models.values.Address
case class AddressTransactionDetails(
address: Address,

2
server/app/com/xsn/explorer/models/persisted/Balance.scala

@ -1,6 +1,6 @@
package com.xsn.explorer.models.persisted
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.values.Address
import play.api.libs.json._
case class Balance(

3
server/app/com/xsn/explorer/models/persisted/Transaction.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.persisted
import com.xsn.explorer.models.{Address, Blockhash, HexString, Size, TransactionId, rpc}
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.models.{Blockhash, HexString, Size, TransactionId, rpc}
case class Transaction(
id: TransactionId,

2
server/app/com/xsn/explorer/models/request/GetLatestTransactionRequest.scala

@ -1,6 +1,6 @@
package com.xsn.explorer.models.request
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.values.Address
import org.scalactic.Every
import play.api.libs.json.{Json, Reads}
import controllers.common.Codecs.everyReads

3
server/app/com/xsn/explorer/models/rpc/Masternode.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.rpc
import com.xsn.explorer.models.{Address, TransactionId}
import com.xsn.explorer.models.TransactionId
import com.xsn.explorer.models.values.Address
import play.api.libs.json.{Json, Writes}
import scala.util.Try

3
server/app/com/xsn/explorer/models/rpc/ScriptPubKey.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.rpc
import com.xsn.explorer.models.{Address, HexString}
import com.xsn.explorer.models.HexString
import com.xsn.explorer.models.values.Address
import play.api.libs.functional.syntax._
import play.api.libs.json.{Reads, __}

3
server/app/com/xsn/explorer/models/rpc/TransactionVIN.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.rpc
import com.xsn.explorer.models.{Address, TransactionId}
import com.xsn.explorer.models.TransactionId
import com.xsn.explorer.models.values.Address
import play.api.libs.functional.syntax._
import play.api.libs.json.{Reads, __}

2
server/app/com/xsn/explorer/models/rpc/TransactionVOUT.scala

@ -1,6 +1,6 @@
package com.xsn.explorer.models.rpc
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.values.Address
import play.api.libs.functional.syntax._
import play.api.libs.json.{Reads, __}

2
server/app/com/xsn/explorer/services/AddressService.scala

@ -5,7 +5,7 @@ import com.alexitc.playsonify.core.{ApplicationResult, FutureApplicationResult}
import com.xsn.explorer.data.async.{BalanceFutureDataHandler, TransactionFutureDataHandler}
import com.xsn.explorer.errors.AddressFormatError
import com.xsn.explorer.models.persisted.{Balance, Transaction}
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.values.Address
import javax.inject.Inject
import org.scalactic.{One, Or}

3
server/app/com/xsn/explorer/services/BalanceService.scala

@ -7,8 +7,9 @@ import com.alexitc.playsonify.models.pagination.{Limit, Offset, PaginatedQuery}
import com.alexitc.playsonify.validators.PaginatedQueryValidator
import com.xsn.explorer.data.async.BalanceFutureDataHandler
import com.xsn.explorer.errors.AddressFormatError
import com.xsn.explorer.models.WrappedResult
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.{Address, WrappedResult}
import com.xsn.explorer.models.values._
import com.xsn.explorer.parsers.BalanceOrderingParser
import javax.inject.Inject
import org.scalactic.{Good, One, Or}

1
server/app/com/xsn/explorer/services/TransactionService.scala

@ -8,6 +8,7 @@ import com.alexitc.playsonify.validators.PaginatedQueryValidator
import com.xsn.explorer.data.async.TransactionFutureDataHandler
import com.xsn.explorer.errors._
import com.xsn.explorer.models._
import com.xsn.explorer.models.values._
import com.xsn.explorer.parsers.TransactionOrderingParser
import io.scalaland.chimney.dsl._
import javax.inject.Inject

1
server/app/com/xsn/explorer/services/XSNService.scala

@ -7,6 +7,7 @@ import com.xsn.explorer.config.{ExplorerConfig, RPCConfig}
import com.xsn.explorer.errors._
import com.xsn.explorer.executors.ExternalServiceExecutionContext
import com.xsn.explorer.models._
import com.xsn.explorer.models.values.Address
import javax.inject.Inject
import org.scalactic.{Bad, Good}
import org.slf4j.LoggerFactory

1
server/app/com/xsn/explorer/services/logic/BlockLogic.scala

@ -4,6 +4,7 @@ import com.alexitc.playsonify.core.ApplicationResult
import com.xsn.explorer.errors.{BlockNotFoundError, BlockhashFormatError}
import com.xsn.explorer.models._
import com.xsn.explorer.models.rpc.{Block, Transaction}
import com.xsn.explorer.models.values.Address
import org.scalactic.{Bad, Good, One, Or}
class BlockLogic {

2
server/app/com/xsn/explorer/services/logic/TransactionLogic.scala

@ -2,8 +2,8 @@ package com.xsn.explorer.services.logic
import com.alexitc.playsonify.core.ApplicationResult
import com.alexitc.playsonify.models.ApplicationError
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.rpc.{Transaction, TransactionVIN, TransactionVOUT}
import com.xsn.explorer.models.values.Address
import org.scalactic.{One, Or}
class TransactionLogic {

2
server/test/com/xsn/explorer/data/StatisticsPostgresDataHandlerSpec.scala

@ -5,8 +5,8 @@ import com.xsn.explorer.data.anorm.dao.{BalancePostgresDAO, StatisticsPostgresDA
import com.xsn.explorer.data.anorm.{BalancePostgresDataHandler, StatisticsPostgresDataHandler}
import com.xsn.explorer.data.common.PostgresDataHandlerSpec
import com.xsn.explorer.helpers.DataHelper
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
import org.scalatest.OptionValues._
class StatisticsPostgresDataHandlerSpec extends PostgresDataHandlerSpec {

2
server/test/com/xsn/explorer/helpers/BalanceDummyDataHandler.scala

@ -6,8 +6,8 @@ import com.alexitc.playsonify.models.pagination
import com.alexitc.playsonify.models.pagination.{PaginatedQuery, PaginatedResult}
import com.xsn.explorer.data.BalanceBlockingDataHandler
import com.xsn.explorer.models.fields.BalanceField
import com.xsn.explorer.models.Address
import com.xsn.explorer.models.persisted.Balance
import com.xsn.explorer.models.values.Address
class BalanceDummyDataHandler extends BalanceBlockingDataHandler {

3
server/test/com/xsn/explorer/helpers/DataGenerator.scala

@ -2,7 +2,8 @@ package com.xsn.explorer.helpers
import com.xsn.explorer.models.persisted.Transaction
import com.xsn.explorer.models.rpc.Block
import com.xsn.explorer.models.{Address, Blockhash, Confirmations, Height, HexString, Size, TransactionId}
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.models.{Blockhash, Confirmations, Height, HexString, Size, TransactionId}
trait DataGenerator {

3
server/test/com/xsn/explorer/helpers/DataHelper.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.helpers
import com.xsn.explorer.models.{Address, Blockhash, TransactionId}
import com.xsn.explorer.models.values._
import com.xsn.explorer.models.{Blockhash, TransactionId}
object DataHelper {

1
server/test/com/xsn/explorer/helpers/DummyXSNService.scala

@ -3,6 +3,7 @@ package com.xsn.explorer.helpers
import com.alexitc.playsonify.core.FutureApplicationResult
import com.xsn.explorer.models._
import com.xsn.explorer.models.rpc.Masternode
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.services.XSNService
import play.api.libs.json.JsValue

1
server/test/com/xsn/explorer/helpers/TransactionDummyDataHandler.scala

@ -8,6 +8,7 @@ import com.xsn.explorer.data.TransactionBlockingDataHandler
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
class TransactionDummyDataHandler extends TransactionBlockingDataHandler {

1
server/test/com/xsn/explorer/models/AddressSpec.scala

@ -1,5 +1,6 @@
package com.xsn.explorer.models
import com.xsn.explorer.models.values._
import org.scalatest.{MustMatchers, OptionValues, WordSpec}
class AddressSpec extends WordSpec with MustMatchers with OptionValues {

3
server/test/com/xsn/explorer/models/rpc/ScriptPubKeySpec.scala

@ -1,6 +1,7 @@
package com.xsn.explorer.models.rpc
import com.xsn.explorer.models.{Address, HexString}
import com.xsn.explorer.models.HexString
import com.xsn.explorer.models.values._
import org.scalatest.{MustMatchers, OptionValues, WordSpec}
class ScriptPubKeySpec extends WordSpec with MustMatchers with OptionValues {

1
server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala

@ -5,6 +5,7 @@ import com.xsn.explorer.errors._
import com.xsn.explorer.helpers.{BlockLoader, DataHelper, Executors, TransactionLoader}
import com.xsn.explorer.models._
import com.xsn.explorer.models.rpc.Masternode
import com.xsn.explorer.models.values._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalactic.{Bad, Good}

1
server/test/controllers/AddressesControllerSpec.scala

@ -9,6 +9,7 @@ import com.xsn.explorer.helpers.{BalanceDummyDataHandler, DataHelper, Transactio
import com.xsn.explorer.models._
import com.xsn.explorer.models.fields.TransactionField
import com.xsn.explorer.models.persisted.{Balance, Transaction}
import com.xsn.explorer.models.values.Address
import com.xsn.explorer.util.Extensions.BigDecimalExt
import controllers.common.MyAPISpec
import org.scalactic.Good

3
server/test/controllers/MasternodesControllerSpec.scala

@ -5,7 +5,8 @@ import com.alexitc.playsonify.play.PublicErrorRenderer
import com.xsn.explorer.errors.MasternodeNotFoundError
import com.xsn.explorer.helpers.DummyXSNService
import com.xsn.explorer.models.rpc.Masternode
import com.xsn.explorer.models.{Address, IPAddress, TransactionId}
import com.xsn.explorer.models.values._
import com.xsn.explorer.models.{IPAddress, TransactionId}
import com.xsn.explorer.services.XSNService
import controllers.common.MyAPISpec
import org.scalactic.{Bad, Good}

Loading…
Cancel
Save