Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction> 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<Transaction> 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<Transaction> result = service.getTransaction(Network.MAINNET, "tx1");

assertTrue(result.isSuccessful());
assertNull(result.getValue().getValidContract());
assertNull(result.getValue().getIndex());
}
}
Loading