Skip to content

Commit 59ade8a

Browse files
Added overloads to claim and attestation command services to allow issuance, amendment and revocation of custom claim and attestation types.
1 parent 6e58b43 commit 59ade8a

File tree

3 files changed

+67
-52
lines changed

3 files changed

+67
-52
lines changed

onixlabs-corda-identity-framework-integration/src/main/kotlin/io/onixlabs/corda/identityframework/integration/AttestationCommandService.kt

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ import net.corda.core.transactions.SignedTransaction
3939
*/
4040
class AttestationCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
4141

42+
/**
43+
* Issues an attestation.
44+
*
45+
* @param T The [Attestation] type.
46+
* @param attestation The attestation to issue.
47+
* @param notary The notary to use for the transaction.
48+
* @param observers Additional observers of the transaction.
49+
* @return Returns a flow process handle.
50+
*/
51+
fun <T : Attestation<*>> issueAttestation(
52+
attestation: T,
53+
notary: Party? = null,
54+
observers: Set<Party> = emptySet()
55+
): FlowProgressHandle<SignedTransaction> {
56+
return rpc.startTrackedFlow(IssueAttestationFlow::Initiator, attestation, notary, observers)
57+
}
58+
4259
/**
4360
* Issues an attestation.
4461
*
@@ -50,6 +67,7 @@ class AttestationCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
5067
* @param linearId The unique identifier of the attestation.
5168
* @param notary The notary to use for the transaction.
5269
* @param observers Additional observers of the transaction.
70+
* @return Returns a flow process handle.
5371
*/
5472
fun <T : ContractState> issueAttestation(
5573
state: StateAndRef<T>,
@@ -60,98 +78,97 @@ class AttestationCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
6078
notary: Party? = null,
6179
observers: Set<Party> = emptySet()
6280
): FlowProgressHandle<SignedTransaction> {
63-
return rpc.startTrackedFlow(
64-
IssueAttestationFlow::Initiator,
65-
state.attest(attestor, status, metadata, linearId),
66-
notary,
67-
observers
68-
)
81+
val attestation = state.attest(attestor, status, metadata, linearId)
82+
return issueAttestation(attestation, notary, observers)
83+
}
84+
85+
/**
86+
* Amends an attestation.
87+
*
88+
* @param T The [Attestation] type.
89+
* @param oldAttestation The old attestation to be consumed.
90+
* @param newAttestation The new attestation to be created.
91+
* @param observers Additional observers of the transaction.
92+
* @return Returns a flow process handle.
93+
*/
94+
fun <T : Attestation<*>> amendAttestation(
95+
oldAttestation: StateAndRef<T>,
96+
newAttestation: T,
97+
observers: Set<Party> = emptySet()
98+
): FlowProgressHandle<SignedTransaction> {
99+
return rpc.startTrackedFlow(AmendAttestationFlow::Initiator, oldAttestation, newAttestation, observers)
69100
}
70101

71102
/**
72103
* Amends an attestation.
73104
*
74105
* @param T The underlying [ContractState] type.
75-
* @param attestation The attestation to be consumed.
106+
* @param oldAttestation The old attestation to be consumed.
76107
* @param status The status of the attestation.
77108
* @param metadata Additional information about the attestation.
78109
* @param observers Additional observers of the transaction.
110+
* @return Returns a flow process handle.
79111
*/
80112
fun <T : ContractState> amendAttestation(
81-
attestation: StateAndRef<Attestation<T>>,
113+
oldAttestation: StateAndRef<Attestation<T>>,
82114
status: AttestationStatus = AttestationStatus.REJECTED,
83115
metadata: Map<String, String> = emptyMap(),
84116
observers: Set<Party> = emptySet()
85117
): FlowProgressHandle<SignedTransaction> {
86-
val amendedAttestation = attestation.amend(status, metadata = metadata)
87-
return rpc.startTrackedFlow(
88-
AmendAttestationFlow::Initiator,
89-
attestation,
90-
amendedAttestation,
91-
observers
92-
)
118+
val newAttestation = oldAttestation.amend(status, metadata = metadata)
119+
return amendAttestation(oldAttestation, newAttestation, observers)
93120
}
94121

95122
/**
96123
* Amends an attestation.
97124
*
98125
* @param T The underlying [ContractState] type.
99-
* @param attestation The attestation to be consumed.
126+
* @param oldAttestation The old attestation to be consumed.
100127
* @param state The state being attested.
101128
* @param status The status of the attestation.
102129
* @param metadata Additional information about the attestation.
103130
* @param observers Additional observers of the transaction.
131+
* @return Returns a flow process handle.
104132
*/
105133
fun <T : ContractState> amendAttestation(
106-
attestation: StateAndRef<Attestation<T>>,
134+
oldAttestation: StateAndRef<Attestation<T>>,
107135
state: StateAndRef<T>,
108136
status: AttestationStatus = AttestationStatus.REJECTED,
109137
metadata: Map<String, String> = emptyMap(),
110138
observers: Set<Party> = emptySet()
111139
): FlowProgressHandle<SignedTransaction> {
112140
val pointer = state.toAttestationPointer()
113-
val amendedAttestation = attestation.amend(status, pointer, metadata)
114-
return rpc.startTrackedFlow(
115-
AmendAttestationFlow::Initiator,
116-
attestation,
117-
amendedAttestation,
118-
observers
119-
)
141+
val newAttestation = oldAttestation.amend(status, pointer, metadata)
142+
return amendAttestation(oldAttestation, newAttestation, observers)
120143
}
121144

