From baafccc200de291aa201eb8c4cfbbee8a4490cbe Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Sun, 6 Aug 2017 23:02:10 +0100 Subject: [PATCH] Fix the BFT notary demo. (#1172) --- .../kotlin/net/corda/notarydemo/Notarise.kt | 2 +- .../notarydemo/flows/DummyIssueAndMove.kt | 38 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt index 890f51ce86..28900fecfa 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt @@ -56,7 +56,7 @@ private class NotaryDemoClientApi(val rpc: CordaRPCOps) { */ private fun buildTransactions(count: Int): List { return Futures.allAsList((1..count).map { - rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity).returnValue + rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity, it).returnValue }).getOrThrow() } diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt index cc0155fcda..83929ac597 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt @@ -1,27 +1,41 @@ package net.corda.notarydemo.flows import co.paralleluniverse.fibers.Suspendable +import net.corda.core.contracts.Contract +import net.corda.core.contracts.ContractState +import net.corda.core.crypto.sha256 import net.corda.core.flows.FlowLogic import net.corda.core.flows.StartableByRPC +import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party +import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.SignedTransaction -import net.corda.testing.contracts.DummyContract -import java.util.* +import net.corda.core.transactions.TransactionBuilder @StartableByRPC -class DummyIssueAndMove(private val notary: Party, private val counterpartyNode: Party) : FlowLogic() { +class DummyIssueAndMove(private val notary: Party, private val counterpartyNode: Party, private val discriminator: Int) : FlowLogic() { + object DoNothingContract : Contract { + override val legalContractReference = byteArrayOf().sha256() + override fun verify(tx: LedgerTransaction) {} + } + + data class State(override val participants: List, private val discriminator: Int) : ContractState { + override val contract = DoNothingContract + } + @Suspendable - override fun call(): SignedTransaction { - val random = Random() + override fun call() = serviceHub.run { // Self issue an asset - val issueTxBuilder = DummyContract.generateInitial(random.nextInt(), notary, serviceHub.myInfo.legalIdentity.ref(0)) - val issueTx = serviceHub.signInitialTransaction(issueTxBuilder) - serviceHub.recordTransactions(issueTx) + val state = State(listOf(myInfo.legalIdentity), discriminator) + val issueTx = signInitialTransaction(TransactionBuilder(notary).apply { + addOutputState(state) + }) + recordTransactions(issueTx) // Move ownership of the asset to the counterparty - val asset = issueTx.tx.outRef(0) - val moveTxBuilder = DummyContract.move(asset, counterpartyNode) - val moveTx = serviceHub.signInitialTransaction(moveTxBuilder) // We don't check signatures because we know that the notary's signature is missing - return moveTx + signInitialTransaction(TransactionBuilder(notary).apply { + addInputState(issueTx.tx.outRef(0)) + addOutputState(state.copy(participants = listOf(counterpartyNode))) + }) } }