Split CashFlow into three flows

Split CashFlow into independent CashIssueFlow, CashExitFlow and CashPaymentFlow,
so that users can be given access to one but not the other(s).

Signed-off-by: Ross Nicoll <ross.nicoll@r3.com>
This commit is contained in:
Ross Nicoll
2017-01-30 18:34:48 +00:00
parent 47d260625a
commit 9055c9d9b0
25 changed files with 357 additions and 254 deletions

View File

@ -9,7 +9,7 @@ import net.corda.core.messaging.startFlow
import net.corda.core.node.services.ServiceInfo
import net.corda.core.node.services.Vault
import net.corda.core.serialization.OpaqueBytes
import net.corda.flows.CashCommand
import net.corda.core.toFuture
import net.corda.flows.CashFlow
import net.corda.node.driver.driver
import net.corda.node.services.User
@ -56,7 +56,7 @@ class IntegrationTestingTutorial {
val issueRef = OpaqueBytes.of(0)
for (i in 1 .. 10) {
thread {
aliceProxy.startFlow(::CashFlow, CashCommand.IssueCash(
aliceProxy.startFlow(::CashFlow, CashFlow.Command.IssueCash(
amount = i.DOLLARS,
issueRef = issueRef,
recipient = bob.nodeInfo.legalIdentity,
@ -82,7 +82,7 @@ class IntegrationTestingTutorial {
// START 5
for (i in 1 .. 10) {
val flowHandle = bobProxy.startFlow(::CashFlow, CashCommand.PayCash(
val flowHandle = bobProxy.startFlow(::CashFlow, CashFlow.Command.PayCash(
amount = i.DOLLARS.issuedBy(alice.nodeInfo.legalIdentity.ref(issueRef)),
recipient = alice.nodeInfo.legalIdentity
))
@ -102,4 +102,4 @@ class IntegrationTestingTutorial {
}
}
}
// END 5
// END 5

View File

@ -12,8 +12,9 @@ import net.corda.core.node.CordaPluginRegistry
import net.corda.core.node.services.ServiceInfo
import net.corda.core.serialization.OpaqueBytes
import net.corda.core.transactions.SignedTransaction
import net.corda.flows.CashCommand
import net.corda.flows.CashFlow
import net.corda.flows.CashExitFlow
import net.corda.flows.CashIssueFlow
import net.corda.flows.CashPaymentFlow
import net.corda.node.driver.driver
import net.corda.node.services.User
import net.corda.node.services.startFlowPermission
@ -41,7 +42,9 @@ fun main(args: Array<String>) {
val printOrVisualise = PrintOrVisualise.valueOf(args[0])
val baseDirectory = Paths.get("build/rpc-api-tutorial")
val user = User("user", "password", permissions = setOf(startFlowPermission<CashFlow>()))
val user = User("user", "password", permissions = setOf(startFlowPermission<CashIssueFlow>(),
startFlowPermission<CashPaymentFlow>(),
startFlowPermission<CashExitFlow>()))
driver(driverDirectory = baseDirectory) {
startNode("Notary", advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
@ -114,14 +117,14 @@ fun generateTransactions(proxy: CordaRPCOps) {
val n = random.nextDouble()
if (ownedQuantity > 10000 && n > 0.8) {
val quantity = Math.abs(random.nextLong()) % 2000
proxy.startFlow(::CashFlow, CashCommand.ExitCash(Amount(quantity, USD), issueRef))
proxy.startFlow(::CashExitFlow, Amount(quantity, USD), issueRef)
ownedQuantity -= quantity
} else if (ownedQuantity > 1000 && n < 0.7) {
val quantity = Math.abs(random.nextLong() % Math.min(ownedQuantity, 2000))
proxy.startFlow(::CashFlow, CashCommand.PayCash(Amount(quantity, Issued(meAndRef, USD)), me))
proxy.startFlow(::CashPaymentFlow, Amount(quantity, Issued(meAndRef, USD)), me)
} else {
val quantity = Math.abs(random.nextLong() % 1000)
proxy.startFlow(::CashFlow, CashCommand.IssueCash(Amount(quantity, USD), issueRef, me, notary))
proxy.startFlow(::CashIssueFlow, Amount(quantity, USD), issueRef, me, notary)
ownedQuantity += quantity
}
}

View File

@ -1,6 +1,5 @@
package net.corda.docs
import net.corda.core.crypto.Party
import net.corda.core.contracts.*
import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo
@ -8,9 +7,8 @@ import net.corda.core.serialization.OpaqueBytes
import net.corda.core.toFuture
import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.core.utilities.DUMMY_NOTARY_KEY
import net.corda.flows.CashCommand
import net.corda.flows.CashFlow
import net.corda.core.node.ServiceEntry
import net.corda.flows.CashIssueFlow
import net.corda.flows.CashPaymentFlow
import net.corda.node.services.network.NetworkMapService
import net.corda.node.services.transactions.ValidatingNotaryService
import net.corda.node.utilities.databaseTransaction
@ -51,19 +49,19 @@ class FxTransactionBuildTutorialTest {
@Test
fun `Run ForeignExchangeFlow to completion`() {
// Use NodeA as issuer and create some dollars
val flowHandle1 = nodeA.services.startFlow(CashFlow(CashCommand.IssueCash(DOLLARS(1000),
val flowHandle1 = nodeA.services.startFlow(CashIssueFlow(DOLLARS(1000),
OpaqueBytes.of(0x01),
nodeA.info.legalIdentity,
notaryNode.info.notaryIdentity)))
notaryNode.info.notaryIdentity))
// Wait for the flow to stop and print
flowHandle1.resultFuture.getOrThrow()
printBalances()
// Using NodeB as Issuer create some pounds.
val flowHandle2 = nodeB.services.startFlow(CashFlow(CashCommand.IssueCash(POUNDS(1000),
val flowHandle2 = nodeB.services.startFlow(CashIssueFlow(POUNDS(1000),
OpaqueBytes.of(0x01),
nodeB.info.legalIdentity,
notaryNode.info.notaryIdentity)))
notaryNode.info.notaryIdentity))
// Wait for flow to come to an end and print
flowHandle2.resultFuture.getOrThrow()
printBalances()
@ -107,4 +105,4 @@ class FxTransactionBuildTutorialTest {
println("BalanceB\n" + nodeB.services.vaultService.cashBalances)
}
}
}
}