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`
This commit is contained in:
Thomas Schroeter 2018-06-26 16:45:18 +01:00 committed by GitHub
parent 9258b0e63b
commit ad2890193d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -38,7 +38,7 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
@Suspendable @Suspendable
override fun call(): Result { override fun call(): Result {
subFlow(CashIssueFlow(amount, issueRef, notary)) subFlow(CashIssueFlow(amount, issueRef, notary))
return subFlow(CashPaymentFlow(amount, recipient, anonymous)) return subFlow(CashPaymentFlow(amount, recipient, anonymous, notary))
} }
@CordaSerializable @CordaSerializable

View File

@ -24,6 +24,7 @@ import java.util.*
* @param recipient the party to pay the currency to. * @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 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 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. * for testing purposes.
*/ */
@StartableByRPC @StartableByRPC
@ -32,14 +33,17 @@ open class CashPaymentFlow(
val recipient: Party, val recipient: Party,
val anonymous: Boolean, val anonymous: Boolean,
progressTracker: ProgressTracker, progressTracker: ProgressTracker,
val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) { val issuerConstraint: Set<Party> = emptySet(),
val notary: Party? = null) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker()) constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
constructor(amount: Amount<Currency>, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker()) constructor(amount: Amount<Currency>, 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<Currency>, 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 @Suspendable
override fun call(): AbstractCashFlow.Result { override fun call(): AbstractCashFlow.Result {
@ -51,7 +55,7 @@ open class CashPaymentFlow(
} }
val anonymousRecipient = txIdentities[recipient] ?: recipient val anonymousRecipient = txIdentities[recipient] ?: recipient
progressTracker.currentStep = GENERATING_TX 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}") logger.info("Generating spend for: ${builder.lockId}")
// TODO: Have some way of restricting this to states the caller controls // TODO: Have some way of restricting this to states the caller controls
val (spendTX, keysForSigning) = try { val (spendTX, keysForSigning) = try {
@ -80,5 +84,6 @@ open class CashPaymentFlow(
class PaymentRequest(amount: Amount<Currency>, class PaymentRequest(amount: Amount<Currency>,
val recipient: Party, val recipient: Party,
val anonymous: Boolean, val anonymous: Boolean,
val issuerConstraint: Set<Party> = emptySet()) : AbstractRequest(amount) val issuerConstraint: Set<Party> = emptySet(),
val notary: Party? = null) : AbstractRequest(amount)
} }

View File

@ -143,6 +143,8 @@ class NewTransaction : Fragment() {
} }
} }
private fun selectNotary(): Party = notaries.first().value!!
private fun newTransactionDialog(window: Window) = Dialog<AbstractCashFlow.AbstractRequest>().apply { private fun newTransactionDialog(window: Window) = Dialog<AbstractCashFlow.AbstractRequest>().apply {
dialogPane = root dialogPane = root
initOwner(window) initOwner(window)
@ -152,8 +154,8 @@ class NewTransaction : Fragment() {
val issueRef = if (issueRef.value != null) OpaqueBytes.of(issueRef.value) else defaultRef val issueRef = if (issueRef.value != null) OpaqueBytes.of(issueRef.value) else defaultRef
when (it) { when (it) {
executeButton -> when (transactionTypeCB.value) { executeButton -> when (transactionTypeCB.value) {
CashTransaction.Issue -> IssueAndPaymentRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), issueRef, partyBChoiceBox.value.party, notaries.first().value!!, 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) 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) CashTransaction.Exit -> ExitRequest(Amount.fromDecimal(amount.value, currencyChoiceBox.value), issueRef)
else -> null else -> null
} }