From 5d68d10887e7e20f362ff608bb74cbb563f08281 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Wed, 14 Mar 2018 21:13:07 -0600 Subject: [PATCH] server: Add AddressBalance model --- .../xsn/explorer/models/AddressBalance.scala | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/app/com/xsn/explorer/models/AddressBalance.scala diff --git a/server/app/com/xsn/explorer/models/AddressBalance.scala b/server/app/com/xsn/explorer/models/AddressBalance.scala new file mode 100644 index 0000000..496d1f3 --- /dev/null +++ b/server/app/com/xsn/explorer/models/AddressBalance.scala @@ -0,0 +1,24 @@ +package com.xsn.explorer.models + +import play.api.libs.functional.syntax._ +import play.api.libs.json._ + +case class AddressBalance(balance: BigInt, received: BigInt) + +object AddressBalance { + implicit val reads: Reads[AddressBalance] = { + val builder = (__ \ 'balance).read[BigDecimal] and (__ \ 'received).read[BigDecimal] + + builder.apply { (balance, received) => + AddressBalance(balance.toBigInt(), received.toBigInt()) + } + } + + implicit val writes: Writes[AddressBalance] = Writes { obj => + val values = Map( + "balance" -> JsNumber(BigDecimal(obj.balance)), + "received" -> JsNumber(BigDecimal(obj.received))) + + JsObject.apply(values) + } +}