Browse Source

server: Remove default json codecs for the LightWalletTransaction

- The AddressesController has its own codecs
- The BlocksController has its own codecs
master
Alexis Hernandez 6 years ago
parent
commit
4a8e481e7e
  1. 4
      server/app/com/xsn/explorer/models/LightWalletTransaction.scala
  2. 10
      server/app/controllers/AddressesController.scala
  3. 24
      server/app/controllers/BlocksController.scala

4
server/app/com/xsn/explorer/models/LightWalletTransaction.scala

@ -1,7 +1,6 @@
package com.xsn.explorer.models
import com.xsn.explorer.models.values.{Address, Blockhash, Size, TransactionId}
import play.api.libs.json.{Json, Writes}
case class LightWalletTransaction(
id: TransactionId,
@ -16,7 +15,4 @@ object LightWalletTransaction {
case class Input(txid: TransactionId, index: Int, value: BigDecimal)
case class Output(index: Int, value: BigDecimal, address: Address)
implicit val inputWrites: Writes[Input] = Json.writes[Input]
implicit val outputWrites: Writes[Output] = Json.writes[Output]
implicit val writes: Writes[LightWalletTransaction] = Json.writes[LightWalletTransaction]
}

10
server/app/controllers/AddressesController.scala

@ -2,6 +2,7 @@ package controllers
import com.alexitc.playsonify.models.ordering.OrderingQuery
import com.alexitc.playsonify.models.pagination.{Limit, Offset, PaginatedQuery}
import com.xsn.explorer.models.LightWalletTransaction
import com.xsn.explorer.models.persisted.Transaction
import com.xsn.explorer.services.{AddressService, TransactionService}
import com.xsn.explorer.util.Extensions.BigDecimalExt
@ -15,6 +16,7 @@ class AddressesController @Inject() (
cc: MyJsonControllerComponents)
extends MyJsonController(cc) {
import AddressesController._
import Codecs._
def getBy(address: String) = public { _ =>
@ -59,3 +61,11 @@ class AddressesController @Inject() (
addressService.getUnspentOutputs(address)
}
}
object AddressesController {
implicit val inputWrites: Writes[LightWalletTransaction.Input] = Json.writes[LightWalletTransaction.Input]
implicit val outputWrites: Writes[LightWalletTransaction.Output] = Json.writes[LightWalletTransaction.Output]
implicit val lightWalletTransactionWrites: Writes[LightWalletTransaction] = Json.writes[LightWalletTransaction]
}

24
server/app/controllers/BlocksController.scala

@ -2,10 +2,12 @@ package controllers
import com.alexitc.playsonify.models.ordering.OrderingQuery
import com.alexitc.playsonify.models.pagination.{Limit, Offset, PaginatedQuery}
import com.xsn.explorer.models.LightWalletTransaction
import com.xsn.explorer.models.values.Height
import com.xsn.explorer.services.{BlockService, TransactionService}
import controllers.common.{Codecs, MyJsonController, MyJsonControllerComponents}
import javax.inject.Inject
import play.api.libs.json.{Json, Writes}
import scala.util.Try
@ -15,6 +17,7 @@ class BlocksController @Inject() (
cc: MyJsonControllerComponents)
extends MyJsonController(cc) {
import BlocksController._
import Codecs._
def getLatestBlocks() = public { _ =>
@ -58,3 +61,24 @@ class BlocksController @Inject() (
transactionService.getLightWalletTransactionsByBlockhash(blockhash, Limit(limit), lastSeenTxid)
}
}
object BlocksController {
implicit val inputWrites: Writes[LightWalletTransaction.Input] = (obj: LightWalletTransaction.Input) => {
Json.obj(
"txid" -> obj.txid,
"index" -> obj.index
)
}
implicit val outputWrites: Writes[LightWalletTransaction.Output] = Json.writes[LightWalletTransaction.Output]
implicit val lightWalletTransactionWrites: Writes[LightWalletTransaction] = (obj: LightWalletTransaction) => {
Json.obj(
"id" -> obj.id,
"size" -> obj.size,
"time" -> obj.time,
"inputs" -> Json.toJson(obj.inputs),
"outputs" -> Json.toJson(obj.outputs)
)
}
}
Loading…
Cancel
Save