122145
/**
123146
* Revokes an attestation.
124147
*
125-
* @param T The underlying [ContractState] type.
148+
* @param T The [Attestation] type.
126149
* @param attestation The attestation to be consumed.
127150
* @param observers Additional observers of the transaction.
151+
* @return Returns a flow process handle.
128152
*/
129-
fun <T : ContractState> revokeAttestation(
130-
attestation: StateAndRef<Attestation<T>>,
153+
fun <T : Attestation<*>> revokeAttestation(
154+
attestation: StateAndRef<T>,
131155
observers: Set<Party> = emptySet()
132156
): FlowProgressHandle<SignedTransaction> {
133-
return rpc.startTrackedFlow(
134-
RevokeAttestationFlow::Initiator,
135-
attestation,
136-
observers
137-
)
157+
return rpc.startTrackedFlow(RevokeAttestationFlow::Initiator, attestation, observers)
138158
}
139159

140160
/**
141161
* Publishes an attestation.
142162
*
143-
* @param T The underlying [ContractState] type.
163+
* @param T The [Attestation] type.
144164
* @param attestation The attestation to be published.
145165
* @param observers Observers of the attestation.
166+
* @return Returns a flow process handle.
146167
*/
147-
fun <T : ContractState> publishAttestation(
148-
attestation: StateAndRef<Attestation<T>>,
168+
fun <T : Attestation<*>> publishAttestation(
169+
attestation: StateAndRef<T>,
149170
observers: Set<Party>
150171
): FlowProgressHandle<SignedTransaction> {
151-
return rpc.startTrackedFlow(
152-
PublishAttestationFlow::Initiator,
153-
attestation,
154-
observers
155-
)
172+
return rpc.startTrackedFlow(PublishAttestationFlow::Initiator, attestation, observers)
156173
}
157174
}

onixlabs-corda-identity-framework-integration/src/main/kotlin/io/onixlabs/corda/identityframework/integration/ClaimCommandService.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
4242
/**
4343
* Issues a claim.
4444
*
45+
* @param T The underlying claim value type.
4546
* @param claim The claim to issue.
4647
* @param notary The notary to use for the transaction.
4748
* @param observers Additional observers of the transaction.
49+
* @return Returns a flow process handle.
4850
*/
4951
fun <T : Any> issueClaim(
5052
claim: CordaClaim<T>,
@@ -65,6 +67,7 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
6567
* @param linearId The unique identifier of the claim.
6668
* @param notary The notary to use for the transaction.
6769
* @param observers Additional observers of the transaction.
70+
* @return Returns a flow process handle.
6871
*/
6972
fun <T : Any> issueClaim(
7073
property: String,
@@ -86,6 +89,7 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
8689
* @param oldClaim The claim to be consumed.
8790
* @param newClaim The claim to be created.
8891
* @param observers Additional observers of the transaction.
92+
* @return Returns a flow process handle.
8993
*/
9094
fun <T : Any> amendClaim(
9195
oldClaim: StateAndRef<CordaClaim<T>>,
@@ -102,6 +106,7 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
102106
* @param claim The claim to be consumed.
103107
* @param value The amended value of the claim.
104108
* @param observers Additional observers of the transaction.
109+
* @return Returns a flow process handle.
105110
*/
106111
fun <T : Any> amendClaim(
107112
claim: StateAndRef<CordaClaim<T>>,
@@ -117,16 +122,13 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
117122
* @param T The underlying claim value type.
118123
* @param claim The claim to be consumed.
119124
* @param observers Additional observers of the transaction.
125+
* @return Returns a flow process handle.
120126
*/
121127
fun <T : Any> revokeClaim(
122128
claim: StateAndRef<CordaClaim<T>>,
123129
observers: Set<Party> = emptySet()
124130
): FlowProgressHandle<SignedTransaction> {
125-
return rpc.startTrackedFlow(
126-
RevokeClaimFlow::Initiator,
127-
claim,
128-
observers
129-
)
131+
return rpc.startTrackedFlow(RevokeClaimFlow::Initiator, claim, observers)
130132
}
131133

132134
/**
@@ -135,15 +137,12 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
135137
* @param T The underlying claim value type.
136138
* @param claim The claim to be published.
137139
* @param observers Additional observers of the transaction.
140+
* @return Returns a flow process handle.
138141
*/
139142
fun <T : Any> publishClaim(
140143
claim: StateAndRef<CordaClaim<T>>,
141144
observers: Set<Party>
142145
): FlowProgressHandle<SignedTransaction> {
143-
return rpc.startTrackedFlow(
144-
PublishClaimFlow::Initiator,
145-
claim,
146-
observers
147-
)
146+
return rpc.startTrackedFlow(PublishClaimFlow::Initiator, claim, observers)
148147
}
149148
}

onixlabs-corda-identity-framework-integration/src/test/kotlin/io/onixlabs/corda/identityframework/integration/AttestationIntegrationTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.onixlabs.corda.identityframework.integration
1818

19-
import io.onixlabs.corda.core.contract.cast
2019
import io.onixlabs.corda.identityframework.contract.Attestation
2120
import io.onixlabs.corda.identityframework.contract.AttestationStatus
2221
import io.onixlabs.corda.identityframework.contract.CordaClaim
@@ -57,7 +56,7 @@ class AttestationIntegrationTests : IntegrationTest() {
5756

5857
// Amend the issued attestation
5958
nodeC.attestations.commandService.amendAttestation(
60-
attestation = issuedAttestation,
59+
oldAttestation = issuedAttestation,
6160
state = issuedClaim,
6261
status = AttestationStatus.ACCEPTED
6362
).returnValue.getOrThrow()

0 commit comments

Comments
 (0)