Skip to content

Commit

Permalink
fixed /waves/external-payment, relock to Scorex 1.2.9-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarin55 committed Jun 12, 2016
1 parent 40bb25c commit 658b404
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 44 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scalaVersion := "2.11.8"

resolvers += "SonaType" at "https://oss.sonatype.org/content/groups/public"

val modulesVersion = "1.2.8-SNAPSHOT"
val modulesVersion = "1.2.9-SNAPSHOT"

libraryDependencies ++= Seq(
"org.consensusresearch" %% "scorex-basics" % modulesVersion,
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**0.2.0-RC5**

* /waves/external-payment returns error for incorrect recipient

**0.2.0-RC4**

* Fixed issue with incorrect Handshake
Expand Down
38 changes: 19 additions & 19 deletions lock.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dependencyOverrides in ThisBuild ++= Set(
"ch.qos.logback" % "logback-classic" % "1.1.7",
"ch.qos.logback" % "logback-core" % "1.1.7",
"com.chuusai" % "shapeless_2.11" % "2.3.0",
"com.chuusai" % "shapeless_2.11" % "2.3.1",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.5.4",
"com.fasterxml.jackson.core" % "jackson-core" % "2.5.4",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.5.4",
Expand All @@ -18,36 +18,36 @@ dependencyOverrides in ThisBuild ++= Set(
"com.fasterxml.jackson.module" % "jackson-module-jaxb-annotations" % "2.4.5",
"com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.4.2",
"com.github.pathikrit" % "better-files_2.11" % "2.13.0",
"com.github.swagger-akka-http" % "swagger-akka-http_2.11" % "0.6.2",
"com.github.swagger-akka-http" % "swagger-akka-http_2.11" % "0.7.0",
"com.google.code.findbugs" % "annotations" % "2.0.1",
"com.google.code.findbugs" % "jsr305" % "2.0.1",
"com.google.guava" % "guava" % "18.0",
"com.h2database" % "h2-mvstore" % "1.4.191",
"com.h2database" % "h2-mvstore" % "1.4.192",
"com.ning" % "async-http-client" % "1.9.11",
"com.thoughtworks.paranamer" % "paranamer" % "2.6",
"com.typesafe" % "config" % "1.3.0",
"com.typesafe" % "ssl-config-akka_2.11" % "0.2.1",
"com.typesafe" % "ssl-config-core_2.11" % "0.2.1",
"com.typesafe.akka" % "akka-actor_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-http-core_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-http-experimental_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-http-spray-json-experimental_2.11" % "2.0.3",
"com.typesafe.akka" % "akka-parsing_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-stream_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-testkit_2.11" % "2.4.4",
"com.typesafe.akka" % "akka-actor_2.11" % "2.4.7",
"com.typesafe.akka" % "akka-http-core_2.11" % "2.4.7",
"com.typesafe.akka" % "akka-http-experimental_2.11" % "2.4.7",
"com.typesafe.akka" % "akka-http-spray-json-experimental_2.11" % "2.4.6",
"com.typesafe.akka" % "akka-parsing_2.11" % "2.4.7",
"com.typesafe.akka" % "akka-stream_2.11" % "2.4.7",
"com.typesafe.akka" % "akka-testkit_2.11" % "2.4.7",
"com.typesafe.play" % "play-datacommons_2.11" % "2.4.6",
"com.typesafe.play" % "play-functional_2.11" % "2.4.6",
"com.typesafe.play" % "play-iteratees_2.11" % "2.4.6",
"com.typesafe.play" % "play-json_2.11" % "2.4.6",
"commons-net" % "commons-net" % "3.4",
"commons-net" % "commons-net" % "3.5",
"io.netty" % "netty" % "3.10.0.Final",
"io.spray" % "spray-json_2.11" % "1.3.2",
"io.spray" % "spray-testkit_2.11" % "1.3.3",
"io.spray" % "spray-util_2.11" % "1.3.3",
"io.swagger" % "swagger-annotations" % "1.5.8",
"io.swagger" % "swagger-core" % "1.5.8",
"io.swagger" % "swagger-jaxrs" % "1.5.8",
"io.swagger" % "swagger-models" % "1.5.8",
"io.swagger" % "swagger-annotations" % "1.5.9",
"io.swagger" % "swagger-core" % "1.5.9",
"io.swagger" % "swagger-jaxrs" % "1.5.9",
"io.swagger" % "swagger-models" % "1.5.9",
"io.swagger" % "swagger-scala-module_2.11" % "1.0.2",
"javax.validation" % "validation-api" % "1.1.0.Final",
"javax.ws.rs" % "jsr311-api" % "1.1.1",
Expand All @@ -57,9 +57,9 @@ dependencyOverrides in ThisBuild ++= Set(
"org.apache.commons" % "commons-lang3" % "3.2.1",
"org.bitlet" % "weupnp" % "0.1.4",
"org.codehaus.woodstox" % "stax2-api" % "3.1.4",
"org.consensusresearch" % "scorex-basics_2.11" % "1.2.8-SNAPSHOT",
"org.consensusresearch" % "scorex-consensus_2.11" % "1.2.8-SNAPSHOT",
"org.consensusresearch" % "scorex-transaction_2.11" % "1.2.8-SNAPSHOT",
"org.consensusresearch" % "scorex-basics_2.11" % "1.2.9-SNAPSHOT",
"org.consensusresearch" % "scorex-consensus_2.11" % "1.2.9-SNAPSHOT",
"org.consensusresearch" % "scorex-transaction_2.11" % "1.2.9-SNAPSHOT",
"org.consensusresearch" % "scrypto_2.11" % "1.0.4",
"org.javassist" % "javassist" % "3.18.2-GA",
"org.joda" % "joda-convert" % "1.7",
Expand All @@ -83,4 +83,4 @@ dependencyOverrides in ThisBuild ++= Set(
"org.whispersystems" % "curve25519-java" % "0.2.4",
"org.yaml" % "snakeyaml" % "1.12"
)
// LIBRARY_DEPENDENCIES_HASH 51f27f7ad38de8d821ad86bcdb9ee2a5d8cc0a87
// LIBRARY_DEPENDENCIES_HASH f7b2c2b9f57e33e87c8b399e0cd3626908096795
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
app {
product = "TWaves"
release = "Release0"
version = "0.2.0-RC4"
version = "0.2.0-RC5"
}
scorex {
fastHash = "scorex.crypto.hash.Blake2b256"
Expand Down
57 changes: 40 additions & 17 deletions src/main/scala/scorex/waves/http/WavesApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,52 @@ case class WavesApiRoute(override val application: Application)(implicit val con
case err: JsError =>
WrongJson.json
case JsSuccess(payment: ExternalPayment, _) =>
val txTry = transactionModule.broadcastPayment(payment)
if (txTry.isSuccess) {
val tx = txTry.get
if (!tx.signatureValid)
InvalidSignature.json
else {
tx.validate match {
case ValidationResult.ValidateOke =>
tx.json

case ValidationResult.InvalidAddress =>
InvalidAddress.json
transactionModule.broadcastPayment(payment) match {
case Left(tx) =>
if (!tx.signatureValid) InvalidSignature.json
else {
tx.validate match {
case ValidationResult.ValidateOke =>
tx.json

case ValidationResult.NegativeAmount =>
NegativeAmount.json
case ValidationResult.InvalidAddress =>
InvalidAddress.json

case ValidationResult.NegativeFee =>
NegativeFee.json
case ValidationResult.NegativeAmount =>
NegativeAmount.json

case ValidationResult.NegativeFee =>
NegativeFee.json
}
}
case Right(e) => e match {
case ValidationResult.NoBalance => NoBalance.json
case ValidationResult.InvalidAddress => InvalidAddress.json
}
} else {
NoBalance.json
}
// if (txTry.isSuccess) {
// val tx = txTry.get
// if (!tx.signatureValid)
// InvalidSignature.json
// else {
// tx.validate match {
// case ValidationResult.ValidateOke =>
// tx.json
//
// case ValidationResult.InvalidAddress =>
// InvalidAddress.json
//
// case ValidationResult.NegativeAmount =>
// NegativeAmount.json
//
// case ValidationResult.NegativeFee =>
// NegativeFee.json
// }
// }
// } else {
// NoBalance.json
// }
}
}.getOrElse(WrongJson.json).toString

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import scorex.app.Application
import scorex.block.BlockField
import scorex.crypto.encode.Base58
import scorex.settings.Settings
import scorex.transaction.LagonakiTransaction.ValidationResult
import scorex.transaction.LagonakiTransaction.ValidationResult.ValidationResult
import scorex.transaction._
import scorex.utils.NTP

Expand All @@ -27,18 +29,24 @@ class WavesTransactionModule(implicit override val settings: TransactionSettings
/**
* Publish signed payment transaction which generated outside node
*/
def broadcastPayment(externalPayment: ExternalPayment): Try[PaymentTransaction] = {
def broadcastPayment(externalPayment: ExternalPayment): Either[PaymentTransaction, ValidationResult] = {
val time = externalPayment.timestamp
val sigBytes = Base58.decode(externalPayment.signature).get
val senderPubKey = Base58.decode(externalPayment.senderPublicKey).get
val recipientAccount = new Account(externalPayment.recipient)
val payment = new PaymentTransaction(new PublicKeyAccount(senderPubKey),
recipientAccount, externalPayment.amount, externalPayment.fee, time, sigBytes)
if (blockStorage.state.isValid(payment)) {
onNewOffchainTransaction(payment)
Success(payment)
} else {
Failure(new Exception(NoBalance.message))

payment.validate match {
case ValidationResult.ValidateOke => {
if (blockStorage.state.isValid(payment)) {
onNewOffchainTransaction(payment)
Left(payment)
} else {
Right(ValidationResult.NoBalance)
}
}
case error: ValidationResult => Right(error)
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/scala/scorex/waves/WavesAPISpecification.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package scorex.waves

import org.scalatest.{FunSuite, Matchers}
import play.api.libs.json.Json
import scorex.api.http.InvalidAddress
import scorex.waves.transaction.ExternalPayment

class WavesAPISpecification extends FunSuite with Matchers {

import TestingCommons._

test("/waves/external-payment API route cant send to address from another net") {

val senderPublicKey = "GvXeYd2iFJUNV7KgeGV2cdnScyrEvrr9uPYJeQFtvg21"
val recipient = "3PBWXDFUc86N2EQxKJmW8eFco65xTyMZx6J"
val timestamp = 1465391445252L
val amount = 10000000000000L
val payment = ExternalPayment(timestamp, amount, 1L, senderPublicKey, recipient, "1")
val json = Json.toJson(payment).toString

val response = postRequest(us = "/waves/external-payment", body = json)
assert(response.toString == InvalidAddress.json.toString)
}
}

0 comments on commit 658b404

Please sign in to comment.