Skip to content

Commit 4d50b0e

Browse files
Merge pull request #4 from onix-labs/feature-integration
Feature integration
2 parents 2124e9a + b33d57b commit 4d50b0e

File tree

3 files changed

+101
-64
lines changed

3 files changed

+101
-64
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: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ import net.corda.core.transactions.SignedTransaction
3939
*/
4040
class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
4141

42+
/**
43+
* Issues a claim.
44+
*
45+
* @param T The underlying claim value type.
46+
* @param claim The claim 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 : Any> issueClaim(
52+
claim: CordaClaim<T>,
53+
notary: Party? = null,
54+
observers: Set<Party> = emptySet()
55+
): FlowProgressHandle<SignedTransaction> {
56+
return rpc.startTrackedFlow(IssueClaimFlow::Initiator, claim, notary, observers)
57+
}
58+
4259
/**
4360
* Issues a claim.
4461
*
@@ -50,6 +67,7 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
5067
* @param linearId The unique identifier of the claim.
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 : Any> issueClaim(
5573
property: String,
@@ -60,12 +78,25 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
6078
notary: Party? = null,
6179
observers: Set<Party> = emptySet()
6280
): FlowProgressHandle<SignedTransaction> {
63-
return rpc.startTrackedFlow(
64-
IssueClaimFlow::Initiator,
65-
CordaClaim(issuer, holder, property, value, linearId),
66-
notary,
67-
observers
68-
)
81+
val claim = CordaClaim(issuer, holder, property, value, linearId)
82+
return issueClaim(claim, notary, observers)
83+
}
84+
85+
/**
86+
* Amends a claim.
87+
*
88+
* @param T The underlying claim value type.
89+
* @param oldClaim The claim to be consumed.
90+
* @param newClaim The claim to be created.
91+
* @param observers Additional observers of the transaction.
92+
* @return Returns a flow process handle.
93+
*/
94+
fun <T : Any> amendClaim(
95+
oldClaim: StateAndRef<CordaClaim<T>>,
96+
newClaim: CordaClaim<T>,
97+
observers: Set<Party> = emptySet()
98+
): FlowProgressHandle<SignedTransaction> {
99+
return rpc.startTrackedFlow(AmendClaimFlow::Initiator, oldClaim, newClaim, observers)
69100
}
70101

71102
/**
@@ -75,18 +106,14 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
75106
* @param claim The claim to be consumed.
76107
* @param value The amended value of the claim.
77108
* @param observers Additional observers of the transaction.
109+
* @return Returns a flow process handle.
78110
*/
79111
fun <T : Any> amendClaim(
80112
claim: StateAndRef<CordaClaim<T>>,
81113
value: T,
82114
observers: Set<Party> = emptySet()
83115
): FlowProgressHandle<SignedTransaction> {
84-
return rpc.startTrackedFlow(
85-
AmendClaimFlow::Initiator,
86-
claim,
87-
claim.amend(value),
88-
observers
89-
)
116+
return amendClaim(claim, claim.amend(value), observers)
90117
}
91118

92119
/**
@@ -95,16 +122,13 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
95122
* @param T The underlying claim value type.
96123
* @param claim The claim to be consumed.
97124
* @param observers Additional observers of the transaction.
125+
* @return Returns a flow process handle.
98126
*/
99127
fun <T : Any> revokeClaim(
100128
claim: StateAndRef<CordaClaim<T>>,
101129
observers: Set<Party> = emptySet()
102130
): FlowProgressHandle<SignedTransaction> {
103-
return rpc.startTrackedFlow(
104-
RevokeClaimFlow::Initiator,
105-
claim,
106-
observers
107-
)
131+
return rpc.startTrackedFlow(RevokeClaimFlow::Initiator, claim, observers)
108132
}
109133

110134
/**
@@ -113,15 +137,12 @@ class ClaimCommandService(rpc: CordaRPCOps) : RPCService(rpc) {
113137
* @param T The underlying claim value type.
114138
* @param claim The claim to be published.
115139
* @param observers Additional observers of the transaction.
140+
* @return Returns a flow process handle.
116141
*/
117142
fun <T : Any> publishClaim(
118143
claim: StateAndRef<CordaClaim<T>>,
119144
observers: Set<Party>
120145
): FlowProgressHandle<SignedTransaction> {
121-
return rpc.startTrackedFlow(
122-
PublishClaimFlow::Initiator,
123-
claim,
124-
observers
125-
)
146+
return rpc.startTrackedFlow(PublishClaimFlow::Initiator, claim, observers)
126147
}
127148
}

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)