Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make redeem flow handlers open #199

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class CreateEvolvableTokensFlowHandler(val otherSession: FlowSession) : FlowLogi
}

// Resolve the creation transaction.
return subFlow(ObserverAwareFinalityFlowHandler(otherSession))
subFlow(ObserverAwareFinalityFlowHandler(otherSession))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ class UpdateEvolvableTokenFlowHandler(val otherSession: FlowSession) : FlowLogic
}

// Resolve the update transaction.
return subFlow(ObserverAwareFinalityFlowHandler(otherSession))
subFlow(ObserverAwareFinalityFlowHandler(otherSession))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import net.corda.core.utilities.unwrap
* [RedeemNonFungibleTokensFlow], [RedeemTokensFlow].
*/
// Called on Issuer side.
class RedeemTokensFlowHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
class RedeemTokensFlowHandler(val otherSession: FlowSession) : FlowLogic<SignedTransaction?>() {
@Suspendable
override fun call() {
override fun call(): SignedTransaction? {
val role = otherSession.receive<TransactionRole>().unwrap { it }
if (role == TransactionRole.PARTICIPANT) {
// Synchronise all confidential identities, issuer isn't involved in move transactions, so states holders may
Expand All @@ -42,9 +42,9 @@ class RedeemTokensFlowHandler(val otherSession: FlowSession) : FlowLogic<Unit>()
})
}
}
if (!serviceHub.myInfo.isLegalIdentity(otherSession.counterparty)) {
return if (!serviceHub.myInfo.isLegalIdentity(otherSession.counterparty)) {
// Call observer aware finality flow handler.
subFlow(ObserverAwareFinalityFlowHandler(otherSession))
}
} else null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ constructor(
}

@InitiatedBy(RedeemFungibleTokens::class)
class RedeemFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
open class RedeemFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() = subFlow(RedeemTokensFlowHandler(otherSession))
override fun call() {
subFlow(RedeemTokensFlowHandler(otherSession))
}
}

@StartableByService
Expand All @@ -57,9 +59,11 @@ constructor(
}

@InitiatedBy(RedeemNonFungibleTokens::class)
class RedeemNonFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
open class RedeemNonFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() = subFlow(RedeemTokensFlowHandler(otherSession))
override fun call() {
subFlow(RedeemTokensFlowHandler(otherSession))
}
}

/* Confidential flows. */
Expand Down Expand Up @@ -91,7 +95,9 @@ constructor(
}

@InitiatedBy(ConfidentialRedeemFungibleTokens::class)
class ConfidentialRedeemFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
open class ConfidentialRedeemFungibleTokensHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() = subFlow(ConfidentialRedeemFungibleTokensFlowHandler(otherSession))
}
override fun call() {
subFlow(ConfidentialRedeemFungibleTokensFlowHandler(otherSession))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import net.corda.core.flows.FlowLogic
import net.corda.core.flows.FlowSession
import net.corda.core.flows.ReceiveFinalityFlow
import net.corda.core.node.StatesToRecord
import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.unwrap

class ObserverAwareFinalityFlowHandler(val otherSession: FlowSession) : FlowLogic<Unit>() {
class ObserverAwareFinalityFlowHandler(val otherSession: FlowSession) : FlowLogic<SignedTransaction?>() {
@Suspendable
override fun call() {
override fun call(): SignedTransaction? {
val role = otherSession.receive<TransactionRole>().unwrap { it }
val statesToRecord = when (role) {
TransactionRole.PARTICIPANT -> StatesToRecord.ONLY_RELEVANT
TransactionRole.OBSERVER -> StatesToRecord.ALL_VISIBLE
}
// If states are issued to self, then ReceiveFinalityFlow does not need to be invoked.
if (!serviceHub.myInfo.isLegalIdentity(otherSession.counterparty)) {
return if (!serviceHub.myInfo.isLegalIdentity(otherSession.counterparty)) {
subFlow(ReceiveFinalityFlow(otherSideSession = otherSession, statesToRecord = statesToRecord))
}
} else null
}
}