Skip to content

Commit 0e7fd94

Browse files
Merge branch 'main' into release
2 parents 6c500fb + f2104d5 commit 0e7fd94

File tree

138 files changed

+4767
-811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4767
-811
lines changed

.github/workflows/gradle-build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3+
4+
name: Java CI with Gradle
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
pull_request:
11+
branches:
12+
- '**'
13+
14+
jobs:
15+
build:
16+
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up JDK 8
22+
uses: actions/setup-java@v2
23+
with:
24+
java-version: '8'
25+
distribution: 'adopt'
26+
cache: gradle
27+
- name: Grant execute permission for gradlew
28+
run: chmod +x gradlew
29+
- name: Build with Gradle
30+
env:
31+
GHA_USERNAME: ${{ secrets.GHA_USERNAME }}
32+
GHA_TOKEN: ${{ secrets.GHA_TOKEN }}
33+
run: ./gradlew build

.idea/runConfigurations/Run_General_Contract_Tests.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55

66
corda_artifactory_url = 'https://software.r3.com/artifactory'
77
corda_group = 'net.corda'
8-
corda_release_version = '4.6'
8+
corda_release_version = '4.8'
99

1010
corda_gradle_plugin_group = 'net.corda.plugins'
1111
corda_gradle_plugin_version = '5.0.4'
@@ -14,9 +14,9 @@ buildscript {
1414
junit_version = '5.3.1'
1515

1616
onixlabs_group = 'io.onixlabs'
17-
onixlabs_corda_core_release_version = '2.0.0'
17+
onixlabs_corda_core_release_version = '3.0.0'
1818

19-
cordapp_platform_version = 8
19+
cordapp_platform_version = 10
2020
cordapp_contract_name = 'ONIXLabs Corda Identity Framework Contract'
2121
cordapp_workflow_name = 'ONIXLabs Corda Identity Framework Workflow'
2222
cordapp_vendor_name = 'ONIXLabs'
@@ -43,8 +43,8 @@ buildscript {
4343
}
4444
}
4545

46-
group 'io.onixlabs'
47-
version '2.0.0'
46+
group getProperty('group')
47+
version getProperty('version')
4848

4949
subprojects {
5050
repositories {
@@ -58,8 +58,8 @@ subprojects {
5858
name = "GitHubPackages-onixlabs-corda-core"
5959
url = uri("https://maven.pkg.github.com/onix-labs/onixlabs-corda-core")
6060
credentials {
61-
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
62-
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
61+
username = project.findProperty("gpr.user") ?: System.getenv("GHA_USERNAME")
62+
password = project.findProperty("gpr.key") ?: System.getenv("GHA_TOKEN")
6363
}
6464
}
6565
}
@@ -84,6 +84,11 @@ subprojects {
8484
}
8585
}
8686

87+
task sourceJar(type: Jar) {
88+
from sourceSets.main.allSource
89+
archiveClassifier = "sources"
90+
}
91+
8792
jar { exclude '**/log4j2*.xml' }
8893

8994
test {

gradle.properties

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name=onixlabs-corda-identity-framework
22
group=io.onixlabs
3-
version=2.0.0
4-
5-
kotlin.incremental=false
6-
kotlin.code.style=official
7-
3+
version=3.0.0
84
onixlabs.development.jarsign.keystore=../lib/onixlabs.development.pkcs12
95
onixlabs.development.jarsign.password=5891f47942424d2acbe108691fdb5ba258712fca7e4762be4327241ebf3dbfa3

onixlabs-corda-identity-framework-contract/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ publishing {
4343
name = "GitHubPackages"
4444
url = uri("https://maven.pkg.github.com/onix-labs/onixlabs-corda-identity-framework")
4545
credentials {
46-
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
47-
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
46+
username = project.findProperty("gpr.user") ?: System.getenv("GHA_USERNAME")
47+
password = project.findProperty("gpr.key") ?: System.getenv("GHA_TOKEN")
4848
}
4949
}
5050
}
@@ -53,6 +53,7 @@ publishing {
5353
groupId = project.parent.group
5454
version = project.parent.version
5555
artifactId = 'onixlabs-corda-identity-framework-contract'
56+
artifact sourceJar
5657
from components.java
5758
}
5859
}

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/Extensions.AbstractClaim.kt

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616

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

