ENT-12291: Removed from rotated keys from public api.

This commit is contained in:
Adel El-Beik 2024-10-09 17:16:04 +01:00
parent 828066a646
commit a2537d59f5
7 changed files with 26 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package net.corda.core.internal
import co.paralleluniverse.fibers.Suspendable
import net.corda.core.DeleteForDJVM
import net.corda.core.contracts.RotatedKeys
import net.corda.core.internal.notary.NotaryService
import net.corda.core.node.ServiceHub
import net.corda.core.node.StatesToRecord
@ -24,6 +25,8 @@ interface ServiceHubCoreInternal : ServiceHub {
fun createTransactionsResolver(flow: ResolveTransactionsFlow): TransactionsResolver
val attachmentsClassLoaderCache: AttachmentsClassLoaderCache
val rotatedKeys: RotatedKeys
}
interface TransactionsResolver {

View File

@ -8,6 +8,7 @@ import net.corda.core.crypto.algorithm
import net.corda.core.crypto.internal.DigestAlgorithmFactory
import net.corda.core.flows.FlowLogic
import net.corda.core.identity.Party
import net.corda.core.node.ServiceHub
import net.corda.core.node.ServicesForResolution
import net.corda.core.serialization.*
import net.corda.core.transactions.*
@ -16,6 +17,20 @@ import java.io.ByteArrayOutputStream
import java.security.PublicKey
import kotlin.reflect.KClass
fun ServiceHub.retrieveRotatedKeys(): RotatedKeys {
if (this is ServiceHubCoreInternal) {
return this.rotatedKeys
}
var clazz: Class<*> = javaClass
while (true) {
if (clazz.name == "net.corda.testing.node.MockServices") {
return clazz.getDeclaredMethod("getRotatedKeys").apply { isAccessible = true }.invoke(this) as RotatedKeys
}
clazz = clazz.superclass ?: throw ClassCastException("${javaClass.name} is not a ServiceHub")
}
}
/** Constructs a [NotaryChangeWireTransaction]. */
class NotaryChangeTransactionBuilder(val inputs: List<StateRef>,
val notary: Party,

View File

@ -171,12 +171,6 @@ interface ServiceHub : ServicesForResolution {
*/
val transactionVerifierService: TransactionVerifierService
/**
* INTERNAL. DO NOT USE.
* @suppress
*/
val rotatedKeys: RotatedKeys
/**
* A [Clock] representing the node's current time. This should be used in preference to directly accessing the
* clock so the current time can be controlled during unit testing.

View File

@ -535,6 +535,7 @@ open class TransactionBuilder(
val resolvedOutputStates = outputStates.map {
val outputConstraint = it.constraint
if (outputConstraint in automaticConstraints) {
it.copy(constraint = defaultOutputConstraint)
} else {
@ -553,9 +554,9 @@ open class TransactionBuilder(
}
private fun getRotatedKeys(services: ServiceHub?): RotatedKeys {
return services?.rotatedKeys ?: CordaRotatedKeys.keys.also {
return services?.let { services.retrieveRotatedKeys() } ?: CordaRotatedKeys.keys.also {
log.warn("WARNING: You must pass in a ServiceHub reference to TransactionBuilder to resolve " +
"rotated keys defined in configuration. If you are writing a unit test then pass in a " +
"state pointers outside of flows. If you are writing a unit test then pass in a " +
"MockServices instance.")
}
}

View File

@ -28,6 +28,7 @@ import net.corda.core.serialization.DeprecatedConstructorForDeserialization
import net.corda.core.serialization.SerializationFactory
import net.corda.core.serialization.SerializedBytes
import net.corda.core.serialization.internal.AttachmentsClassLoaderCache
import net.corda.core.serialization.internal.AttachmentsClassLoaderForRotatedKeysOnlyImpl
import net.corda.core.serialization.serialize
import net.corda.core.utilities.OpaqueBytes
import java.security.PublicKey
@ -166,8 +167,7 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
{ stateRef -> resolveStateRef(stateRef)?.serialize() },
{ null },
Attachment::isUploaderTrusted,
null
// TODO : elbad01 : does rotated keys need to be passed here, or we use attachment class loader cache
attachmentsClassLoaderCache = AttachmentsClassLoaderForRotatedKeysOnlyImpl()
)
}

View File

@ -3,6 +3,7 @@ package net.corda.testing.node
import com.google.common.collect.MutableClassToInstanceMap
import net.corda.core.contracts.Attachment
import net.corda.core.contracts.ContractClassName
import net.corda.core.contracts.CordaRotatedKeys
import net.corda.core.contracts.RotatedKeys
import net.corda.core.contracts.StateRef
import net.corda.core.cordapp.CordappProvider
@ -457,10 +458,10 @@ open class MockServices private constructor(
override val cordappProvider: CordappProvider get() = mockCordappProvider
override var networkParametersService: NetworkParametersService = MockNetworkParametersStorage(initialNetworkParameters)
override val diagnosticsService: DiagnosticsService = NodeDiagnosticsService()
var rotatedKeys: RotatedKeys = CordaRotatedKeys.keys
protected val servicesForResolution: ServicesForResolution
get() = ServicesForResolutionImpl(identityService, attachments, cordappProvider, networkParametersService, validatedTransactions)
override val rotatedKeys: RotatedKeys = RotatedKeys()
internal fun makeVaultService(schemaService: SchemaService, database: CordaPersistence, cordappLoader: CordappLoader): VaultServiceInternal {
return NodeVaultService(

View File

@ -105,7 +105,7 @@ data class TestTransactionDSLInterpreter private constructor(
ThreadFactoryBuilder().setNameFormat("flow-external-operation-thread").build()
)
override val rotatedKeys: RotatedKeys = ledgerInterpreter.services.rotatedKeys
override val rotatedKeys: RotatedKeys = (ledgerInterpreter.services as? ServiceHubCoreInternal)?.rotatedKeys ?: CordaRotatedKeys.keys
override val attachmentTrustCalculator: AttachmentTrustCalculator =
ledgerInterpreter.services.attachments.let {