From c108637df623ed568b3f67319b69984a89d50f5f Mon Sep 17 00:00:00 2001 From: Matthew Nesbit Date: Thu, 21 Sep 2017 15:31:42 +0100 Subject: [PATCH] Remove unused certificate method from IdentityService. (#1582) Put wellKnownParty in methods that return a Party which is one. Fixup rebase --- .../corda/client/jackson/JacksonSupport.kt | 10 ++--- .../corda/confidential/IdentitySyncFlow.kt | 2 +- .../confidential/IdentitySyncFlowTests.kt | 6 +-- .../confidential/SwapIdentitiesFlowTests.kt | 4 +- .../net/corda/core/messaging/CordaRPCOps.kt | 4 +- .../kotlin/net/corda/core/node/ServiceHub.kt | 4 +- .../core/node/services/IdentityService.kt | 42 ++++++++++--------- docs/source/api-rpc.rst | 2 +- .../java/net/corda/docs/FlowCookbookJava.java | 2 +- .../kotlin/net/corda/docs/FlowCookbook.kt | 2 +- docs/source/tutorial-attachments.rst | 2 +- .../net/corda/finance/flows/CashExitFlow.kt | 2 +- .../corda/finance/flows/TwoPartyDealFlow.kt | 4 +- .../corda/finance/flows/TwoPartyTradeFlow.kt | 4 +- .../statemachine/LargeTransactionsTest.kt | 2 +- .../corda/node/internal/CordaRPCOpsImpl.kt | 8 ++-- .../identity/InMemoryIdentityService.kt | 11 +++-- .../identity/PersistentIdentityService.kt | 17 ++++---- .../network/PersistentNetworkMapCache.kt | 2 +- ...bstractPartyToX500NameAsStringConverter.kt | 4 +- .../network/InMemoryIdentityServiceTests.kt | 8 ++-- .../network/PersistentIdentityServiceTests.kt | 10 ++--- .../corda/attachmentdemo/AttachmentDemo.kt | 4 +- .../corda/bank/api/BankOfCordaClientApi.kt | 2 +- .../net/corda/bank/api/BankOfCordaWebApi.kt | 4 +- .../kotlin/net/corda/irs/flows/FixingFlow.kt | 2 +- .../kotlin/net/corda/vega/flows/SimmFlow.kt | 4 +- .../net/corda/vega/flows/SimmRevaluation.kt | 2 +- .../corda/traderdemo/TraderDemoClientApi.kt | 6 +-- 29 files changed, 88 insertions(+), 88 deletions(-) diff --git a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt index de028ed2e6..a9935f12fc 100644 --- a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt +++ b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt @@ -46,25 +46,25 @@ object JacksonSupport { // If you change this API please update the docs in the docsite (json.rst) interface PartyObjectMapper { - fun partyFromX500Name(name: CordaX500Name): Party? + fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? fun partyFromKey(owningKey: PublicKey): Party? fun partiesFromName(query: String): Set } class RpcObjectMapper(val rpc: CordaRPCOps, factory: JsonFactory, val fuzzyIdentityMatch: Boolean) : PartyObjectMapper, ObjectMapper(factory) { - override fun partyFromX500Name(name: CordaX500Name): Party? = rpc.partyFromX500Name(name) + override fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? = rpc.wellKnownPartyFromX500Name(name) override fun partyFromKey(owningKey: PublicKey): Party? = rpc.partyFromKey(owningKey) override fun partiesFromName(query: String) = rpc.partiesFromName(query, fuzzyIdentityMatch) } class IdentityObjectMapper(val identityService: IdentityService, factory: JsonFactory, val fuzzyIdentityMatch: Boolean) : PartyObjectMapper, ObjectMapper(factory) { - override fun partyFromX500Name(name: CordaX500Name): Party? = identityService.partyFromX500Name(name) + override fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? = identityService.wellKnownPartyFromX500Name(name) override fun partyFromKey(owningKey: PublicKey): Party? = identityService.partyFromKey(owningKey) override fun partiesFromName(query: String) = identityService.partiesFromName(query, fuzzyIdentityMatch) } class NoPartyObjectMapper(factory: JsonFactory) : PartyObjectMapper, ObjectMapper(factory) { - override fun partyFromX500Name(name: CordaX500Name): Party? = throw UnsupportedOperationException() + override fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? = throw UnsupportedOperationException() override fun partyFromKey(owningKey: PublicKey): Party? = throw UnsupportedOperationException() override fun partiesFromName(query: String) = throw UnsupportedOperationException() } @@ -192,7 +192,7 @@ object JacksonSupport { // how to parse the content return if (parser.text.contains("=")) { val principal = CordaX500Name.parse(parser.text) - mapper.partyFromX500Name(principal) ?: throw JsonParseException(parser, "Could not find a Party with name $principal") + mapper.wellKnownPartyFromX500Name(principal) ?: throw JsonParseException(parser, "Could not find a Party with name $principal") } else { val nameMatches = mapper.partiesFromName(parser.text) if (nameMatches.isEmpty()) { diff --git a/confidential-identities/src/main/kotlin/net/corda/confidential/IdentitySyncFlow.kt b/confidential-identities/src/main/kotlin/net/corda/confidential/IdentitySyncFlow.kt index e5f68de31f..01f520afda 100644 --- a/confidential-identities/src/main/kotlin/net/corda/confidential/IdentitySyncFlow.kt +++ b/confidential-identities/src/main/kotlin/net/corda/confidential/IdentitySyncFlow.kt @@ -79,7 +79,7 @@ object IdentitySyncFlow { override fun call(): Unit { progressTracker.currentStep = RECEIVING_IDENTITIES val allIdentities = otherSideSession.receive>().unwrap { it } - val unknownIdentities = allIdentities.filter { serviceHub.identityService.partyFromAnonymous(it) == null } + val unknownIdentities = allIdentities.filter { serviceHub.identityService.wellKnownPartyFromAnonymous(it) == null } progressTracker.currentStep = RECEIVING_CERTIFICATES val missingIdentities = otherSideSession.sendAndReceive>(unknownIdentities) diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt index 867931718b..6358fe92db 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt @@ -52,15 +52,15 @@ class IdentitySyncFlowTests { val issueFlow = aliceNode.services.startFlow(CashIssueAndPaymentFlow(1000.DOLLARS, ref, alice, anonymous, notary)) val issueTx = issueFlow.resultFuture.getOrThrow().stx val confidentialIdentity = issueTx.tx.outputs.map { it.data }.filterIsInstance().single().owner - assertNull(bobNode.database.transaction { bobNode.services.identityService.partyFromAnonymous(confidentialIdentity) }) + assertNull(bobNode.database.transaction { bobNode.services.identityService.wellKnownPartyFromAnonymous(confidentialIdentity) }) // Run the flow to sync up the identities aliceNode.services.startFlow(Initiator(bob, issueTx.tx)).resultFuture.getOrThrow() val expected = aliceNode.database.transaction { - aliceNode.services.identityService.partyFromAnonymous(confidentialIdentity) + aliceNode.services.identityService.wellKnownPartyFromAnonymous(confidentialIdentity) } val actual = bobNode.database.transaction { - bobNode.services.identityService.partyFromAnonymous(confidentialIdentity) + bobNode.services.identityService.wellKnownPartyFromAnonymous(confidentialIdentity) } assertEquals(expected, actual) } diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt index f974216870..684cd92c82 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt @@ -42,8 +42,8 @@ class SwapIdentitiesFlowTests { assertNotEquals(bob, bobAnonymousIdentity) // Verify that the anonymous identities look sane - assertEquals(alice.name, aliceNode.database.transaction { aliceNode.services.identityService.partyFromAnonymous(aliceAnonymousIdentity)!!.name }) - assertEquals(bob.name, bobNode.database.transaction { bobNode.services.identityService.partyFromAnonymous(bobAnonymousIdentity)!!.name }) + assertEquals(alice.name, aliceNode.database.transaction { aliceNode.services.identityService.wellKnownPartyFromAnonymous(aliceAnonymousIdentity)!!.name }) + assertEquals(bob.name, bobNode.database.transaction { bobNode.services.identityService.wellKnownPartyFromAnonymous(bobAnonymousIdentity)!!.name }) // Verify that the nodes have the right anonymous identities assertTrue { aliceAnonymousIdentity.owningKey in aliceNode.services.keyManagementService.keys } diff --git a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt index 84c42b228f..c4421d8b38 100644 --- a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt +++ b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt @@ -249,12 +249,12 @@ interface CordaRPCOps : RPCOps { * @param party identity to determine well known identity for. * @return well known identity, if found. */ - fun partyFromAnonymous(party: AbstractParty): Party? + fun wellKnownPartyFromAnonymous(party: AbstractParty): Party? /** Returns the [Party] corresponding to the given key, if found. */ fun partyFromKey(key: PublicKey): Party? /** Returns the [Party] with the X.500 principal as it's [Party.name]. */ - fun partyFromX500Name(x500Name: CordaX500Name): Party? + fun wellKnownPartyFromX500Name(x500Name: CordaX500Name): Party? /** * Returns a list of candidate matches for a given string, with optional fuzzy(ish) matching. Fuzzy matching may diff --git a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt index 7860c687e0..650f3bb486 100644 --- a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt +++ b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt @@ -309,7 +309,7 @@ interface ServiceHub : ServicesForResolution { @Throws(IllegalArgumentException::class) fun groupAbstractPartyByWellKnownParty(parties: Collection, ignoreUnrecognisedParties: Boolean): Map> { val partyToPublicKey: Iterable> = parties.mapNotNull { - (identityService.partyFromAnonymous(it) ?: if (ignoreUnrecognisedParties) return@mapNotNull null else throw IllegalArgumentException("Could not find Party for $it")) to it + (identityService.wellKnownPartyFromAnonymous(it) ?: if (ignoreUnrecognisedParties) return@mapNotNull null else throw IllegalArgumentException("Could not find Party for $it")) to it } return partyToPublicKey.toMultiMap() } @@ -331,7 +331,7 @@ interface ServiceHub : ServicesForResolution { /** * Remove this node from a map of well known [Party]s. * - * @return a new copy of the map, with the well known [Party] for this node removed. + * @return a new copy of the map, with he well known [Party] for this node removed. */ fun excludeMe(map: Map): Map = map.filterKeys { !myInfo.isLegalIdentity(it) } diff --git a/core/src/main/kotlin/net/corda/core/node/services/IdentityService.kt b/core/src/main/kotlin/net/corda/core/node/services/IdentityService.kt index da4ee3e600..41a60bb30d 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/IdentityService.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/IdentityService.kt @@ -42,46 +42,48 @@ interface IdentityService { fun getAllIdentities(): Iterable /** - * Get the certificate and path for a well known identity's owning key. + * Get the certificate and path for a known identity's owning key. * * @return the party and certificate, or null if unknown. */ fun certificateFromKey(owningKey: PublicKey): PartyAndCertificate? /** - * Get the certificate and path for a well known identity. - * - * @return the party and certificate. - * @throws IllegalArgumentException if the certificate and path are unknown. This should never happen for a well - * known identity. + * Converts an owning [PublicKey] to the X500Name extended [Party] object if the [Party] has been + * previously registered with the [IdentityService] either as a well known network map identity, + * or as a part of flows creating and exchanging the identity. + * @param key The owning [PublicKey] of the [Party]. + * @return Returns a [Party] with a matching owningKey if known, else returns null. */ - fun certificateFromParty(party: Party): PartyAndCertificate - - // There is no method for removing identities, as once we are made aware of a Party we want to keep track of them - // indefinitely. It may be that in the long term we need to drop or archive very old Party information for space, - // but for now this is not supported. - fun partyFromKey(key: PublicKey): Party? - fun partyFromX500Name(name: CordaX500Name): Party? + /** + * Resolves a party name to the well known identity [Party] instance for this name. + * @param name The [CordaX500Name] to search for. + * @return If known the canonical [Party] with that name, else null. + */ + fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? /** - * Returns the well known identity from an abstract party. This is intended to resolve the well known identity - * from a confidential identity, however it transparently handles returning the well known identity back if + * Returns the well known identity from an [AbstractParty]. This is intended to resolve the well known identity, + * as visible in the [NetworkMapCache] from a confidential identity. + * It transparently handles returning the well known identity back if * a well known identity is passed in. * * @param party identity to determine well known identity for. * @return well known identity, if found. */ - fun partyFromAnonymous(party: AbstractParty): Party? + fun wellKnownPartyFromAnonymous(party: AbstractParty): Party? /** - * Resolve the well known identity of a party. If the party passed in is already a well known identity - * (i.e. a [Party]) this returns it as-is. + * Returns the well known identity from a PartyAndReference. This is intended to resolve the well known identity, + * as visible in the [NetworkMapCache] from a confidential identity. + * It transparently handles returning the well known identity back if + * a well known identity is passed in. * * @return the well known identity, or null if unknown. */ - fun partyFromAnonymous(partyRef: PartyAndReference) = partyFromAnonymous(partyRef.party) + fun wellKnownPartyFromAnonymous(partyRef: PartyAndReference) = wellKnownPartyFromAnonymous(partyRef.party) /** * Resolve the well known identity of a party. Throws an exception if the party cannot be identified. @@ -90,7 +92,7 @@ interface IdentityService { * @return the well known identity. * @throws IllegalArgumentException */ - fun requirePartyFromAnonymous(party: AbstractParty): Party + fun requireWellKnownPartyFromAnonymous(party: AbstractParty): Party /** * Returns a list of candidate matches for a given string, with optional fuzzy(ish) matching. Fuzzy matching may diff --git a/docs/source/api-rpc.rst b/docs/source/api-rpc.rst index 8f37fa9beb..8c7d79d9a5 100644 --- a/docs/source/api-rpc.rst +++ b/docs/source/api-rpc.rst @@ -23,7 +23,7 @@ The key RPC operations exposed by the node are: * Returns the node's identity * ``CordaRPCOps.currentNodeTime`` * Returns the node's current time -* ``CordaRPCOps.partyFromKey/CordaRPCOps.partyFromX500Name`` +* ``CordaRPCOps.partyFromKey/CordaRPCOps.wellKnownPartyFromX500Name`` * Retrieves a party on the network based on a public key or X500 name * ``CordaRPCOps.uploadAttachment``/``CordaRPCOps.openAttachment``/``CordaRPCOps.attachmentExists`` * Uploads, opens and checks for the existence of attachments \ No newline at end of file diff --git a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java index 247b3160d2..094d1757f0 100644 --- a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java +++ b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java @@ -135,7 +135,7 @@ public class FlowCookbookJava { // We may also need to identify a specific counterparty. // Again, we do so using the network map. // DOCSTART 2 - Party namedCounterparty = getServiceHub().getIdentityService().partyFromX500Name(new CordaX500Name("NodeA", "London", "UK")); + Party namedCounterparty = getServiceHub().getIdentityService().wellKnownPartyFromX500Name(new CordaX500Name("NodeA", "London", "UK")); Party keyedCounterparty = getServiceHub().getIdentityService().partyFromKey(dummyPubKey); // DOCEND 2 diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt index f16983a6c8..a3063e930d 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt @@ -116,7 +116,7 @@ object FlowCookbook { // We may also need to identify a specific counterparty. We // do so using identity service. // DOCSTART 2 - val namedCounterparty: Party = serviceHub.identityService.partyFromX500Name(CordaX500Name(organisation = "NodeA", locality = "London", country = "UK")) ?: + val namedCounterparty: Party = serviceHub.identityService.wellKnownPartyFromX500Name(CordaX500Name(organisation = "NodeA", locality = "London", country = "UK")) ?: throw IllegalArgumentException("Couldn't find counterparty for NodeA in identity service") val keyedCounterparty: Party = serviceHub.identityService.partyFromKey(dummyPubKey) ?: throw IllegalArgumentException("Couldn't find counterparty with key: $dummyPubKey in identity service") diff --git a/docs/source/tutorial-attachments.rst b/docs/source/tutorial-attachments.rst index 90dd58750c..09a2736b38 100644 --- a/docs/source/tutorial-attachments.rst +++ b/docs/source/tutorial-attachments.rst @@ -90,7 +90,7 @@ transaction and send it to the recipient node: fun sender(rpc: CordaRPCOps) { // Get the identity key of the other side (the recipient). - val otherSide: Party = rpc.partyFromName("Bank B")!! + val otherSide: Party = rpc.wellKnownPartyFromName("Bank B")!! // Make sure we have the file in storage // TODO: We should have our own demo file, not share the trader demo file diff --git a/finance/src/main/kotlin/net/corda/finance/flows/CashExitFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/CashExitFlow.kt index 63bb087726..763f0d4cff 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/CashExitFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/CashExitFlow.kt @@ -65,7 +65,7 @@ class CashExitFlow(private val amount: Amount, // TODO: Is it safe to drop participants we don't know how to contact? Does not knowing how to contact them // count as a reason to fail? val participants: Set = inputStates - .mapNotNull { serviceHub.identityService.partyFromAnonymous(it.state.data.owner) } + .mapNotNull { serviceHub.identityService.wellKnownPartyFromAnonymous(it.state.data.owner) } .toSet() // Sign transaction progressTracker.currentStep = SIGNING_TX diff --git a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt index 8398bb37c5..b60635c4e3 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt @@ -134,8 +134,8 @@ object TwoPartyDealFlow { progressTracker.currentStep = VERIFYING return handshake.unwrap { // Verify the transaction identities represent the correct parties - val wellKnownOtherParty = serviceHub.identityService.partyFromAnonymous(it.primaryIdentity) - val wellKnownMe = serviceHub.identityService.partyFromAnonymous(it.secondaryIdentity) + val wellKnownOtherParty = serviceHub.identityService.wellKnownPartyFromAnonymous(it.primaryIdentity) + val wellKnownMe = serviceHub.identityService.wellKnownPartyFromAnonymous(it.secondaryIdentity) require(wellKnownOtherParty == otherSideSession.counterparty) require(wellKnownMe == ourIdentity) validateHandshake(it) diff --git a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyTradeFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyTradeFlow.kt index 57a862041c..b69fad717a 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyTradeFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyTradeFlow.kt @@ -98,7 +98,7 @@ object TwoPartyTradeFlow { val states: Iterable = stx.tx.inputs.map { serviceHub.loadState(it).data } + stx.tx.outputs.map { it.data } states.forEach { state -> state.participants.forEach { anon -> - require(serviceHub.identityService.partyFromAnonymous(anon) != null) { + require(serviceHub.identityService.wellKnownPartyFromAnonymous(anon) != null) { "Transaction state $state involves unknown participant $anon" } } @@ -197,7 +197,7 @@ object TwoPartyTradeFlow { // The asset must either be owned by the well known identity of the counterparty, or we must be able to // prove the owner is a confidential identity of the counterparty. - val assetForSaleIdentity = serviceHub.identityService.partyFromAnonymous(asset.owner) + val assetForSaleIdentity = serviceHub.identityService.wellKnownPartyFromAnonymous(asset.owner) require(assetForSaleIdentity == sellerSession.counterparty) // Register the identity we're about to send payment to. This shouldn't be the same as the asset owner diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt index 36cd3a6979..97d4d83503 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt @@ -37,7 +37,7 @@ class LargeTransactionsTest { .addAttachment(hash4) val stx = serviceHub.signInitialTransaction(tx, ourIdentity.owningKey) // Send to the other side and wait for it to trigger resolution from us. - val bob = serviceHub.identityService.partyFromX500Name(BOB.name)!! + val bob = serviceHub.identityService.wellKnownPartyFromX500Name(BOB.name)!! val bobSession = initiateFlow(bob) subFlow(SendTransactionFlow(bobSession, stx)) bobSession.receive() diff --git a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt index 7e831fb50f..ac94252dc3 100644 --- a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt +++ b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt @@ -182,9 +182,9 @@ class CordaRPCOpsImpl( } } - override fun partyFromAnonymous(party: AbstractParty): Party? { + override fun wellKnownPartyFromAnonymous(party: AbstractParty): Party? { return database.transaction { - services.identityService.partyFromAnonymous(party) + services.identityService.wellKnownPartyFromAnonymous(party) } } @@ -194,9 +194,9 @@ class CordaRPCOpsImpl( } } - override fun partyFromX500Name(x500Name: CordaX500Name): Party? { + override fun wellKnownPartyFromX500Name(x500Name: CordaX500Name): Party? { return database.transaction { - services.identityService.partyFromX500Name(x500Name) + services.identityService.wellKnownPartyFromX500Name(x500Name) } } diff --git a/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt index 39559168c8..9ee5707a57 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt @@ -75,14 +75,13 @@ class InMemoryIdentityService(identities: Iterable = emptyS } override fun certificateFromKey(owningKey: PublicKey): PartyAndCertificate? = keyToParties[owningKey] - override fun certificateFromParty(party: Party): PartyAndCertificate = principalToParties[party.name] ?: throw IllegalArgumentException("Unknown identity ${party.name}") // We give the caller a copy of the data set to avoid any locking problems override fun getAllIdentities(): Iterable = ArrayList(keyToParties.values) override fun partyFromKey(key: PublicKey): Party? = keyToParties[key]?.party - override fun partyFromX500Name(name: CordaX500Name): Party? = principalToParties[name]?.party - override fun partyFromAnonymous(party: AbstractParty): Party? { + override fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? = principalToParties[name]?.party + override fun wellKnownPartyFromAnonymous(party: AbstractParty): Party? { // Expand the anonymous party to a full party (i.e. has a name) if possible val candidate = party as? Party ?: keyToParties[party.owningKey]?.party // TODO: This should be done via the network map cache, which is the authoritative source of well known identities @@ -95,9 +94,9 @@ class InMemoryIdentityService(identities: Iterable = emptyS null } } - override fun partyFromAnonymous(partyRef: PartyAndReference) = partyFromAnonymous(partyRef.party) - override fun requirePartyFromAnonymous(party: AbstractParty): Party { - return partyFromAnonymous(party) ?: throw IllegalStateException("Could not deanonymise party ${party.owningKey.toStringShort()}") + override fun wellKnownPartyFromAnonymous(partyRef: PartyAndReference) = wellKnownPartyFromAnonymous(partyRef.party) + override fun requireWellKnownPartyFromAnonymous(party: AbstractParty): Party { + return wellKnownPartyFromAnonymous(party) ?: throw IllegalStateException("Could not deanonymise party ${party.owningKey.toStringShort()}") } override fun partiesFromName(query: String, exactMatch: Boolean): Set { diff --git a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt index c28a96da49..9b739f455c 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt @@ -9,6 +9,7 @@ import net.corda.core.internal.toX509CertHolder import net.corda.core.node.services.IdentityService import net.corda.core.node.services.UnknownAnonymousPartyException import net.corda.core.serialization.SingletonSerializeAsToken +import net.corda.core.utilities.debug import net.corda.core.utilities.loggerFor import net.corda.node.utilities.AppendOnlyPersistentMap import net.corda.node.utilities.NODE_DATABASE_PREFIX @@ -124,7 +125,7 @@ class PersistentIdentityService(identities: Iterable = empt throw e } - log.info("Registering identity $identity") + log.debug { "Registering identity $identity" } val key = mapToKey(identity) keyToParties.addWithDuplicatesAllowed(key, identity) // Always keep the first party we registered, as that's the well known identity @@ -141,14 +142,12 @@ class PersistentIdentityService(identities: Iterable = empt } else null } - override fun certificateFromParty(party: Party): PartyAndCertificate = certificateFromCordaX500Name(party.name) ?: throw IllegalArgumentException("Unknown identity ${party.name}") - // We give the caller a copy of the data set to avoid any locking problems override fun getAllIdentities(): Iterable = keyToParties.allPersisted().map { it.second }.asIterable() override fun partyFromKey(key: PublicKey): Party? = certificateFromKey(key)?.party - override fun partyFromX500Name(name: CordaX500Name): Party? = certificateFromCordaX500Name(name)?.party - override fun partyFromAnonymous(party: AbstractParty): Party? { + override fun wellKnownPartyFromX500Name(name: CordaX500Name): Party? = certificateFromCordaX500Name(name)?.party + override fun wellKnownPartyFromAnonymous(party: AbstractParty): Party? { // Expand the anonymous party to a full party (i.e. has a name) if possible val candidate = party as? Party ?: partyFromKey(party.owningKey) // TODO: This should be done via the network map cache, which is the authoritative source of well known identities @@ -156,16 +155,16 @@ class PersistentIdentityService(identities: Iterable = empt return if (candidate != null) { // If we have a well known identity by that name, use it in preference to the candidate. Otherwise default // back to the candidate. - val res = partyFromX500Name(candidate.name) ?: candidate + val res = wellKnownPartyFromX500Name(candidate.name) ?: candidate res } else { null } } - override fun partyFromAnonymous(partyRef: PartyAndReference) = partyFromAnonymous(partyRef.party) - override fun requirePartyFromAnonymous(party: AbstractParty): Party { - return partyFromAnonymous(party) ?: throw IllegalStateException("Could not deanonymise party ${party.owningKey.toStringShort()}") + override fun wellKnownPartyFromAnonymous(partyRef: PartyAndReference) = wellKnownPartyFromAnonymous(partyRef.party) + override fun requireWellKnownPartyFromAnonymous(party: AbstractParty): Party { + return wellKnownPartyFromAnonymous(party) ?: throw IllegalStateException("Could not deanonymise party ${party.owningKey.toStringShort()}") } override fun partiesFromName(query: String, exactMatch: Boolean): Set { diff --git a/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt b/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt index 788e0a94fb..45e2b6f9b0 100644 --- a/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt +++ b/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt @@ -110,7 +110,7 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal) override fun getNodesByLegalIdentityKey(identityKey: PublicKey): List = serviceHub.database.transaction { queryByIdentityKey(identityKey) } override fun getNodeByLegalIdentity(party: AbstractParty): NodeInfo? { - val wellKnownParty = serviceHub.identityService.partyFromAnonymous(party) + val wellKnownParty = serviceHub.identityService.wellKnownPartyFromAnonymous(party) return wellKnownParty?.let { getNodesByLegalIdentityKey(it.owningKey).singleOrNull() } diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/AbstractPartyToX500NameAsStringConverter.kt b/node/src/main/kotlin/net/corda/node/services/persistence/AbstractPartyToX500NameAsStringConverter.kt index f93048868e..ac1d696af7 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/AbstractPartyToX500NameAsStringConverter.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/AbstractPartyToX500NameAsStringConverter.kt @@ -21,7 +21,7 @@ class AbstractPartyToX500NameAsStringConverter(identitySvc: () -> IdentityServic override fun convertToDatabaseColumn(party: AbstractParty?): String? { if (party != null) { - val partyName = identityService.partyFromAnonymous(party)?.toString() + val partyName = identityService.wellKnownPartyFromAnonymous(party)?.toString() if (partyName != null) return partyName log.warn("Identity service unable to resolve AbstractParty: $party") } @@ -30,7 +30,7 @@ class AbstractPartyToX500NameAsStringConverter(identitySvc: () -> IdentityServic override fun convertToEntityAttribute(dbData: String?): AbstractParty? { if (dbData != null) { - val party = identityService.partyFromX500Name(CordaX500Name.parse(dbData)) + val party = identityService.wellKnownPartyFromX500Name(CordaX500Name.parse(dbData)) if (party != null) return party log.warn ("Identity service unable to resolve X500name: $dbData") } diff --git a/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt index f54747a578..e7f87f6104 100644 --- a/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/network/InMemoryIdentityServiceTests.kt @@ -54,7 +54,7 @@ class InMemoryIdentityServiceTests { @Test fun `get identity by name with no registered identities`() { val service = InMemoryIdentityService(trustRoot = DEV_TRUST_ROOT) - assertNull(service.partyFromX500Name(ALICE.name)) + assertNull(service.wellKnownPartyFromX500Name(ALICE.name)) } @Test @@ -74,9 +74,9 @@ class InMemoryIdentityServiceTests { val service = InMemoryIdentityService(trustRoot = DEV_TRUST_ROOT) val identities = listOf("Org A", "Org B", "Org C") .map { getTestPartyAndCertificate(CordaX500Name(organisation = it, locality = "London", country = "GB"), generateKeyPair().public) } - assertNull(service.partyFromX500Name(identities.first().name)) + assertNull(service.wellKnownPartyFromX500Name(identities.first().name)) identities.forEach { service.verifyAndRegisterIdentity(it) } - identities.forEach { assertEquals(it.party, service.partyFromX500Name(it.name)) } + identities.forEach { assertEquals(it.party, service.wellKnownPartyFromX500Name(it.name)) } } /** @@ -171,7 +171,7 @@ class InMemoryIdentityServiceTests { @Test fun `deanonymising a well known identity`() { val expected = ALICE - val actual = InMemoryIdentityService(trustRoot = DEV_TRUST_ROOT).partyFromAnonymous(expected) + val actual = InMemoryIdentityService(trustRoot = DEV_TRUST_ROOT).wellKnownPartyFromAnonymous(expected) assertEquals(expected, actual) } } diff --git a/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt index 3d596f0b05..9c5163db2d 100644 --- a/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/network/PersistentIdentityServiceTests.kt @@ -88,7 +88,7 @@ class PersistentIdentityServiceTests { @Test fun `get identity by name with no registered identities`() { database.transaction { - assertNull(identityService.partyFromX500Name(ALICE.name)) + assertNull(identityService.wellKnownPartyFromX500Name(ALICE.name)) } } @@ -112,7 +112,7 @@ class PersistentIdentityServiceTests { val identities = listOf("Organisation A", "Organisation B", "Organisation C") .map { getTestPartyAndCertificate(CordaX500Name(organisation = it, locality = "London", country = "GB"), generateKeyPair().public) } database.transaction { - assertNull(identityService.partyFromX500Name(identities.first().name)) + assertNull(identityService.wellKnownPartyFromX500Name(identities.first().name)) } identities.forEach { database.transaction { @@ -121,7 +121,7 @@ class PersistentIdentityServiceTests { } identities.forEach { database.transaction { - assertEquals(it.party, identityService.partyFromX500Name(it.name)) + assertEquals(it.party, identityService.wellKnownPartyFromX500Name(it.name)) } } } @@ -245,7 +245,7 @@ class PersistentIdentityServiceTests { } val aliceParent = database.transaction { - newPersistentIdentityService.partyFromAnonymous(anonymousAlice.party.anonymise()) + newPersistentIdentityService.wellKnownPartyFromAnonymous(anonymousAlice.party.anonymise()) } assertEquals(alice.party, aliceParent!!) @@ -272,7 +272,7 @@ class PersistentIdentityServiceTests { fun `deanonymising a well known identity`() { val expected = ALICE val actual = database.transaction { - identityService.partyFromAnonymous(expected) + identityService.wellKnownPartyFromAnonymous(expected) } assertEquals(expected, actual) } diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt index 630255cd71..f33f151428 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt @@ -87,8 +87,8 @@ fun sender(rpc: CordaRPCOps, numOfClearBytes: Int = 1024) { // default size 1K. private fun sender(rpc: CordaRPCOps, inputStream: InputStream, hash: SecureHash.SHA256, executor: ScheduledExecutorService) { // Get the identity key of the other side (the recipient). - val notaryFuture: CordaFuture = poll(executor, DUMMY_NOTARY.name.toString()) { rpc.partyFromX500Name(DUMMY_NOTARY.name) } - val otherSideFuture: CordaFuture = poll(executor, DUMMY_BANK_B.name.toString()) { rpc.partyFromX500Name(DUMMY_BANK_B.name) } + val notaryFuture: CordaFuture = poll(executor, DUMMY_NOTARY.name.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_NOTARY.name) } + val otherSideFuture: CordaFuture = poll(executor, DUMMY_BANK_B.name.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_BANK_B.name) } // Make sure we have the file in storage if (!rpc.attachmentExists(hash)) { diff --git a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaClientApi.kt b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaClientApi.kt index 39b738f04b..455c090973 100644 --- a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaClientApi.kt +++ b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaClientApi.kt @@ -39,7 +39,7 @@ class BankOfCordaClientApi(val hostAndPort: NetworkHostAndPort) { rpc.waitUntilNetworkReady() // Resolve parties via RPC - val issueToParty = rpc.partyFromX500Name(params.issueToPartyName) + val issueToParty = rpc.wellKnownPartyFromX500Name(params.issueToPartyName) ?: throw IllegalStateException("Unable to locate ${params.issueToPartyName} in Network Map Service") val notaryLegalIdentity = rpc.notaryIdentities().firstOrNull { it.name == params.notaryName } ?: throw IllegalStateException("Couldn't locate notary ${params.notaryName} in NetworkMapCache") diff --git a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt index b651455765..8180350c74 100644 --- a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt +++ b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/api/BankOfCordaWebApi.kt @@ -41,9 +41,9 @@ class BankOfCordaWebApi(val rpc: CordaRPCOps) { @Consumes(MediaType.APPLICATION_JSON) fun issueAssetRequest(params: IssueRequestParams): Response { // Resolve parties via RPC - val issueToParty = rpc.partyFromX500Name(params.issueToPartyName) + val issueToParty = rpc.wellKnownPartyFromX500Name(params.issueToPartyName) ?: return Response.status(Response.Status.FORBIDDEN).entity("Unable to locate ${params.issueToPartyName} in identity service").build() - rpc.partyFromX500Name(params.issuerBankName) ?: return Response.status(Response.Status.FORBIDDEN).entity("Unable to locate ${params.issuerBankName} in identity service").build() + rpc.wellKnownPartyFromX500Name(params.issuerBankName) ?: return Response.status(Response.Status.FORBIDDEN).entity("Unable to locate ${params.issuerBankName} in identity service").build() val notaryParty = rpc.notaryIdentities().firstOrNull { it.name == params.notaryName } ?: return Response.status(Response.Status.FORBIDDEN).entity("Unable to locate notary ${params.notaryName} in network map").build() diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt index e44cc055cc..e7d1074362 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt @@ -136,7 +136,7 @@ object FixingFlow { val myKey = ourIdentity.owningKey if (parties[0].owningKey == myKey) { val fixing = FixingSession(ref, fixableDeal.oracle) - val counterparty = serviceHub.identityService.partyFromAnonymous(parties[1]) ?: throw IllegalStateException("Cannot resolve floater party") + val counterparty = serviceHub.identityService.wellKnownPartyFromAnonymous(parties[1]) ?: throw IllegalStateException("Cannot resolve floater party") // Start the Floater which will then kick-off the Fixer val session = initiateFlow(counterparty) subFlow(Floater(session, fixing)) diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt index 852777bdfe..9bf30f2051 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt @@ -115,7 +115,7 @@ object SimmFlow { val state = stateRef.state.data val portfolio = serviceHub.vaultQueryService.queryBy(VaultQueryCriteria(stateRefs = state.portfolio)).states.toPortfolio() - val valuer = serviceHub.identityService.partyFromAnonymous(state.valuer) + val valuer = serviceHub.identityService.wellKnownPartyFromAnonymous(state.valuer) require(valuer != null) { "Valuer party must be known to this node" } val valuation = agreeValuation(portfolio, valuationDate, valuer!!) val update = PortfolioState.Update(valuation = valuation) @@ -317,7 +317,7 @@ object SimmFlow { @Suspendable private fun updateValuation(stateRef: StateAndRef) { val portfolio = serviceHub.vaultQueryService.queryBy(VaultQueryCriteria(stateRefs = stateRef.state.data.portfolio)).states.toPortfolio() - val valuer = serviceHub.identityService.partyFromAnonymous(stateRef.state.data.valuer) ?: throw IllegalStateException("Unknown valuer party ${stateRef.state.data.valuer}") + val valuer = serviceHub.identityService.wellKnownPartyFromAnonymous(stateRef.state.data.valuer) ?: throw IllegalStateException("Unknown valuer party ${stateRef.state.data.valuer}") val valuation = agreeValuation(portfolio, offer.valuationDate, valuer) subFlow(object : StateRevisionFlow.Receiver(replyToSession) { override fun verifyProposal(stx: SignedTransaction, proposal: Proposal) { diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt index 72fa97480a..8f607163ef 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt @@ -23,7 +23,7 @@ object SimmRevaluation { val stateAndRef = serviceHub.vaultQueryService.queryBy(VaultQueryCriteria(stateRefs = listOf(curStateRef))).states.single() val curState = stateAndRef.state.data if (ourIdentity == curState.participants[0]) { - val otherParty = serviceHub.identityService.partyFromAnonymous(curState.participants[1]) + val otherParty = serviceHub.identityService.wellKnownPartyFromAnonymous(curState.participants[1]) require(otherParty != null) { "Other party must be known by this node" } subFlow(SimmFlow.Requester(otherParty!!, valuationDate, stateAndRef)) } diff --git a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt index 5fdccd69af..e373de677d 100644 --- a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt +++ b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt @@ -43,8 +43,8 @@ class TraderDemoClientApi(val rpc: CordaRPCOps) { fun runIssuer(amount: Amount, buyerName: CordaX500Name, sellerName: CordaX500Name) { val ref = OpaqueBytes.of(1) - val buyer = rpc.partyFromX500Name(buyerName) ?: throw IllegalStateException("Don't know $buyerName") - val seller = rpc.partyFromX500Name(sellerName) ?: throw IllegalStateException("Don't know $sellerName") + val buyer = rpc.wellKnownPartyFromX500Name(buyerName) ?: throw IllegalStateException("Don't know $buyerName") + val seller = rpc.wellKnownPartyFromX500Name(sellerName) ?: throw IllegalStateException("Don't know $sellerName") val notaryIdentity = rpc.notaryIdentities().first() val amounts = calculateRandomlySizedAmounts(amount, 3, 10, Random()) @@ -73,7 +73,7 @@ class TraderDemoClientApi(val rpc: CordaRPCOps) { } fun runSeller(amount: Amount = 1000.0.DOLLARS, buyerName: CordaX500Name) { - val otherParty = rpc.partyFromX500Name(buyerName) ?: throw IllegalStateException("Don't know $buyerName") + val otherParty = rpc.wellKnownPartyFromX500Name(buyerName) ?: throw IllegalStateException("Don't know $buyerName") // The seller will sell some commercial paper to the buyer, who will pay with (self issued) cash. // // The CP sale transaction comes with a prospectus PDF, which will tag along for the ride in an