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.
31 lines
765 B
31 lines
765 B
package com.xsn.explorer.models
|
|
|
|
import com.xsn.explorer.models.base.WrappedString
|
|
import play.api.libs.json._
|
|
|
|
class TransactionId private (val string: String) extends AnyVal with WrappedString
|
|
|
|
object TransactionId {
|
|
|
|
private val pattern = "^[a-f0-9]{64}$".r.pattern
|
|
|
|
def from(string: String): Option[TransactionId] = {
|
|
val lowercaseString = string.toLowerCase
|
|
|
|
if (pattern.matcher(lowercaseString).matches()) {
|
|
Some(new TransactionId(lowercaseString))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
implicit val reads: Reads[TransactionId] = Reads { json =>
|
|
json.validate[String].flatMap { string =>
|
|
from(string)
|
|
.map(JsSuccess.apply(_))
|
|
.getOrElse {
|
|
JsError.apply("Invalid transaction")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|