Skip to content

Commit 18d956d

Browse files
Split TransactionBuilder extensions into separate files for maintainability.
1 parent 009a549 commit 18d956d

File tree

5 files changed

+192
-140
lines changed

5 files changed

+192
-140
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import io.onixlabs.corda.identityframework.contract.accounts.Account
20+
import io.onixlabs.corda.identityframework.contract.accounts.AccountContract
21+
import net.corda.core.contracts.StateAndRef
22+
23+
/**
24+
* Adds an account for issuance to a transaction builder, including the required command.
25+
*
26+
* @param state The account state to be created in the transaction.
27+
* @return Returns the current transaction builder.
28+
*/
29+
fun Builder.addIssuedAccount(state: Account): Builder = apply {
30+
addOutputState(state)
31+
addCommand(AccountContract.Issue, state.owner.owningKey)
32+
}
33+
34+
/**
35+
* Adds an account for amendment to a transaction builder, including the required command.
36+
*
37+
* @param oldState The old account state to be consumed in the transaction.
38+
* @param newState The new account state to be created in the transaction.
39+
* @return Returns the current transaction builder.
40+
*/
41+
fun Builder.addAmendedAccount(oldState: StateAndRef<Account>, newState: Account): Builder = apply {
42+
addInputState(oldState)
43+
addOutputState(newState)
44+
addCommand(AccountContract.Amend, newState.owner.owningKey)
45+
}
46+
47+
/**
48+
* Adds an account for revocation to a transaction builder, including the required command.
49+
*
50+
* @param state The account state to be consumed in the transaction.
51+
* @return Returns the current transaction builder.
52+
*/
53+
fun Builder.addRevokedAccount(state: StateAndRef<Account>): Builder = apply {
54+
addInputState(state)
55+
addCommand(AccountContract.Revoke, state.state.data.owner.owningKey)
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import io.onixlabs.corda.identityframework.contract.attestations.Attestation
20+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationContract
21+
import net.corda.core.contracts.StateAndRef
22+
23+
/**
24+
* Adds an attestation for issuance to a transaction builder, including the required command.
25+
*
26+
* @param state The attestation state to be created in the transaction.
27+
* @return Returns the current transaction builder.
28+
*/
29+
fun Builder.addIssuedAttestation(state: Attestation<*>): Builder = apply {
30+
addOutputState(state)
31+
addCommand(AttestationContract.Issue, state.attestor.owningKey)
32+
}
33+
34+
/**
35+
* Adds an attestation for amendment to a transaction builder, including the required command.
36+
*
37+
* @param oldState The old attestation state to be consumed in the transaction.
38+
* @param newState The new attestation state to be created in the transaction.
39+
* @return Returns the current transaction builder.
40+
*/
41+
fun Builder.addAmendedAttestation(oldState: StateAndRef<Attestation<*>>, newState: Attestation<*>): Builder = apply {
42+
addInputState(oldState)
43+
addOutputState(newState)
44+
addCommand(AttestationContract.Amend, newState.attestor.owningKey)
45+
}
46+
47+
/**
48+
* Adds an attestation for revocation to a transaction builder, including the required command.
49+
*
50+
* @param state The attestation state to be consumed in the transaction.
51+
* @return Returns the current transaction builder.
52+
*/
53+
fun Builder.addRevokedAttestation(state: StateAndRef<Attestation<*>>): Builder = apply {
54+
addInputState(state)
55+
addCommand(AttestationContract.Revoke, state.state.data.attestor.owningKey)
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import io.onixlabs.corda.identityframework.contract.claims.CordaClaim
20+
import io.onixlabs.corda.identityframework.contract.claims.CordaClaimContract
21+
import net.corda.core.contracts.StateAndRef
22+
23+
/**
24+
* Adds a claim for issuance to a transaction builder, including the required command.
25+
*
26+
* @param state The claim state to be created in the transaction.
27+
* @return Returns the current transaction builder.
28+
*/
29+
fun Builder.addIssuedClaim(state: CordaClaim<*>): Builder = apply {
30+
addOutputState(state)
31+
addCommand(CordaClaimContract.Issue, state.issuer.owningKey)
32+
}
33+
34+
/**
35+
* Adds a claim for amendment to a transaction builder, including the required command.
36+
*
37+
* @param oldState The old claim state to be consumed in the transaction.
38+
* @param newState The new claim state to be created in the transaction.
39+
* @return Returns the current transaction builder.
40+
*/
41+
fun Builder.addAmendedClaim(oldState: StateAndRef<CordaClaim<*>>, newState: CordaClaim<*>): Builder = apply {
42+
addInputState(oldState)
43+
addOutputState(newState)
44+
addCommand(CordaClaimContract.Amend, newState.issuer.owningKey)
45+
}
46+
47+
/**
48+
* Adds a claim for revocation to a transaction builder, including the required command.
49+
*
50+
* @param state The claim state to be consumed in the transaction.
51+
* @return Returns the current transaction builder.
52+
*/
53+
fun Builder.addRevokedClaim(state: StateAndRef<CordaClaim<*>>): Builder = apply {
54+
addInputState(state)
55+
addCommand(CordaClaimContract.Revoke, state.state.data.issuer.owningKey)
56+
}

onixlabs-corda-identity-framework-workflow/src/main/kotlin/io/onixlabs/corda/identityframework/workflow/Extensions.TransactionBuilder.kt

Lines changed: 0 additions & 140 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import net.corda.core.transactions.TransactionBuilder
20+
21+
/**
22+
* Only exists so I can fit method signatures on a single line.
23+
*/
24+
internal typealias Builder = TransactionBuilder

0 commit comments

Comments
 (0)