Browse Source

server: Return the txid after pushing a transaction to the network

master
Alexis Hernandez 6 years ago
parent
commit
aa05af72ac
  1. 6
      server/app/com/xsn/explorer/services/TransactionRPCService.scala
  2. 7
      server/app/com/xsn/explorer/services/XSNService.scala
  3. 2
      server/test/com/xsn/explorer/helpers/DummyXSNService.scala

6
server/app/com/xsn/explorer/services/TransactionRPCService.scala

@ -11,7 +11,7 @@ import com.xsn.explorer.util.Extensions.FutureOrExt
import javax.inject.Inject
import org.scalactic.{Bad, Good, One, Or}
import org.slf4j.LoggerFactory
import play.api.libs.json.{JsObject, JsString, JsValue}
import play.api.libs.json.{JsObject, JsString, JsValue, Json}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
@ -125,8 +125,8 @@ class TransactionRPCService @Inject() (
def sendRawTransaction(hexString: String): FutureApplicationResult[JsValue] = {
val result = for {
hex <- Or.from(HexString.from(hexString), One(InvalidRawTransactionError)).toFutureOr
_ <- xsnService.sendRawTransaction(hex).toFutureOr
} yield JsObject.empty + ("hex" -> JsString(hex.string))
txid <- xsnService.sendRawTransaction(hex).toFutureOr
} yield Json.obj("txid" -> JsString(txid))
result.toFuture
}

7
server/app/com/xsn/explorer/services/XSNService.scala

@ -46,7 +46,7 @@ trait XSNService {
def getUnspentOutputs(address: Address): FutureApplicationResult[JsValue]
def sendRawTransaction(hex: HexString): FutureApplicationResult[Unit]
def sendRawTransaction(hex: HexString): FutureApplicationResult[String]
def cleanGenesisBlock(block: rpc.Block): rpc.Block = {
Option(block)
@ -394,7 +394,7 @@ class XSNServiceRPCImpl @Inject() (
}
}
override def sendRawTransaction(hex: HexString): FutureApplicationResult[Unit] = {
override def sendRawTransaction(hex: HexString): FutureApplicationResult[String] = {
val errorCodeMapper = Map(
-26 -> InvalidRawTransactionError,
-22 -> InvalidRawTransactionError,
@ -411,8 +411,7 @@ class XSNServiceRPCImpl @Inject() (
server
.post(body)
.map { response =>
val maybe = getResult[String](response, errorCodeMapper)
.map { _.map(_ => ()) }
val maybe = getResult[String](response, errorCodeMapper).map { _.map(_.toString()) }
maybe.getOrElse {
logger.warn(s"Unexpected response from XSN Server, status = ${response.status}, response = ${response.body}")

2
server/test/com/xsn/explorer/helpers/DummyXSNService.scala

@ -24,5 +24,5 @@ class DummyXSNService extends XSNService {
override def getMasternodes(): FutureApplicationResult[List[rpc.Masternode]] = ???
override def getMasternode(ipAddress: IPAddress): FutureApplicationResult[Masternode] = ???
override def getUnspentOutputs(address: Address): FutureApplicationResult[JsValue] = ???
override def sendRawTransaction(hex: HexString): FutureApplicationResult[Unit] = ???
override def sendRawTransaction(hex: HexString): FutureApplicationResult[String] = ???
}

Loading…
Cancel
Save