Skip to content

Commit

Permalink
CORE-14632: Update Apples flows to select explicit notary. (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisr3 authored Aug 30, 2023
1 parent cfeaf0a commit 70a25b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import net.corda.v5.ledger.common.NotaryLookup
import net.corda.v5.ledger.utxo.UtxoLedgerService
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*
import java.util.UUID

@InitiatingFlow(protocol = "create-and-issue-apple-stamp")
class CreateAndIssueAppleStampFlow : ClientStartableFlow {

internal data class CreateAndIssueAppleStampRequest(
val stampDescription: String,
val holder: MemberX500Name
val holder: MemberX500Name,
val notary: MemberX500Name
)

@CordaInject
Expand All @@ -48,7 +49,8 @@ class CreateAndIssueAppleStampFlow : ClientStartableFlow {
val stampDescription = request.stampDescription
val holderName = request.holder

val notaryInfo = notaryLookup.notaryServices.single()
val notaryInfo = notaryLookup.lookup(request.notary)
?: throw IllegalArgumentException("Notary ${request.notary} not found")

val issuer = memberLookup.myInfo().ledgerKeys.first()
val holder = memberLookup.lookup(holderName)?.ledgerKeys?.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import net.corda.v5.application.flows.ClientStartableFlow
import net.corda.v5.application.marshalling.JsonMarshallingService
import net.corda.v5.application.membership.MemberLookup
import net.corda.v5.base.annotations.Suspendable
import net.corda.v5.base.types.MemberX500Name
import net.corda.v5.ledger.common.NotaryLookup
import net.corda.v5.ledger.utxo.UtxoLedgerService
import java.time.Instant
import java.time.temporal.ChronoUnit

class PackageApplesFlow : ClientStartableFlow {

internal data class PackApplesRequest(val appleDescription: String, val weight: Int)
internal data class PackApplesRequest(val appleDescription: String, val weight: Int, val notary: MemberX500Name)

@CordaInject
lateinit var jsonMarshallingService: JsonMarshallingService
Expand All @@ -34,7 +35,8 @@ class PackageApplesFlow : ClientStartableFlow {
val request = requestBody.getRequestBodyAs(jsonMarshallingService, PackApplesRequest::class.java)
val appleDescription = request.appleDescription
val weight = request.weight
val notary = notaryLookup.notaryServices.single()
val notary = notaryLookup.lookup(request.notary)
?: throw IllegalArgumentException("Notary ${request.notary} not found")
val myKey = memberLookup.myInfo().ledgerKeys.first()

// Building the output BasketOfApples state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.r3.developers.apples.contracts.AppleCommands
import com.r3.developers.apples.states.AppleStamp
import com.r3.developers.apples.states.BasketOfApples
import net.corda.v5.base.types.MemberX500Name
import java.util.*

import net.corda.v5.application.flows.CordaInject
import net.corda.v5.application.flows.InitiatingFlow
import net.corda.v5.application.flows.ClientRequestBody
Expand All @@ -18,11 +16,12 @@ import net.corda.v5.ledger.common.NotaryLookup
import net.corda.v5.ledger.utxo.UtxoLedgerService
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID

@InitiatingFlow(protocol = "redeem-apples")
class RedeemApplesFlow : ClientStartableFlow {

internal data class RedeemApplesRequest(val buyer: MemberX500Name, val stampId: UUID)
internal data class RedeemApplesRequest(val buyer: MemberX500Name, val notary: MemberX500Name, val stampId: UUID)

@CordaInject
lateinit var flowMessaging: FlowMessaging
Expand All @@ -45,8 +44,9 @@ class RedeemApplesFlow : ClientStartableFlow {
val buyerName = request.buyer
val stampId = request.stampId

// Retrieve the notaries public key (this will change)
val notaryInfo = notaryLookup.notaryServices.single()
// Retrieve the notary's public key (this will change)
val notaryInfo = notaryLookup.lookup(request.notary)
?: throw IllegalArgumentException("Notary ${request.notary} not found")

val myKey = memberLookup.myInfo().ledgerKeys.first()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ApplesFlowDriverTests {
fun `test that RedeemApplesFlow is successful`() {
val stampId = createAndIssueAppleStamp("Stamp # 0002", bob, alice)!!
packageApples("Basket of apples # 0002", 350, alice)
val redeemApplesFlowArgs = RedeemApplesFlow.RedeemApplesRequest(bob, stampId)
val redeemApplesFlowArgs = RedeemApplesFlow.RedeemApplesRequest(bob, notary, stampId)
driver.run { dsl ->
dsl.runFlow<RedeemApplesFlow>(vNodes[alice] ?: fail("Missing vNode for Alice")) {
jsonMapper.writeValueAsString(redeemApplesFlowArgs)
Expand All @@ -78,7 +78,7 @@ class ApplesFlowDriverTests {
}

private fun packageApples(description: String, weight: Int, packer: MemberX500Name) {
val packageApplesFlowArgs = PackageApplesFlow.PackApplesRequest(description, weight)
val packageApplesFlowArgs = PackageApplesFlow.PackApplesRequest(description, weight, notary)
driver.run { dsl: DriverDSL ->
dsl.runFlow<PackageApplesFlow>(vNodes[packer] ?: fail(String.format("Missing vNode {}", jsonMapper.writeValueAsString(packer)))) {
jsonMapper.writeValueAsString(packageApplesFlowArgs)
Expand All @@ -87,7 +87,7 @@ class ApplesFlowDriverTests {
}

private fun createAndIssueAppleStamp(description: String, member: MemberX500Name, issuer: MemberX500Name): UUID? {
val createAndIssueFlowArgs = CreateAndIssueAppleStampFlow.CreateAndIssueAppleStampRequest(description, member)
val createAndIssueFlowArgs = CreateAndIssueAppleStampFlow.CreateAndIssueAppleStampRequest(description, member, notary)
val result = driver.let<String> { dsl ->
dsl.runFlow<CreateAndIssueAppleStampFlow>(
vNodes[issuer] ?: fail(String.format("Missing vNode {}", jsonMapper.writeValueAsString(issuer)))
Expand Down

0 comments on commit 70a25b1

Please sign in to comment.