diff --git a/server/app/com/xsn/explorer/services/XSNService.scala b/server/app/com/xsn/explorer/services/XSNService.scala index c075dae..29a06a2 100644 --- a/server/app/com/xsn/explorer/services/XSNService.scala +++ b/server/app/com/xsn/explorer/services/XSNService.scala @@ -20,6 +20,8 @@ trait XSNService { def getTransaction(txid: TransactionId): FutureApplicationResult[rpc.Transaction] + def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue] + def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] def getTransactions(address: Address): FutureApplicationResult[List[TransactionId]] @@ -68,6 +70,22 @@ class XSNServiceRPCImpl @Inject() ( } } + override def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue] = { + val errorCodeMapper = Map(-5 -> TransactionNotFoundError) + + server + .post(s"""{ "jsonrpc": "1.0", "method": "getrawtransaction", "params": ["${txid.string}", 1] }""") + .map { response => + + val maybe = getResult[JsValue](response, errorCodeMapper) + maybe.getOrElse { + logger.warn(s"Unexpected response from XSN Server, txid = ${txid.string}, status = ${response.status}, response = ${response.body}") + + Bad(XSNUnexpectedResponseError).accumulating + } + } + } + override def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] = { val body = s""" |{ diff --git a/server/test/com/xsn/explorer/helpers/DummyXSNService.scala b/server/test/com/xsn/explorer/helpers/DummyXSNService.scala index 3e9ec55..ad5f64f 100644 --- a/server/test/com/xsn/explorer/helpers/DummyXSNService.scala +++ b/server/test/com/xsn/explorer/helpers/DummyXSNService.scala @@ -4,10 +4,12 @@ import com.alexitc.playsonify.core.FutureApplicationResult import com.xsn.explorer.models._ import com.xsn.explorer.models.rpc.Masternode import com.xsn.explorer.services.XSNService +import play.api.libs.json.JsValue class DummyXSNService extends XSNService { override def getTransaction(txid: TransactionId): FutureApplicationResult[rpc.Transaction] = ??? + override def getRawTransaction(txid: TransactionId): FutureApplicationResult[JsValue] = ??? override def getAddressBalance(address: Address): FutureApplicationResult[rpc.AddressBalance] = ??? override def getTransactions(address: Address): FutureApplicationResult[List[TransactionId]] = ??? override def getBlock(blockhash: Blockhash): FutureApplicationResult[rpc.Block] = ??? diff --git a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala index c57e160..23b4d5f 100644 --- a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala +++ b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala @@ -157,6 +157,24 @@ class XSNServiceRPCImplSpec extends WordSpec with MustMatchers with ScalaFutures } } + "getRawTransaction" should { + "retrieve the raw transaction" in { + val txid = createTransactionId("024aba1d535cfe5dd3ea465d46a828a57b00e1df012d7a2d158e0f7484173f7c") + val expected = TransactionLoader.json(txid.string) + + val responseBody = createRPCSuccessfulResponse(TransactionLoader.json(txid.string)) + val json = Json.parse(responseBody) + + when(response.status).thenReturn(200) + when(response.json).thenReturn(json) + when(request.post[String](anyString())(any())).thenReturn(Future.successful(response)) + + whenReady(service.getRawTransaction(txid)) { result => + result mustEqual Good(expected) + } + } + } + "getAddressBalance" should { "return the balance" in { val responseBody =