|
|
@ -1,8 +1,12 @@ |
|
|
|
package com.xsn.explorer.models |
|
|
|
|
|
|
|
import javax.xml.bind.DatatypeConverter |
|
|
|
|
|
|
|
import com.xsn.explorer.models.base.WrappedString |
|
|
|
import play.api.libs.json._ |
|
|
|
|
|
|
|
import scala.util.Try |
|
|
|
|
|
|
|
class Address private (val string: String) extends AnyVal with WrappedString |
|
|
|
|
|
|
|
object Address { |
|
|
@ -17,6 +21,13 @@ object Address { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|