Skip to content

Commit

Permalink
Merge pull request #1064 from wavesplatform/node-496-proof-based-crea…
Browse files Browse the repository at this point in the history
…te-alias-tx

Node 496 proof based create alias tx
  • Loading branch information
ismagin authored Apr 28, 2018
2 parents 8c7e905 + 49f1f32 commit d24c5da
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scodec.bits.{BitVector, ByteVector}
import scorex.account.AddressScheme
import scorex.block.Block
import scorex.transaction.assets.IssueTransaction
import scorex.transaction.{Authorized, CreateAliasTransaction, DataTransaction, Transaction}
import scorex.transaction.{Authorized, CreateAliasTransactionV1, DataTransaction, Transaction}
import scorex.utils.ScorexLogging

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -65,7 +65,7 @@ object ExtractInfo extends App with ScorexLogging {
val aliasTxs = nonEmptyBlocks(benchSettings.aliasesFromHeight)
.flatMap(_.transactionData)
.collect {
case _: CreateAliasTransaction => true
case _: CreateAliasTransactionV1 => true
}

val restTxs = nonEmptyBlocks(benchSettings.restTxsFromHeight)
Expand All @@ -81,7 +81,7 @@ object ExtractInfo extends App with ScorexLogging {
} yield sender.toAddress.stringRepr
write("accounts", benchSettings.accountsFile, takeUniq(1000, accounts))

val aliasTxIds = aliasTxs.map(_.asInstanceOf[CreateAliasTransaction].alias.stringRepr)
val aliasTxIds = aliasTxs.map(_.asInstanceOf[CreateAliasTransactionV1].alias.stringRepr)
write("aliases", benchSettings.aliasesFile, aliasTxIds.take(1000))

val restTxIds = restTxs.map(_.id().base58)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ class NarrowTransactionGenerator(settings: Settings, val accounts: Seq[PrivateKe
val sender = accounts.find(_.address == lease.sender.address).get
logOption(LeaseCancelTransactionV1.create(sender, lease.id(), moreThatStandartFee * 3, ts))
})
case CreateAliasTransaction =>
case CreateAliasTransactionV1 =>
val sender = randomFrom(accounts).get
val aliasString = NarrowTransactionGenerator.generateAlias()
logOption(CreateAliasTransaction.create(sender, Alias.buildWithCurrentNetworkByte(aliasString).right.get, 100000, ts))
logOption(CreateAliasTransactionV1.create(sender, Alias.buildWithCurrentNetworkByte(aliasString).right.get, 100000, ts))
case MassTransferTransaction =>
val transferCount = r.nextInt(MassTransferTransaction.MaxTransferCount)
val transfers = for (i <- 0 to transferCount) yield {
Expand Down
4 changes: 2 additions & 2 deletions it/src/main/scala/com/wavesplatform/it/api/AsyncHttpApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.scalatest.{Assertion, Assertions, Matchers}
import play.api.libs.json.Json.{parse, stringify, toJson}
import play.api.libs.json._
import scorex.api.http.PeersApiRoute.{ConnectReq, connectFormat}
import scorex.api.http.alias.CreateAliasRequest
import scorex.api.http.alias.CreateAliasV1Request
import scorex.api.http.assets._
import scorex.api.http.leasing.{LeaseCancelV1Request, LeaseV1Request, SignedLeaseCancelV1Request, SignedLeaseV1Request}
import scorex.api.http.{AddressApiRoute, ApiErrorResponse, DataRequest}
Expand Down Expand Up @@ -355,7 +355,7 @@ object AsyncHttpApi extends Assertions {
}

def createAlias(targetAddress: String, alias: String, fee: Long): Future[Transaction] =
postJson("/alias/create", CreateAliasRequest(targetAddress, alias, fee)).as[Transaction]
postJson("/alias/create", CreateAliasV1Request(targetAddress, alias, fee)).as[Transaction]

def aliasByAddress(targetAddress: String): Future[Seq[String]] =
get(s"/alias/by-address/$targetAddress").as[Seq[String]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scorex.transaction.ValidationError._
import scorex.transaction._
import scorex.transaction.assets._
import scorex.transaction.assets.exchange.ExchangeTransaction
import scorex.transaction.lease.{LeaseCancelTransactionV1, LeaseCancelTransactionV2, LeaseTransactionV1, LeaseTransactionV2}
import scorex.transaction.lease._
import scorex.transaction.smart.SetScriptTransaction
import scorex.transaction.transfer._

Expand Down Expand Up @@ -102,7 +102,7 @@ object CommonValidation {
case _: ExchangeTransaction => Right(tx)
case _: LeaseTransactionV1 => Right(tx)
case _: LeaseCancelTransactionV1 => Right(tx)
case _: CreateAliasTransaction => Right(tx)
case _: CreateAliasTransactionV1 => Right(tx)
case _: MassTransferTransaction => activationBarrier(BlockchainFeatures.MassTransfer)
case _: DataTransaction => activationBarrier(BlockchainFeatures.DataTransaction)
case _: SetScriptTransaction => activationBarrier(BlockchainFeatures.SmartAccounts)
Expand All @@ -112,6 +112,7 @@ object CommonValidation {
case _: BurnTransactionV2 => activationBarrier(BlockchainFeatures.SmartAccounts)
case _: LeaseTransactionV2 => activationBarrier(BlockchainFeatures.SmartAccounts)
case _: LeaseCancelTransactionV2 => activationBarrier(BlockchainFeatures.SmartAccounts)
case _: CreateAliasTransactionV2 => activationBarrier(BlockchainFeatures.SmartAccounts)
case _: SponsorFeeTransaction => activationBarrier(BlockchainFeatures.FeeSponsorship)
case _ => Left(GenericError("Unknown transaction must be explicitly activated"))
}
Expand All @@ -135,21 +136,17 @@ object CommonValidation {
def feeInUnits: Either[ValidationError, Int] = tx match {
case _: GenesisTransaction => Right(0)
case _: PaymentTransaction => Right(1)
case _: IssueTransactionV1 => Right(1000)
case _: IssueTransactionV2 => Right(1000)
case _: IssueTransaction => Right(1000)
case _: ReissueTransaction => Right(1000)
case _: BurnTransaction => Right(1)
case _: TransferTransactionV1 => Right(1)
case _: TransferTransaction => Right(1)
case tx: MassTransferTransaction => Right(1 + (tx.transfers.size + 1) / 2)
case _: LeaseTransactionV1 => Right(1)
case _: LeaseTransactionV2 => Right(1)
case _: LeaseCancelTransactionV1 => Right(1)
case _: LeaseCancelTransactionV2 => Right(1)
case _: LeaseTransaction => Right(1)
case _: LeaseCancelTransaction => Right(1)
case _: ExchangeTransaction => Right(3)
case _: CreateAliasTransaction => Right(1)
case tx: DataTransaction => Right(1 + (tx.bytes().length - 1) / 1024)
case _: SetScriptTransaction => Right(1)
case _: TransferTransactionV2 => Right(1)
case _: SponsorFeeTransaction => Right(1000)
case _ => Left(UnsupportedTransactionType)
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/wavesplatform/state/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.wavesplatform
import scorex.account.{Address, AddressOrAlias, Alias}
import scorex.block.Block
import scorex.transaction.ValidationError.{AliasDoesNotExist, GenericError}
import scorex.transaction._
import scorex.transaction.lease.{LeaseTransaction, LeaseTransactionV1}
import scorex.transaction.{AssetId, CreateAliasTransaction, Transaction, ValidationError}
import scorex.transaction.{AssetId, CreateAliasTransactionV1, Transaction, ValidationError}

import scala.reflect.ClassTag
import scala.util.{Left, Right, Try}
Expand Down Expand Up @@ -72,7 +73,7 @@ package object state {

def aliasesOfAddress(address: Address): Seq[Alias] =
blockchain
.addressTransactions(address, Set(CreateAliasTransaction.typeId), Int.MaxValue, 0)
.addressTransactions(address, Set(CreateAliasTransactionV1.typeId), Int.MaxValue, 0)
.collect { case (_, a: CreateAliasTransaction) => a.alias }

def activeLeases(address: Address): Seq[(Int, LeaseTransaction)] =
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/scorex/api/http/TransactionsApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import play.api.libs.json._
import scorex.BroadcastRoute
import scorex.account.Address
import scorex.api.http.DataRequest._
import scorex.api.http.alias.{CreateAliasRequest, SignedCreateAliasRequest}
import scorex.api.http.alias.{CreateAliasV1Request, CreateAliasV2Request, SignedCreateAliasV1Request, SignedCreateAliasV2Request}
import scorex.api.http.assets.SponsorFeeRequest._
import scorex.api.http.assets._
import scorex.api.http.leasing._
Expand Down Expand Up @@ -183,7 +183,8 @@ case class TransactionsApiRoute(settings: RestAPISettings,
case LeaseTransactionV2 => TransactionFactory.leaseV2(jsv.as[LeaseV2Request], wallet, time)
case LeaseCancelTransactionV1 => TransactionFactory.leaseCancelV1(jsv.as[LeaseCancelV1Request], wallet, time)
case LeaseCancelTransactionV2 => TransactionFactory.leaseCancelV2(jsv.as[LeaseCancelV2Request], wallet, time)
case CreateAliasTransaction => TransactionFactory.alias(jsv.as[CreateAliasRequest], wallet, time)
case CreateAliasTransactionV1 => TransactionFactory.aliasV1(jsv.as[CreateAliasV1Request], wallet, time)
case CreateAliasTransactionV2 => TransactionFactory.aliasV2(jsv.as[CreateAliasV2Request], wallet, time)
case DataTransaction => TransactionFactory.data(jsv.as[DataRequest], wallet, time)
case SetScriptTransaction => TransactionFactory.setScript(jsv.as[SetScriptRequest], wallet, time)
case SponsorFeeTransaction => TransactionFactory.sponsor(jsv.as[SponsorFeeRequest], wallet, time)
Expand Down Expand Up @@ -230,7 +231,8 @@ case class TransactionsApiRoute(settings: RestAPISettings,
case LeaseTransactionV2 => jsv.as[SignedLeaseV2Request].toTx
case LeaseCancelTransactionV1 => jsv.as[SignedLeaseCancelV1Request].toTx
case LeaseCancelTransactionV2 => jsv.as[SignedLeaseCancelV2Request].toTx
case CreateAliasTransaction => jsv.as[SignedCreateAliasRequest].toTx
case CreateAliasTransactionV1 => jsv.as[SignedCreateAliasV1Request].toTx
case CreateAliasTransactionV2 => jsv.as[SignedCreateAliasV2Request].toTx
case DataTransaction => jsv.as[SignedDataRequest].toTx
case SetScriptTransaction => jsv.as[SignedSetScriptRequest].toTx
case SponsorFeeTransaction => jsv.as[SignedSponsorFeeRequest].toTx
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scorex/api/http/alias/AliasApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ case class AliasApiRoute(settings: RestAPISettings, wallet: Wallet, utx: UtxPool
)
))
@ApiResponses(Array(new ApiResponse(code = 200, message = "Json with response or error")))
def alias: Route = processRequest("create", (t: CreateAliasRequest) => doBroadcast(TransactionFactory.alias(t, wallet, time)))
def alias: Route = processRequest("create", (t: CreateAliasV1Request) => doBroadcast(TransactionFactory.aliasV1(t, wallet, time)))
@Path("/by-alias/{alias}")
@ApiOperation(
value = "Account",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package scorex.api.http.alias

import javax.ws.rs.Path

import akka.http.scaladsl.server.Route
import com.wavesplatform.settings.RestAPISettings
import com.wavesplatform.utx.UtxPool
import io.netty.channel.group.ChannelGroup
import io.swagger.annotations._
import javax.ws.rs.Path
import scorex.BroadcastRoute
import scorex.api.http._

Expand All @@ -33,7 +32,7 @@ case class AliasBroadcastApiRoute(settings: RestAPISettings, utx: UtxPool, allCh
))
@ApiResponses(Array(new ApiResponse(code = 200, message = "Json with response or error")))
def signedCreate: Route = (path("create") & post) {
json[SignedCreateAliasRequest] { aliasReq =>
json[SignedCreateAliasV1Request] { aliasReq =>
doBroadcast(aliasReq.toTx)
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/main/scala/scorex/api/http/alias/CreateAliasRequest.scala

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/scala/scorex/api/http/alias/CreateAliasV1Request.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package scorex.api.http.alias

import io.swagger.annotations.ApiModelProperty
import play.api.libs.json.{Format, Json}

case class CreateAliasV1Request(@ApiModelProperty(value = "Base58 encoded sender public key", required = true)
sender: String,
@ApiModelProperty(value = "Alias", required = true)
alias: String,
@ApiModelProperty(required = true)
fee: Long,
timestamp: Option[Long] = None)

object CreateAliasV1Request {
implicit val aliasV1RequestFormat: Format[CreateAliasV1Request] = Json.format
}
18 changes: 18 additions & 0 deletions src/main/scala/scorex/api/http/alias/CreateAliasV2Request.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scorex.api.http.alias

import io.swagger.annotations.ApiModelProperty
import play.api.libs.json.{Format, Json}

case class CreateAliasV2Request(@ApiModelProperty(required = true)
version: Byte,
@ApiModelProperty(value = "Base58 encoded sender public key", required = true)
sender: String,
@ApiModelProperty(value = "Alias", required = true)
alias: String,
@ApiModelProperty(required = true)
fee: Long,
timestamp: Option[Long] = None)

object CreateAliasV2Request {
implicit val aliasV2RequestFormat: Format[CreateAliasV2Request] = Json.format
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package scorex.api.http.alias

import io.swagger.annotations.ApiModelProperty
import play.api.libs.json.{Format, Json}
import scorex.account.{Alias, PublicKeyAccount}
import scorex.api.http.BroadcastRequest
import scorex.transaction.TransactionParsers.SignatureStringLength
import scorex.transaction.{CreateAliasTransactionV1, ValidationError}

case class SignedCreateAliasV1Request(@ApiModelProperty(value = "Base58 encoded sender public key", required = true)
senderPublicKey: String,
@ApiModelProperty(required = true)
fee: Long,
@ApiModelProperty(value = "Alias", required = true)
alias: String,
@ApiModelProperty(required = true)
timestamp: Long,
@ApiModelProperty(required = true)
signature: String)
extends BroadcastRequest {
def toTx: Either[ValidationError, CreateAliasTransactionV1] =
for {
_sender <- PublicKeyAccount.fromBase58String(senderPublicKey)
_signature <- parseBase58(signature, "invalid.signature", SignatureStringLength)
_alias <- Alias.buildWithCurrentNetworkByte(alias)
_t <- CreateAliasTransactionV1.create(_sender, _alias, fee, timestamp, _signature)
} yield _t
}

object SignedCreateAliasV1Request {
implicit val broadcastAliasV1RequestReadsFormat: Format[SignedCreateAliasV1Request] = Json.format
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package scorex.api.http.alias

import io.swagger.annotations.ApiModelProperty
import play.api.libs.json.{Format, Json}
import scorex.account.{Alias, PublicKeyAccount}
import scorex.api.http.BroadcastRequest
import scorex.transaction.{CreateAliasTransaction, CreateAliasTransactionV2, Proofs, ValidationError}
import cats.implicits._

case class SignedCreateAliasV2Request(@ApiModelProperty(required = true)
version: Byte,
@ApiModelProperty(value = "Base58 encoded sender public key", required = true)
senderPublicKey: String,
@ApiModelProperty(required = true)
fee: Long,
@ApiModelProperty(value = "Alias", required = true)
alias: String,
@ApiModelProperty(required = true)
timestamp: Long,
@ApiModelProperty(required = true)
proofs: List[String])
extends BroadcastRequest {
def toTx: Either[ValidationError, CreateAliasTransaction] =
for {
_sender <- PublicKeyAccount.fromBase58String(senderPublicKey)
_proofBytes <- proofs.traverse(s => parseBase58(s, "invalid proof", Proofs.MaxProofStringSize))
_proofs <- Proofs.create(_proofBytes)
_alias <- Alias.buildWithCurrentNetworkByte(alias)
_t <- CreateAliasTransactionV2.create(version, _sender, _alias, fee, timestamp, _proofs)
} yield _t
}

object SignedCreateAliasV2Request {
implicit val broadcastAliasV2RequestReadsFormat: Format[SignedCreateAliasV2Request] = Json.format
}
Loading

0 comments on commit d24c5da

Please sign in to comment.