Skip to content

Commit

Permalink
Specify Notary in CashIssueAndPaymentFlow and PaymentRequest (cor…
Browse files Browse the repository at this point in the history
…da#3443)

* Specify notary in CashIssueAndPaymentFlow

* Specify notary in PaymentRequest

* Address comments

* Default to the first notary in the `CashPaymentFlow`
  • Loading branch information
Thomas Schroeter authored Jun 26, 2018
1 parent 9258b0e commit ad28901
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
@Suspendable
override fun call(): Result {
subFlow(CashIssueFlow(amount, issueRef, notary))
return subFlow(CashPaymentFlow(amount, recipient, anonymous))
return subFlow(CashPaymentFlow(amount, recipient, anonymous, notary))
}

@CordaSerializable
Expand All @@ -47,4 +47,4 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
val recipient: Party,
val notary: Party,
val anonymous: Boolean) : AbstractRequest(amount)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,14 +33,17 @@ open class CashPaymentFlow(
val recipient: Party,
val anonymous: Boolean,
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. */
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())

/** 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(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
override fun call(): AbstractCashFlow.Result {
Expand All @@ -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 {
Expand Down Expand Up @@ -80,5 +84,6 @@ open class CashPaymentFlow(
class PaymentRequest(amount: Amount<Currency>,
val recipient: Party,
val anonymous: Boolean,
val issuerConstraint: Set<Party> = emptySet()) : AbstractRequest(amount)
val issuerConstraint: Set<Party> = emptySet(),
val notary: Party? = null) : AbstractRequest(amount)
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class NewTransaction : Fragment() {
}
}

private fun selectNotary(): Party = notaries.first().value!!

private fun newTransactionDialog(window: Window) = Dialog<AbstractCashFlow.AbstractRequest>().apply {
dialogPane = root
initOwner(window)
Expand All @@ -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
}
Expand Down

0 comments on commit ad28901

Please sign in to comment.