Skip to content

Commit

Permalink
Preparation for major version 4.0.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMatthewLayton committed Feb 17, 2022
1 parent c4538b2 commit 76885d7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.messaging.CordaRPCOps
import net.corda.core.utilities.parsePublicKeyBase58

/**
* Determines whether the current Corda node owns the specified party identity.
*
* @param party The identity to determine is owned by the current Corda node.
* @return Returns true if the current Corda node owns the specified party identity; otherwise, false.
*/
fun CordaRPCOps.ownsLegalIdentity(party: AbstractParty): Boolean {
val partyToResolve = if (party is AccountParty) party.owner else party
val wellKnownParty = wellKnownPartyFromAnonymous(partyToResolve)

return wellKnownParty in nodeInfo().legalIdentities
}

/**
* Resolves the specified value to an [AbstractParty].
*
* @param value The value to resolve to an [AbstractParty].
* @param type The type of account to resolve, if the value represents an [AccountParty].
* @return Returns an [AbstractParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AbstractParty].
*/
fun CordaRPCOps.resolveParty(value: String, type: Class<out Account> = Account::class.java): AbstractParty {
return if (AccountParty.DELIMITER in value) resolveAccountParty(value, type) else resolveAbstractParty(value)
}

/**
* Resolves the specified value to an [AbstractParty].
*
* @param value The value to resolve to an [AbstractParty].
* @return Returns an [AbstractParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AbstractParty].
*/
fun CordaRPCOps.resolveAbstractParty(value: String): AbstractParty {
return try {
val parsedCordaX500Name = CordaX500Name.parse(value)
Expand All @@ -46,6 +67,14 @@ fun CordaRPCOps.resolveAbstractParty(value: String): AbstractParty {
} ?: throw IllegalArgumentException("Failed to resolve '$value' to party.")
}

/**
* Resolves the specified value to an [AccountParty].
*
* @param value The value to resolve to an [AccountParty].
* @param type The type of account to resolve.
* @return Returns an [AccountParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AccountParty].
*/
fun CordaRPCOps.resolveAccountParty(value: String, type: Class<out Account> = Account::class.java): AccountParty {
val identityComponent = value.substringAfter(AccountParty.DELIMITER)
val linearIdComponent = value.substringBefore(AccountParty.DELIMITER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,54 @@ import io.onixlabs.corda.core.workflow.checkSufficientSessionsForContractStates
import io.onixlabs.corda.core.workflow.checkSufficientSessionsForTransactionBuilder
import io.onixlabs.corda.identityframework.contract.accounts.AccountParty
import net.corda.core.contracts.ContractState
import net.corda.core.flows.FlowException
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.FlowSession
import net.corda.core.identity.AbstractParty
import net.corda.core.transactions.TransactionBuilder

/**
* Checks that sufficient flow sessions have been provided for the account identities of the specified states.
*
* @param sessions The flow sessions that have been provided to the flow.
* @param states The states that will be used as input or output states in a transaction.
* @throws FlowException if a required counter-party session is missing for a state participant.
*/
@Suspendable
fun FlowLogic<*>.checkSufficientSessionsForAccounts(
sessions: Iterable<FlowSession>,
states: Iterable<ContractState>
) = checkSufficientSessionsForContractStates(sessions, states) { it.getAccountOwningPartyOrThis() }

/**
* Checks that sufficient flow sessions have been provided for the account identities of the specified states.
*
* @param sessions The flow sessions that have been provided to the flow.
* @param states The states that will be used as input or output states in a transaction.
* @throws FlowException if a required counter-party session is missing for a state participant.
*/
@Suspendable
fun FlowLogic<*>.checkSufficientSessionsForAccounts(
sessions: Iterable<FlowSession>,
vararg states: ContractState
) = checkSufficientSessionsForContractStates(sessions, *states) { it.getAccountOwningPartyOrThis() }


/**
* Checks that sufficient flow sessions have been provided for the specified transaction.
*
* @param sessions The flow sessions that have been provided to the flow.
* @param transaction The transaction for which to check that sufficient flow sessions exist.
* @throws FlowException if a required counter-party session is missing for a state participant.
*/
@Suspendable
fun FlowLogic<*>.checkSufficientSessionsForTransactionBuilder(
sessions: Iterable<FlowSession>,
transaction: TransactionBuilder
) = checkSufficientSessionsForTransactionBuilder(sessions, transaction) { it.getAccountOwningPartyOrThis() }

/**
* Gets the underlying account owner identity, or returns the current identity if it is not an [AccountParty].
*/
private fun AbstractParty.getAccountOwningPartyOrThis(): AbstractParty {
return if (this is AccountParty) owner else this
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.node.ServiceHub
import net.corda.core.utilities.parsePublicKeyBase58

/**
* Determines whether the current Corda node owns the specified party identity.
*
* @param party The identity to determine is owned by the current Corda node.
* @return Returns true if the current Corda node owns the specified party identity; otherwise, false.
*/
fun ServiceHub.ownsLegalIdentity(party: AbstractParty): Boolean {
val partyToResolve = if (party is AccountParty) party.owner else party
val wellKnownParty = identityService.wellKnownPartyFromAnonymous(partyToResolve)

return wellKnownParty in myInfo.legalIdentities
}

/**
* Resolves the specified value to an [AbstractParty].
*
* @param value The value to resolve to an [AbstractParty].
* @param type The type of account to resolve, if the value represents an [AccountParty].
* @return Returns an [AbstractParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AbstractParty].
*/
fun ServiceHub.resolveParty(value: String, type: Class<out Account> = Account::class.java): AbstractParty {
return if (AccountParty.DELIMITER in value) resolveAccountParty(value, type) else resolveAbstractParty(value)
}

/**
* Resolves the specified value to an [AbstractParty].
*
* @param value The value to resolve to an [AbstractParty].
* @return Returns an [AbstractParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AbstractParty].
*/
fun ServiceHub.resolveAbstractParty(value: String): AbstractParty {
return try {
val parsedCordaX500Name = CordaX500Name.parse(value)
Expand All @@ -46,6 +67,14 @@ fun ServiceHub.resolveAbstractParty(value: String): AbstractParty {
} ?: throw IllegalArgumentException("Failed to resolve '$value' to party.")
}

/**
* Resolves the specified value to an [AccountParty].
*
* @param value The value to resolve to an [AccountParty].
* @param type The type of account to resolve.
* @return Returns an [AccountParty] resolved from the specified value.
* @throws IllegalArgumentException if the specified value cannot be resolved to an [AccountParty].
*/
fun ServiceHub.resolveAccountParty(value: String, type: Class<out Account> = Account::class.java): AccountParty {
val identityComponent = value.substringAfter(AccountParty.DELIMITER)
val linearIdComponent = value.substringBefore(AccountParty.DELIMITER)
Expand Down

0 comments on commit 76885d7

Please sign in to comment.