You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
833 B

package com.xsn.explorer.models
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsObject, Reads, __}
case class TransactionVOUT(
value: BigDecimal,
n: Int,
scriptPubKeyType: String,
address: Option[Address])
object TransactionVOUT {
implicit val reads: Reads[TransactionVOUT] = {
val builder = (__ \ 'value).read[BigDecimal] and
(__ \ 'n).read[Int] and
(__ \ 'scriptPubKey).read[JsObject].map { json =>
val t = (json \ "type").as[String]
val a = (json \ "addresses")
.asOpt[List[String]]
.flatMap(_.headOption)
.flatMap(Address.from)
(t, a)
}
builder.apply { (value, n, tuple) =>
val (scriptType, address) = tuple
TransactionVOUT(value, n, scriptType, address)
}
}
}