com.wavesplatform.api.http.requests.SignedSetAssetScriptRequest.scala Maven / Gradle / Ivy
The newest version!
package com.wavesplatform.api.http.requests
import com.wavesplatform.account.PublicKey
import com.wavesplatform.lang.ValidationError
import com.wavesplatform.lang.script.Script
import com.wavesplatform.transaction.Asset.IssuedAsset
import com.wavesplatform.transaction.Proofs
import com.wavesplatform.transaction.assets.SetAssetScriptTransaction
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Reads}
object SignedSetAssetScriptRequest {
implicit val signedSetAssetScriptRequestReads: Reads[SignedSetAssetScriptRequest] = (
(JsPath \ "version").readNullable[Byte] and
(JsPath \ "senderPublicKey").read[String] and
(JsPath \ "assetId").read[IssuedAsset] and
(JsPath \ "script").readNullable[String] and
(JsPath \ "fee").read[Long] and
(JsPath \ "timestamp").read[Long] and
(JsPath \ "proofs").read[Proofs]
)(SignedSetAssetScriptRequest.apply _)
}
case class SignedSetAssetScriptRequest(
version: Option[Byte],
senderPublicKey: String,
assetId: IssuedAsset,
script: Option[String],
fee: Long,
timestamp: Long,
proofs: Proofs
) {
def toTx: Either[ValidationError, SetAssetScriptTransaction] =
for {
_sender <- PublicKey.fromBase58String(senderPublicKey)
_script <- script match {
case None | Some("") => Right(None)
case Some(s) => Script.fromBase64String(s).map(Some(_))
}
t <- SetAssetScriptTransaction.create(version.getOrElse(1.toByte), _sender, assetId, _script, fee, timestamp, proofs)
} yield t
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy