diff --git a/server/app/com/xsn/explorer/models/rpc/Transaction.scala b/server/app/com/xsn/explorer/models/rpc/Transaction.scala index b7bf469..0ab44f9 100644 --- a/server/app/com/xsn/explorer/models/rpc/Transaction.scala +++ b/server/app/com/xsn/explorer/models/rpc/Transaction.scala @@ -21,16 +21,17 @@ object Transaction { val builder = (__ \ 'txid).read[TransactionId] and (__ \ 'size).read[Size] and (__ \ 'blockhash).read[Blockhash] and - (__ \ 'time).read[Long] and - (__ \ 'blocktime).read[Long] and + (__ \ 'time).readNullable[Long] and + (__ \ 'blocktime).readNullable[Long] and (__ \ 'confirmations).read[Confirmations] and (__ \ 'vout).read[List[TransactionVOUT]] and (__ \ 'vin).readNullable[List[JsValue]] .map(_ getOrElse List.empty) .map { list => list.flatMap(_.asOpt[TransactionVIN]) } + // TODO: Enfore blocktime and time fields when https://github.com/X9Developers/XSN/issues/72 is fixed. builder.apply { (id, size, blockHash, time, blockTime, confirmations, vout, vin) => - Transaction(id, size, blockHash, time, blockTime, confirmations, vin, vout) + Transaction(id, size, blockHash, time.getOrElse(0), blockTime.getOrElse(0), confirmations, vin, vout) } } } diff --git a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala index 341ed1a..c26b984 100644 --- a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala +++ b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala @@ -100,6 +100,24 @@ class XSNServiceRPCImplSpec extends WordSpec with MustMatchers with ScalaFutures } } + "handle transaction having no blocktime, nor time" in { + // TODO: Remove this test when https://github.com/X9Developers/XSN/issues/72 is fixed. + val txid = createTransactionId("f24cd135c34ebb9032f8bc5b45599f1424980d34583df2847c4a4db584c94e97") + 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.getTransaction(txid)) { result => + result.isGood mustEqual true + + val tx = result.get + tx.id mustEqual txid + } + } + "handle transaction not found" in { val txid = createTransactionId("0834641a7d30d8a2d2b451617599670445ee94ed7736e146c13be260c576c641") val responseBody = createRPCErrorResponse(-5, "No information available about transaction") diff --git a/server/test/resources/transactions/f24cd135c34ebb9032f8bc5b45599f1424980d34583df2847c4a4db584c94e97 b/server/test/resources/transactions/f24cd135c34ebb9032f8bc5b45599f1424980d34583df2847c4a4db584c94e97 new file mode 100644 index 0000000..726c2e5 --- /dev/null +++ b/server/test/resources/transactions/f24cd135c34ebb9032f8bc5b45599f1424980d34583df2847c4a4db584c94e97 @@ -0,0 +1,64 @@ +{ + "hex": "0100000001f402c6a51689c50c65ffb6231283dcaedec8e882ceee34281269592f97937917010000006a4730440220187bd17e8e4e5fd984eeb7413e08e4158bed0489daf4d172cfa5882e0ab5e9240220175beade81605352083a5dc9ca38c00268497d3c4017ce883701c0049ac557e8012102eca9a91d1e0a6cfa8f4fff2fc0ae97d251458695837df3d6779b9d9d20f556d7ffffffff03000000000000000000b781be9b1a0000001976a914200ed407409342e079826fdde05471cbb10b9a7488ac400cb378000000001976a914144842839c0d7ebe1492fe9910762b57aab86cf988ac00000000", + "txid": "f24cd135c34ebb9032f8bc5b45599f1424980d34583df2847c4a4db584c94e97", + "size": 234, + "version": 1, + "locktime": 0, + "vin": [ + { + "txid": "177993972f5969122834eece82e8c8deaedc831223b6ff650cc58916a5c602f4", + "vout": 1, + "scriptSig": { + "asm": "30440220187bd17e8e4e5fd984eeb7413e08e4158bed0489daf4d172cfa5882e0ab5e9240220175beade81605352083a5dc9ca38c00268497d3c4017ce883701c0049ac557e8[ALL] 02eca9a91d1e0a6cfa8f4fff2fc0ae97d251458695837df3d6779b9d9d20f556d7", + "hex": "4730440220187bd17e8e4e5fd984eeb7413e08e4158bed0489daf4d172cfa5882e0ab5e9240220175beade81605352083a5dc9ca38c00268497d3c4017ce883701c0049ac557e8012102eca9a91d1e0a6cfa8f4fff2fc0ae97d251458695837df3d6779b9d9d20f556d7" + }, + "value": 1122.57103223, + "valueSat": 112257103223, + "address": "XdcMDgA1sWNfBPq9U5P5ngcP5L3sePMCpL", + "sequence": 4294967295 + } + ], + "vout": [ + { + "value": 0.00000000, + "valueSat": 0, + "n": 0, + "scriptPubKey": { + "asm": "", + "hex": "", + "type": "nonstandard" + } + }, + { + "value": 1142.82103223, + "valueSat": 114282103223, + "n": 1, + "scriptPubKey": { + "asm": "OP_DUP OP_HASH160 200ed407409342e079826fdde05471cbb10b9a74 OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914200ed407409342e079826fdde05471cbb10b9a7488ac", + "reqSigs": 1, + "type": "pubkeyhash", + "addresses": [ + "XdcMDgA1sWNfBPq9U5P5ngcP5L3sePMCpL" + ] + } + }, + { + "value": 20.25000000, + "valueSat": 2025000000, + "n": 2, + "scriptPubKey": { + "asm": "OP_DUP OP_HASH160 144842839c0d7ebe1492fe9910762b57aab86cf9 OP_EQUALVERIFY OP_CHECKSIG", + "hex": "76a914144842839c0d7ebe1492fe9910762b57aab86cf988ac", + "reqSigs": 1, + "type": "pubkeyhash", + "addresses": [ + "XcY5unoGBDZdRJJrHXPePGJgK3W7Th9LzG" + ] + } + } + ], + "blockhash": "ee5ee42a4f9c106808b8867f9469a47cb7d5fc5f71ec58e56f0bff895ac2b78d", + "height": -1, + "confirmations": 0 +} \ No newline at end of file