mirror of
https://github.com/corda/corda.git
synced 2024-12-21 13:57:54 +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> {
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user