1
1
package com.template
2
2
3
3
import co.paralleluniverse.fibers.Suspendable
4
+ import net.corda.core.contracts.CommandData
4
5
import net.corda.core.contracts.Contract
5
6
import net.corda.core.contracts.ContractState
6
- import net.corda.core.flows.FlowLogic
7
- import net.corda.core.flows.InitiatedBy
8
- import net.corda.core.flows.InitiatingFlow
9
- import net.corda.core.flows.StartableByRPC
7
+ import net.corda.core.flows.*
10
8
import net.corda.core.identity.AbstractParty
11
- import net.corda.core.identity.Party
12
9
import net.corda.core.messaging.CordaRPCOps
13
10
import net.corda.core.serialization.SerializationWhitelist
14
11
import net.corda.core.transactions.LedgerTransaction
@@ -24,13 +21,13 @@ import javax.ws.rs.core.Response
24
21
// * API Endpoints *
25
22
// *****************
26
23
@Path(" template" )
27
- class TemplateApi (val services : CordaRPCOps ) {
24
+ class TemplateApi (val rpcOps : CordaRPCOps ) {
28
25
// Accessible at /api/template/templateGetEndpoint.
29
26
@GET
30
27
@Path(" templateGetEndpoint" )
31
28
@Produces(MediaType .APPLICATION_JSON )
32
29
fun templateGetEndpoint (): Response {
33
- return Response .ok(mapOf ( " message " to " Template GET endpoint." ) ).build()
30
+ return Response .ok(" Template GET endpoint." ).build()
34
31
}
35
32
}
36
33
@@ -41,17 +38,22 @@ class TemplateApi(val services: CordaRPCOps) {
41
38
val TEMPLATE_CONTRACT_ID = " com.template.TemplateContract"
42
39
43
40
open class TemplateContract : Contract {
44
- // The verify() function of the contract for each of the transaction's input and output states must not throw an
45
- // exception for a transaction to be considered valid .
41
+ // A transaction is considered valid if the verify() function of the contract of each of the transaction's input
42
+ // and output states does not throw an exception .
46
43
override fun verify (tx : LedgerTransaction ) {
47
44
// Verification logic goes here.
48
45
}
46
+
47
+ // Used to indicate the transaction's intent.
48
+ interface Commands : CommandData {
49
+ class Action : Commands
50
+ }
49
51
}
50
52
51
53
// *********
52
54
// * State *
53
55
// *********
54
- class TemplateState (val data : String ) : ContractState {
56
+ data class TemplateState (val data : String ) : ContractState {
55
57
override val participants: List <AbstractParty > get() = listOf ()
56
58
}
57
59
@@ -68,21 +70,13 @@ class Initiator : FlowLogic<Unit>() {
68
70
}
69
71
70
72
@InitiatedBy(Initiator ::class )
71
- class Responder (val otherParty : Party ) : FlowLogic<Unit>() {
73
+ class Responder (val counterpartySession : FlowSession ) : FlowLogic<Unit>() {
72
74
@Suspendable
73
75
override fun call () {
74
76
return Unit
75
77
}
76
78
}
77
79
78
- // Serialization whitelist (only needed for 3rd party classes, but we use a local example here).
79
- class TemplateSerializationWhitelist : SerializationWhitelist {
80
- override val whitelist: List <Class <* >> = listOf (TemplateData ::class .java)
81
- }
82
-
83
- // Not annotated with @CordaSerializable just for use with manual whitelisting above.
84
- data class TemplateData (val payload : String )
85
-
86
80
class TemplateWebPlugin : WebServerPluginRegistry {
87
81
// A list of classes that expose web JAX-RS REST APIs.
88
82
override val webApis: List <Function <CordaRPCOps , out Any >> = listOf (Function (::TemplateApi ))
@@ -93,3 +87,12 @@ class TemplateWebPlugin : WebServerPluginRegistry {
93
87
" template" to javaClass.classLoader.getResource(" templateWeb" ).toExternalForm()
94
88
)
95
89
}
90
+
91
+ // Serialization whitelist.
92
+ class TemplateSerializationWhitelist : SerializationWhitelist {
93
+ override val whitelist: List <Class <* >> = listOf (TemplateData ::class .java)
94
+ }
95
+
96
+ // This class is not annotated with @CordaSerializable, so it must be added to the serialization whitelist, above, if
97
+ // we want to send it to other nodes within a flow.
98
+ data class TemplateData (val payload : String )
0 commit comments