Browse Source

server: Add serializer for the Balance model

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
f560a8f567
  1. 14
      server/app/com/xsn/explorer/models/Balance.scala

14
server/app/com/xsn/explorer/models/Balance.scala

@ -1,5 +1,7 @@
package com.xsn.explorer.models
import play.api.libs.json._
case class Balance(
address: Address,
received: BigDecimal = BigDecimal(0),
@ -7,3 +9,15 @@ case class Balance(
def available: BigDecimal = received - spent
}
object Balance {
implicit val writes: Writes[Balance] = Writes { obj =>
val values = Map(
"address" -> JsString(obj.address.string),
"received" -> JsNumber(obj.received),
"spent" -> JsNumber(obj.spent),
"available" -> JsNumber(obj.available))
JsObject.apply(values)
}
}

Loading…
Cancel
Save