diff --git a/src/main/java/adlabs/nexus/client/backend/api/transaction/model/Transaction.java b/src/main/java/adlabs/nexus/client/backend/api/transaction/model/Transaction.java index 26275bc..5e97161 100644 --- a/src/main/java/adlabs/nexus/client/backend/api/transaction/model/Transaction.java +++ b/src/main/java/adlabs/nexus/client/backend/api/transaction/model/Transaction.java @@ -26,6 +26,19 @@ public class Transaction { private String totalOutput; private String fee; private String deposit; + /** + * Whether the transaction's Plutus scripts all succeeded. Null where the provider does + * not report it. Distinct from {@link TxPlutusContract#getValidContract()}, which is + * per-script-execution; this one is transaction-level. + */ + @JsonProperty("valid_contract") + private Boolean validContract; + /** + * Zero-based position of the transaction within its block, so it can be identified by + * (block, index) rather than by hash alone. Null where the provider does not report it. + * Serialized as {@code index}, not snake_case, so no @JsonProperty is needed. + */ + private Integer index; @JsonProperty("invalid_before") private String invalidBefore; @JsonProperty("invalid_after") diff --git a/src/test/java/adlabs/nexus/client/backend/api/transaction/TransactionServiceTest.java b/src/test/java/adlabs/nexus/client/backend/api/transaction/TransactionServiceTest.java index 3cbd88a..f9853cf 100644 --- a/src/test/java/adlabs/nexus/client/backend/api/transaction/TransactionServiceTest.java +++ b/src/test/java/adlabs/nexus/client/backend/api/transaction/TransactionServiceTest.java @@ -76,4 +76,45 @@ void getTransactionsCbor_postsHashArray() throws Exception { assertEquals("/api/transactions/cbor?network=cardano-mainnet", req.getPath()); assertEquals("[\"h1\",\"h2\"]", req.getBody().readUtf8()); } + + @Test + void getTransaction_mapsValidContractAndIndex() throws Exception { + // Shape verified against mainnet tx 4847714e...c6710d25: both fields are top-level, + // valid_contract is snake_case, index is not. + server.enqueue(new MockResponse().setResponseCode(200).setBody( + "{\"txHash\":\"tx1\",\"valid_contract\":true,\"index\":5,\"fee\":\"170000\"}")); + + Result result = service.getTransaction(Network.MAINNET, "tx1"); + + assertTrue(result.isSuccessful()); + assertEquals(Boolean.TRUE, result.getValue().getValidContract()); + assertEquals(Integer.valueOf(5), result.getValue().getIndex()); + } + + @Test + void getTransaction_indexZeroIsNotReadAsAbsent() throws Exception { + // index 0 is the first transaction in a block, not a missing value. + server.enqueue(new MockResponse().setResponseCode(200).setBody( + "{\"txHash\":\"tx1\",\"valid_contract\":false,\"index\":0}")); + + Result result = service.getTransaction(Network.MAINNET, "tx1"); + + assertTrue(result.isSuccessful()); + assertEquals(Integer.valueOf(0), result.getValue().getIndex()); + assertEquals(Boolean.FALSE, result.getValue().getValidContract()); + } + + @Test + void getTransaction_absentValidContractAndIndexStayNull() throws Exception { + // Providers that do not report them (and networks with no yaci datasource for the + // index enrichment) omit both; they must not default to false/0. + server.enqueue(new MockResponse().setResponseCode(200).setBody( + "{\"txHash\":\"tx1\",\"fee\":\"170000\"}")); + + Result result = service.getTransaction(Network.MAINNET, "tx1"); + + assertTrue(result.isSuccessful()); + assertNull(result.getValue().getValidContract()); + assertNull(result.getValue().getIndex()); + } }