mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
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:
parent
9258b0e63b
commit
ad2890193d
@ -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
|
||||
@ -47,4 +47,4 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
|
||||
val recipient: Party,
|
||||
val notary: Party,
|
||||
val anonymous: Boolean) : AbstractRequest(amount)
|
||||
}
|
||||
}
|
||||
|
@ -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<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 {
|
||||
@ -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<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)
|
||||
}
|
||||
|
@ -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)
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user