Fix the BFT notary demo. (#1172)

This commit is contained in:
Andrzej Cichocki 2017-08-06 23:02:10 +01:00 committed by Clinton
parent fb1bec77d9
commit baafccc200
2 changed files with 27 additions and 13 deletions

View File

@ -56,7 +56,7 @@ private class NotaryDemoClientApi(val rpc: CordaRPCOps) {
*/ */
private fun buildTransactions(count: Int): List<SignedTransaction> { private fun buildTransactions(count: Int): List<SignedTransaction> {
return Futures.allAsList((1..count).map { return Futures.allAsList((1..count).map {
rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity).returnValue rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity, it).returnValue
}).getOrThrow() }).getOrThrow()
} }

View File

@ -1,27 +1,41 @@
package net.corda.notarydemo.flows package net.corda.notarydemo.flows
import co.paralleluniverse.fibers.Suspendable 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.FlowLogic
import net.corda.core.flows.StartableByRPC import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.testing.contracts.DummyContract import net.corda.core.transactions.TransactionBuilder
import java.util.*
@StartableByRPC @StartableByRPC
class DummyIssueAndMove(private val notary: Party, private val counterpartyNode: Party) : FlowLogic<SignedTransaction>() { class DummyIssueAndMove(private val notary: Party, private val counterpartyNode: Party, private val discriminator: Int) : FlowLogic<SignedTransaction>() {
object DoNothingContract : Contract {
override val legalContractReference = byteArrayOf().sha256()
override fun verify(tx: LedgerTransaction) {}
}
data class State(override val participants: List<AbstractParty>, private val discriminator: Int) : ContractState {
override val contract = DoNothingContract
}
@Suspendable @Suspendable
override fun call(): SignedTransaction { override fun call() = serviceHub.run {
val random = Random()
// Self issue an asset // Self issue an asset
val issueTxBuilder = DummyContract.generateInitial(random.nextInt(), notary, serviceHub.myInfo.legalIdentity.ref(0)) val state = State(listOf(myInfo.legalIdentity), discriminator)
val issueTx = serviceHub.signInitialTransaction(issueTxBuilder) val issueTx = signInitialTransaction(TransactionBuilder(notary).apply {
serviceHub.recordTransactions(issueTx) addOutputState(state)
})
recordTransactions(issueTx)
// Move ownership of the asset to the counterparty // Move ownership of the asset to the counterparty
val asset = issueTx.tx.outRef<DummyContract.SingleOwnerState>(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 // 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<ContractState>(0))
addOutputState(state.copy(participants = listOf(counterpartyNode)))
})
} }
} }