mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Fix the BFT notary demo. (#1172)
This commit is contained in:
parent
fb1bec77d9
commit
baafccc200
@ -56,7 +56,7 @@ private class NotaryDemoClientApi(val rpc: CordaRPCOps) {
|
||||
*/
|
||||
private fun buildTransactions(count: Int): List<SignedTransaction> {
|
||||
return Futures.allAsList((1..count).map {
|
||||
rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity).returnValue
|
||||
rpc.startFlow(::DummyIssueAndMove, notary, counterpartyNode.legalIdentity, it).returnValue
|
||||
}).getOrThrow()
|
||||
}
|
||||
|
||||
|
@ -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<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
|
||||
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<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
|
||||
return moveTx
|
||||
signInitialTransaction(TransactionBuilder(notary).apply {
|
||||
addInputState(issueTx.tx.outRef<ContractState>(0))
|
||||
addOutputState(state.copy(participants = listOf(counterpartyNode)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user