From ad2890193db0a38eab27dfababbcbb76fe867b53 Mon Sep 17 00:00:00 2001 From: Thomas Schroeter Date: Tue, 26 Jun 2018 16:45:18 +0100 Subject: [PATCH] Specify Notary in `CashIssueAndPaymentFlow` and `PaymentRequest` (#3443) * Specify notary in CashIssueAndPaymentFlow * Specify notary in PaymentRequest * Address comments * Default to the first notary in the `CashPaymentFlow` --- .../corda/finance/flows/CashIssueAndPaymentFlow.kt | 4 ++-- .../net/corda/finance/flows/CashPaymentFlow.kt | 13 +++++++++---- .../explorer/views/cordapps/cash/NewTransaction.kt | 6 ++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/finance/src/main/kotlin/net/corda/finance/flows/CashIssueAndPaymentFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/CashIssueAndPaymentFlow.kt index 95a58e8cfb..08618cabce 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/CashIssueAndPaymentFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/CashIssueAndPaymentFlow.kt @@ -38,7 +38,7 @@ class CashIssueAndPaymentFlow(val amount: Amount, @Suspendable override fun call(): Result { subFlow(CashIssueFlow(amount, issueRef, notary)) - return subFlow(CashPaymentFlow(amount, recipient, anonymous)) + return subFlow(CashPaymentFlow(amount, recipient, anonymous, notary)) } @CordaSerializable @@ -47,4 +47,4 @@ class CashIssueAndPaymentFlow(val amount: Amount, val recipient: Party, val notary: Party, val anonymous: Boolean) : AbstractRequest(amount) -} \ No newline at end of file +} diff --git a/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt index b45d61067b..b5147fb0f5 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt @@ -24,6 +24,7 @@ import java.util.* * @param recipient the party to pay the currency to. * @param issuerConstraint if specified, the payment will be made using only cash issued by the given parties. * @param anonymous whether to anonymous the recipient party. Should be true for normal usage, but may be false + * @param notary if not specified, the first notary of the network map is selected * for testing purposes. */ @StartableByRPC @@ -32,14 +33,17 @@ open class CashPaymentFlow( val recipient: Party, val anonymous: Boolean, progressTracker: ProgressTracker, - val issuerConstraint: Set = emptySet()) : AbstractCashFlow(progressTracker) { + val issuerConstraint: Set = emptySet(), + val notary: Party? = null) : AbstractCashFlow(progressTracker) { /** A straightforward constructor that constructs spends using cash states of any issuer. */ constructor(amount: Amount, recipient: Party) : this(amount, recipient, true, tracker()) /** A straightforward constructor that constructs spends using cash states of any issuer. */ constructor(amount: Amount, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker()) - constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint) + constructor(amount: Amount, recipient: Party, anonymous: Boolean, notary: Party) : this(amount, recipient, anonymous, tracker(), notary = notary) + + constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint, request.notary) @Suspendable override fun call(): AbstractCashFlow.Result { @@ -51,7 +55,7 @@ open class CashPaymentFlow( } val anonymousRecipient = txIdentities[recipient] ?: recipient progressTracker.currentStep = GENERATING_TX - val builder = TransactionBuilder(notary = null) + val builder = TransactionBuilder(notary = notary ?: serviceHub.networkMapCache.notaryIdentities.first()) logger.info("Generating spend for: ${builder.lockId}") // TODO: Have some way of restricting this to states the caller controls val (spendTX, keysForSigning) = try { @@ -80,5 +84,6 @@ open class CashPaymentFlow( class PaymentRequest(amount: Amount, val recipient: Party, val anonymous: Boolean, - val issuerConstraint: Set = emptySet()) : AbstractRequest(amount) + val issuerConstraint: Set = emptySet(), + val notary: Party? = null) : AbstractRequest(amount) } diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/NewTransaction.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/NewTransaction.kt index e9f92a33ad..f980b0fceb 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/NewTransaction.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/cordapps/cash/NewTransaction.kt @@ -143,6 +143,8 @@ class NewTransaction : Fragment() { } } + private fun selectNotary(): Party = notaries.first().value!! + private fun newTransactionDialog(window: Window) = Dialog().apply { dialogPane = root initOwner(window) @@ -152,8 +154,8 @@ class NewTransaction : Fragment() { val issueRef = if (issueRef.value != null) OpaqueBytes.of(issueRef.value) else defaultRef when (it) { executeButton -> when (transactionTypeCB.value) { - CashTransaction.Issue -> IssueAndPaymentRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), issueRef, partyBChoiceBox.value.party, notaries.first().value!!, anonymous) - CashTransaction.Pay -> PaymentRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), partyBChoiceBox.value.party, anonymous = anonymous) + CashTransaction.Issue -> IssueAndPaymentRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), issueRef, partyBChoiceBox.value.party, selectNotary(), anonymous) + CashTransaction.Pay -> PaymentRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), partyBChoiceBox.value.party, anonymous = anonymous, notary = selectNotary()) CashTransaction.Exit -> ExitRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), issueRef) else -> null }