19+
import io.onixlabs.corda.core.toTypedClass
20+
import io.onixlabs.corda.identityframework.contract.claims.AbstractClaim
21+
import io.onixlabs.corda.identityframework.contract.claims.ClaimTypeInfo
22+
23+
private typealias Claims = Iterable<AbstractClaim<*>>
24+
1925
/**
2026
* Determines whether a collection of [AbstractClaim] contains duplicate properties.
2127
*
2228
* @param property The property to search for duplicates.
2329
* @param ignoreCase Determines whether to ignore case when searching for duplicates.
2430
* @return Returns true if the collection contains duplicates; otherwise, false.
2531
*/
26-
fun Iterable<AbstractClaim<*>>.containsDuplicateProperties(
27-
property: String? = null,
28-
ignoreCase: Boolean = false
29-
): Boolean {
32+
fun Claims.containsDuplicateProperties(property: String? = null, ignoreCase: Boolean = false): Boolean {
3033
val properties = map { if (ignoreCase) it.property.toLowerCase() else it.property }
3134
val filteredProperties = properties.filter { property?.equals(it, ignoreCase) ?: true }
3235
return filteredProperties.size != filteredProperties.distinct().size
@@ -40,8 +43,92 @@ fun Iterable<AbstractClaim<*>>.containsDuplicateProperties(
4043
* @param message The exception message to throw if the collection contains duplicate keys.
4144
* @throws IllegalStateException if the collection contains duplicate keys.
4245
*/
43-
fun Iterable<AbstractClaim<*>>.checkForDuplicateProperties(
46+
fun Claims.checkForDuplicateProperties(
4447
property: String? = null,
4548
ignoreCase: Boolean = false,
4649
message: String = "The claim collection contains duplicate keys."
4750
) = check(!containsDuplicateProperties(property, ignoreCase)) { message }
51+
52+
/**
53+
* Casts an [AbstractClaim] to the specified type.
54+
*
55+
* @param T The underlying [AbstractClaim] type to cast to.
56+
* @param type The [AbstractClaim] type to cast to.
57+
* @return Returns an instance of [T] cast from this [AbstractClaim].
58+
* @throws ClassCastException if this instance cannot be cast to the specified type [T].
59+
*/
60+
fun <T : AbstractClaim<*>> AbstractClaim<*>.cast(type: Class<T>): T {
61+
return type.cast(this)
62+
}
63+
64+
/**
65+
* Casts an [AbstractClaim] to the specified type.
66+
*
67+
* @param T The underlying [AbstractClaim] type to cast to.
68+
* @return Returns an instance of [T] cast from this [AbstractClaim].
69+
* @throws ClassCastException if this instance cannot be cast to the specified type [T].
70+
*/
71+
inline fun <reified T : AbstractClaim<*>> AbstractClaim<*>.cast(): T {
72+
return cast(T::class.java)
73+
}
74+
75+
/**
76+
* Casts an [Iterable] of [AbstractClaim] to the specified type.
77+
*
78+
* @param T The underlying [AbstractClaim] type to cast to.
79+
* @param type The [AbstractClaim] type to cast to.
80+
* @return Returns an [Iterable] of [T] cast from this [Iterable] of [AbstractClaim].
81+
* @throws ClassCastException if any instance cannot be cast to the specified type [T].
82+
*/
83+
fun <T : AbstractClaim<*>> Claims.cast(type: Class<T>): List<T> {
84+
return map { it.cast(type) }
85+
}
86+
87+
/**
88+
* Casts an [Iterable] of [AbstractClaim] to the specified type.
89+
*
90+
* @param T The underlying [AbstractClaim] type to cast to.
91+
* @return Returns an [Iterable] of [T] cast from this [Iterable] of [AbstractClaim].
92+
* @throws ClassCastException if any instance cannot be cast to the specified type [T].
93+
*/
94+
inline fun <reified T : AbstractClaim<*>> Claims.cast(): List<T> {
95+
return cast(T::class.java)
96+
}
97+
98+
/**
99+
* Filters an [Iterable] of [AbstractClaim] by the specified claim type, and optionally by the value type.
100+
*
101+
* @param T The underlying claim value type.
102+
* @param U The underlying claim type.
103+
* @param claimType The claim type to filter by.
104+
* @param valueType The claim value type to filter by.
105+
* @return Returns a [List] of [U] specified by the claim type, and optionally by the value type.
106+
*/
107+
fun <T, U : AbstractClaim<in T>> Claims.filterByType(claimType: Class<U>, valueType: Class<in T>? = null): List<U> {
108+
return filter { it.javaClass == claimType }
109+
.filterIsInstance(claimType)
110+
.filter { claim -> valueType?.let { claim.value?.javaClass == it } ?: true }
111+
}
112+
113+
/**
114+
* Filters an [Iterable] of [AbstractClaim] by the specified claim type.
115+
*
116+
* @param T The underlying claim type.
117+
* @return Returns a [List] of [T] specified by the claim type.
118+
*/
119+
inline fun <reified T : AbstractClaim<*>> Claims.filterByType(): List<T> {
120+
val claimTypeInfo = object : ClaimTypeInfo<T>() {}
121+
return filterByType(claimTypeInfo.claimType.toTypedClass(), claimTypeInfo.claimValueType)
122+
}
123+
124+
/**
125+
* Filters an [Iterable] of [AbstractClaim] by the specified property.
126+
*
127+
* @param T The underlying claim type.
128+
* @param property The property to filter by.
129+
* @param ignoreCase Determines whether to ignore the property case when filtering.
130+
* @return Returns an [Iterable] of [AbstractClaim] by the specified property.
131+
*/
132+
fun <T : AbstractClaim<*>> Iterable<T>.filterByProperty(property: String, ignoreCase: Boolean = false): List<T> {
133+
return filter { it.property.equals(property, ignoreCase) }
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.contract
18+
19+
import io.onixlabs.corda.identityframework.contract.accounts.Account
20+
import io.onixlabs.corda.identityframework.contract.accounts.AccountParty
21+
import net.corda.core.contracts.UniqueIdentifier
22+
import net.corda.core.identity.AbstractParty
23+
24+
/**
25+
* Gets the account linear ID from an [AccountParty], or null of this [AbstractParty] is not an [AccountParty].
26+
*/
27+
val AbstractParty.accountLinearId: UniqueIdentifier?
28+
get() = if (this is AccountParty) accountLinearId else null
29+
30+
/**
31+
* Gets the account type from an [AccountParty], or null of this [AbstractParty] is not an [AccountParty].
32+
*/
33+
val AbstractParty.accountType: Class<out Account>?
34+
get() = if (this is AccountParty) accountType else null

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/Extensions.Attestation.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

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

19+
import io.onixlabs.corda.identityframework.contract.attestations.Attestation
20+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationPointer
21+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
1922
import net.corda.core.contracts.ContractState
2023
import net.corda.core.contracts.LinearState
2124
import net.corda.core.contracts.StateAndRef

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/Extensions.CordaClaim.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

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

19+
import io.onixlabs.corda.identityframework.contract.claims.CordaClaim
20+
import io.onixlabs.corda.identityframework.contract.claims.LinearClaimPointer
21+
import io.onixlabs.corda.identityframework.contract.claims.StaticClaimPointer
1922
import net.corda.core.contracts.StateAndRef
2023

2124
/**
@@ -26,14 +29,25 @@ import net.corda.core.contracts.StateAndRef
2629
* @param value The amended claim value.
2730
* @return Returns an amended claim.
2831
* @throws IllegalStateException if the amend function of the specified state type cannot be cast to [U].
29-
*
32+
*
3033
* Note that this function tends to fail if you don't override the amend function of custom claim types.
3134
*/
32-
inline fun <T : Any, reified U : CordaClaim<T>> StateAndRef<U>.amend(value: T): U = try {
33-
U::class.java.cast(state.data.amend(ref, value))
34-
} catch (ex: ClassCastException) {
35-
val message = "${ex.message}. Did you forget to override ${U::class.java.simpleName}.amend?"
36-
throw IllegalStateException(message, ex)
35+
inline fun <T : Any, reified U : CordaClaim<T>> StateAndRef<U>.amend(value: T): U {
36+
val amendedClaim = state.data.amend(ref, value)
37+
38+
return try {
39+
U::class.java.cast(amendedClaim)
40+
} catch (classCastException: ClassCastException) {
41+
val baseTypeName = CordaClaim::class.java.canonicalName
42+
val derivedTypeName = U::class.java.canonicalName
43+
val returnTypeName = amendedClaim.javaClass.canonicalName
44+
45+
throw IllegalStateException(buildString {
46+
append("${classCastException.message}. ")
47+
append("This typically occurs if a derived type of '$baseTypeName' does not override 'amend'. ")
48+
append("The 'amend' function of '$derivedTypeName' appears to return '$returnTypeName' instead of '$derivedTypeName'.")
49+
}, classCastException)
50+
}
3751
}
3852

3953
/**

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/Extensions.StateAndRef.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

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

19+
import io.onixlabs.corda.identityframework.contract.attestations.Attestation
20+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
21+
import io.onixlabs.corda.identityframework.contract.attestations.LinearAttestationPointer
22+
import io.onixlabs.corda.identityframework.contract.attestations.StaticAttestationPointer
1923
import net.corda.core.contracts.ContractState
2024
import net.corda.core.contracts.LinearState
2125
import net.corda.core.contracts.StateAndRef

0 commit comments

Comments
 (0)