1
+ package net.corda.verification
2
+
3
+ import co.paralleluniverse.fibers.Suspendable
4
+ import net.corda.core.contracts.CommandData
5
+ import net.corda.core.contracts.Contract
6
+ import net.corda.core.contracts.ContractState
7
+ import net.corda.core.flows.*
8
+ import net.corda.core.identity.AbstractParty
9
+ import net.corda.core.identity.CordaX500Name
10
+ import net.corda.core.identity.Party
11
+ import net.corda.core.serialization.CordaSerializable
12
+ import net.corda.core.transactions.LedgerTransaction
13
+ import net.corda.core.transactions.TransactionBuilder
14
+ import net.corda.core.utilities.ProgressTracker
15
+ import net.corda.core.utilities.unwrap
16
+
17
+
18
+ @StartableByRPC
19
+ @InitiatingFlow
20
+ class TestCommsFlowInitiator (val x500Name : CordaX500Name ? = null ) : FlowLogic<List<String>>() {
21
+
22
+ object SENDING : ProgressTracker.Step(" SENDING" )
23
+ object RECIEVED_ALL : ProgressTracker.Step(" RECIEVED_ALL" )
24
+ object FINALIZING : ProgressTracker.Step(" FINALIZING" )
25
+
26
+ override val progressTracker: ProgressTracker = ProgressTracker (SENDING , RECIEVED_ALL , FINALIZING )
27
+
28
+ @Suspendable
29
+ override fun call (): List <String > {
30
+ progressTracker.currentStep = SENDING
31
+ val responses = serviceHub.networkMapCache.allNodes.map {
32
+ it.legalIdentities.first()
33
+ }.filterNot {
34
+ it in serviceHub.myInfo.legalIdentities
35
+ }.filterNot {
36
+ it in serviceHub.networkMapCache.notaryIdentities
37
+ }.filter(::matchesX500)
38
+ .map {
39
+ val initiateFlow = initiateFlow(it)
40
+ initiateFlow.receive<String >().unwrap { it }
41
+ }.toList().also {
42
+ progressTracker.currentStep = RECIEVED_ALL
43
+ }
44
+ val tx = TransactionBuilder (notary = serviceHub.networkMapCache.notaryIdentities.first())
45
+ tx.addOutputState(CommsTestState (responses, serviceHub.myInfo.legalIdentities.first()), CommsTestContract ::class .qualifiedName!! )
46
+ tx.addCommand(CommsTestCommand , serviceHub.myInfo.legalIdentities.first().owningKey)
47
+ val signedTx = serviceHub.signInitialTransaction(tx)
48
+ subFlow(FinalityFlow (signedTx))
49
+ return responses
50
+ }
51
+
52
+ fun matchesX500 (it : Party ): Boolean {
53
+ return x500Name?.equals(it.name) ? : true
54
+ }
55
+ }
56
+
57
+ @InitiatedBy(TestCommsFlowInitiator ::class )
58
+ class TestCommsFlowResponder (val otherSideSession : FlowSession ) : FlowLogic<Unit>() {
59
+ @Suspendable
60
+ override fun call () {
61
+ otherSideSession.send(" Hello from: " + serviceHub.myInfo.legalIdentities.first().name.toString())
62
+ }
63
+
64
+ }
65
+
66
+ @CordaSerializable
67
+ data class CommsTestState (val responses : List <String >, val issuer : AbstractParty ) : ContractState {
68
+ override val participants: List <AbstractParty >
69
+ get() = listOf (issuer)
70
+
71
+ }
72
+
73
+
74
+ @CordaSerializable
75
+ object CommsTestCommand : CommandData
76
+
77
+
78
+ class CommsTestContract : Contract {
79
+ override fun verify (tx : LedgerTransaction ) {
80
+ }
81
+ }
0 commit comments