diff --git a/core-deterministic/testing/verifier/src/main/kotlin/net/corda/deterministic/verifier/TransactionVerificationRequest.kt b/core-deterministic/testing/verifier/src/main/kotlin/net/corda/deterministic/verifier/TransactionVerificationRequest.kt index 0ed50800f9..c259f2791c 100644 --- a/core-deterministic/testing/verifier/src/main/kotlin/net/corda/deterministic/verifier/TransactionVerificationRequest.kt +++ b/core-deterministic/testing/verifier/src/main/kotlin/net/corda/deterministic/verifier/TransactionVerificationRequest.kt @@ -2,8 +2,8 @@ package net.corda.deterministic.verifier import net.corda.core.contracts.Attachment import net.corda.core.contracts.ContractAttachment -import net.corda.core.contracts.ContractClassName import net.corda.core.internal.DEPLOYED_CORDAPP_UPLOADER +import net.corda.core.internal.toLtxDjvmInternal import net.corda.core.node.NetworkParameters import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.SerializedBytes @@ -25,13 +25,10 @@ class TransactionVerificationRequest(val wtxToVerify: SerializedBytes() @Suppress("DEPRECATION") - return wtxToVerify.deserialize().toLedgerTransaction( - resolveIdentity = { null }, + return wtxToVerify.deserialize().toLtxDjvmInternal( resolveAttachment = { attachmentMap[it] }, resolveStateRef = { deps[it.txhash]?.outputs?.get(it.index) }, - resolveContractAttachment = { contractAttachmentMap[it.contract]?.id }, resolveParameters = { networkParameters.deserialize() } ) } diff --git a/core/src/main/kotlin/net/corda/core/internal/DjvmUtils.kt b/core/src/main/kotlin/net/corda/core/internal/DjvmUtils.kt new file mode 100644 index 0000000000..755a7959e1 --- /dev/null +++ b/core/src/main/kotlin/net/corda/core/internal/DjvmUtils.kt @@ -0,0 +1,20 @@ +@file:KeepForDJVM + +package net.corda.core.internal + +import net.corda.core.KeepForDJVM +import net.corda.core.contracts.Attachment +import net.corda.core.contracts.StateRef +import net.corda.core.contracts.TransactionState +import net.corda.core.crypto.SecureHash +import net.corda.core.node.NetworkParameters +import net.corda.core.transactions.LedgerTransaction +import net.corda.core.transactions.WireTransaction + +fun WireTransaction.toLtxDjvmInternal( + resolveAttachment: (SecureHash) -> Attachment?, + resolveStateRef: (StateRef) -> TransactionState<*>?, + resolveParameters: (SecureHash?) -> NetworkParameters? +): LedgerTransaction { + return toLtxDjvmInternalBridge(resolveAttachment, resolveStateRef, resolveParameters) +} diff --git a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt index a3f2a13794..2d0c76b950 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt @@ -130,18 +130,37 @@ class WireTransaction(componentGroups: List, val privacySalt: Pr */ @Deprecated("Use toLedgerTransaction(ServicesForTransaction) instead") @Throws(AttachmentResolutionException::class, TransactionResolutionException::class) - @JvmOverloads fun toLedgerTransaction( resolveIdentity: (PublicKey) -> Party?, resolveAttachment: (SecureHash) -> Attachment?, resolveStateRef: (StateRef) -> TransactionState<*>?, - @Suppress("UNUSED_PARAMETER") resolveContractAttachment: (TransactionState) -> AttachmentId?, - resolveParameters: (SecureHash?) -> NetworkParameters? = { null } // TODO This { null } is left here only because of API stability. It doesn't make much sense anymore as it will fail on transaction verification. + @Suppress("UNUSED_PARAMETER") resolveContractAttachment: (TransactionState) -> AttachmentId? ): LedgerTransaction { // This reverts to serializing the resolved transaction state. - return toLedgerTransactionInternal(resolveIdentity, resolveAttachment, { stateRef -> resolveStateRef(stateRef)?.serialize() }, resolveParameters, + return toLedgerTransactionInternal( + resolveIdentity, + resolveAttachment, + { stateRef -> resolveStateRef(stateRef)?.serialize() }, + { null }, // Returning a dummy `missingAttachment` Attachment allows this deprecated method to work and it disables "contract version no downgrade rule" as a dummy Attachment returns version 1 - { it -> resolveAttachment(it.txhash) ?: missingAttachment }) + { it -> resolveAttachment(it.txhash) ?: missingAttachment } + ) + } + + // Especially crafted for TransactionVerificationRequest + @CordaInternal + internal fun toLtxDjvmInternalBridge( + resolveAttachment: (SecureHash) -> Attachment?, + resolveStateRef: (StateRef) -> TransactionState<*>?, + resolveParameters: (SecureHash?) -> NetworkParameters? + ): LedgerTransaction { + return toLedgerTransactionInternal( + { null }, + resolveAttachment, + { stateRef -> resolveStateRef(stateRef)?.serialize() }, + resolveParameters, + { it -> resolveAttachment(it.txhash) ?: missingAttachment } + ) } private fun toLedgerTransactionInternal(