diff --git a/newm-chain-db/src/main/kotlin/io/newm/chain/database/repository/LedgerRepositoryImpl.kt b/newm-chain-db/src/main/kotlin/io/newm/chain/database/repository/LedgerRepositoryImpl.kt index 6a2eaf9c..59a3e9e3 100644 --- a/newm-chain-db/src/main/kotlin/io/newm/chain/database/repository/LedgerRepositoryImpl.kt +++ b/newm-chain-db/src/main/kotlin/io/newm/chain/database/repository/LedgerRepositoryImpl.kt @@ -1576,9 +1576,9 @@ class LedgerRepositoryImpl : LedgerRepository { override fun queryTransactionConfirmationCounts(txIds: List): Map = transaction { - val tipBlockExpression = LedgerUtxosTable.blockCreated.max() + val tipBlockExpression = ChainTable.blockNumber.max() val tipBlock: Long = - LedgerUtxosTable.select(tipBlockExpression).firstOrNull()?.let { + ChainTable.select(tipBlockExpression).firstOrNull()?.let { it[tipBlockExpression] } ?: 0L @@ -1590,7 +1590,7 @@ class LedgerRepositoryImpl : LedgerRepository { .associate { row -> val txId = row[LedgerUtxosTable.txId] val blockCreated = row[LedgerUtxosTable.blockCreated] - txId to max(tipBlock - blockCreated, 0L) + txId to max(tipBlock - blockCreated + 1L, 0L) } txIds.associateWith { txId -> (ledgerMap[txId] ?: 0L) } diff --git a/newm-chain-db/src/test/kotlin/io/newm/chain/database/repository/QueryTransactionInfoRepositoryTest.kt b/newm-chain-db/src/test/kotlin/io/newm/chain/database/repository/QueryTransactionInfoRepositoryTest.kt index 787780b5..5c5b9bc3 100644 --- a/newm-chain-db/src/test/kotlin/io/newm/chain/database/repository/QueryTransactionInfoRepositoryTest.kt +++ b/newm-chain-db/src/test/kotlin/io/newm/chain/database/repository/QueryTransactionInfoRepositoryTest.kt @@ -214,6 +214,40 @@ class QueryTransactionInfoRepositoryTest { } } + @Test + fun `queryTransactionConfirmationCounts uses chain tip and is inclusive`() { + (100L..106L).forEach { blockNumber -> + insertChainBlock(blockNumber = blockNumber, slotNumber = 1000L + blockNumber) + } + insertLedgerUtxo( + address = "addr_test_dest1", + txId = "target-tx", + txIx = 0, + lovelace = "2500", + blockCreated = 100L, + ) + + val result = repository.queryTransactionConfirmationCounts(listOf("target-tx", "missing-tx")) + + assertThat(result["target-tx"]).isEqualTo(7L) + assertThat(result["missing-tx"]).isEqualTo(0L) + } + + @Test + fun `queryTransactionConfirmationCounts returns zero when chain tip is missing`() { + insertLedgerUtxo( + address = "addr_test_dest1", + txId = "target-tx", + txIx = 0, + lovelace = "2500", + blockCreated = 100L, + ) + + val result = repository.queryTransactionConfirmationCounts(listOf("target-tx")) + + assertThat(result["target-tx"]).isEqualTo(0L) + } + private fun insertChainBlock( blockNumber: Long, slotNumber: Long, diff --git a/newm-chain/build.gradle.kts b/newm-chain/build.gradle.kts index e3ec518a..eafe6a1f 100644 --- a/newm-chain/build.gradle.kts +++ b/newm-chain/build.gradle.kts @@ -114,13 +114,17 @@ tasks.withType { } } -tasks.withType { +tasks.withType().configureEach { manifest { attributes( - "Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()), "Main-Class" to "io.newm.chain.ApplicationKt" ) } + doFirst { + manifest.attributes( + "Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()) + ) + } } // Ensure start scripts tasks depend on shadowJar since we use it as the main jar diff --git a/newm-server/build.gradle.kts b/newm-server/build.gradle.kts index ac0176d4..9190dc35 100644 --- a/newm-server/build.gradle.kts +++ b/newm-server/build.gradle.kts @@ -146,13 +146,17 @@ dependencies { "integTestImplementation"(Dependencies.Typesafe.CONFIG) } -tasks.withType { +tasks.withType().configureEach { manifest { attributes( - "Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()), "Main-Class" to "io.newm.server.ApplicationKt" ) } + doFirst { + manifest.attributes( + "Build-Time" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()) + ) + } } tasks.withType {