Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMatthewLayton committed Oct 25, 2021
2 parents 6c500fb + f2104d5 commit 0e7fd94
Show file tree
Hide file tree
Showing 138 changed files with 4,767 additions and 811 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
env:
GHA_USERNAME: ${{ secrets.GHA_USERNAME }}
GHA_TOKEN: ${{ secrets.GHA_TOKEN }}
run: ./gradlew build
15 changes: 15 additions & 0 deletions .idea/runConfigurations/Run_General_Contract_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {

corda_artifactory_url = 'https://software.r3.com/artifactory'
corda_group = 'net.corda'
corda_release_version = '4.6'
corda_release_version = '4.8'

corda_gradle_plugin_group = 'net.corda.plugins'
corda_gradle_plugin_version = '5.0.4'
Expand All @@ -14,9 +14,9 @@ buildscript {
junit_version = '5.3.1'

onixlabs_group = 'io.onixlabs'
onixlabs_corda_core_release_version = '2.0.0'
onixlabs_corda_core_release_version = '3.0.0'

cordapp_platform_version = 8
cordapp_platform_version = 10
cordapp_contract_name = 'ONIXLabs Corda Identity Framework Contract'
cordapp_workflow_name = 'ONIXLabs Corda Identity Framework Workflow'
cordapp_vendor_name = 'ONIXLabs'
Expand All @@ -43,8 +43,8 @@ buildscript {
}
}

group 'io.onixlabs'
version '2.0.0'
group getProperty('group')
version getProperty('version')

subprojects {
repositories {
Expand All @@ -58,8 +58,8 @@ subprojects {
name = "GitHubPackages-onixlabs-corda-core"
url = uri("https://maven.pkg.github.com/onix-labs/onixlabs-corda-core")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
username = project.findProperty("gpr.user") ?: System.getenv("GHA_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GHA_TOKEN")
}
}
}
Expand All @@ -84,6 +84,11 @@ subprojects {
}
}

task sourceJar(type: Jar) {
from sourceSets.main.allSource
archiveClassifier = "sources"
}

jar { exclude '**/log4j2*.xml' }

test {
Expand Down
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name=onixlabs-corda-identity-framework
group=io.onixlabs
version=2.0.0

kotlin.incremental=false
kotlin.code.style=official

version=3.0.0
onixlabs.development.jarsign.keystore=../lib/onixlabs.development.pkcs12
onixlabs.development.jarsign.password=5891f47942424d2acbe108691fdb5ba258712fca7e4762be4327241ebf3dbfa3
5 changes: 3 additions & 2 deletions onixlabs-corda-identity-framework-contract/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ publishing {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/onix-labs/onixlabs-corda-identity-framework")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
username = project.findProperty("gpr.user") ?: System.getenv("GHA_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GHA_TOKEN")
}
}
}
Expand All @@ -53,6 +53,7 @@ publishing {
groupId = project.parent.group
version = project.parent.version
artifactId = 'onixlabs-corda-identity-framework-contract'
artifact sourceJar
from components.java
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@

package io.onixlabs.corda.identityframework.contract

import io.onixlabs.corda.core.toTypedClass
import io.onixlabs.corda.identityframework.contract.claims.AbstractClaim
import io.onixlabs.corda.identityframework.contract.claims.ClaimTypeInfo

private typealias Claims = Iterable<AbstractClaim<*>>

/**
* Determines whether a collection of [AbstractClaim] contains duplicate properties.
*
* @param property The property to search for duplicates.
* @param ignoreCase Determines whether to ignore case when searching for duplicates.
* @return Returns true if the collection contains duplicates; otherwise, false.
*/
fun Iterable<AbstractClaim<*>>.containsDuplicateProperties(
property: String? = null,
ignoreCase: Boolean = false
): Boolean {
fun Claims.containsDuplicateProperties(property: String? = null, ignoreCase: Boolean = false): Boolean {
val properties = map { if (ignoreCase) it.property.toLowerCase() else it.property }
val filteredProperties = properties.filter { property?.equals(it, ignoreCase) ?: true }
return filteredProperties.size != filteredProperties.distinct().size
Expand All @@ -40,8 +43,92 @@ fun Iterable<AbstractClaim<*>>.containsDuplicateProperties(
* @param message The exception message to throw if the collection contains duplicate keys.
* @throws IllegalStateException if the collection contains duplicate keys.
*/
fun Iterable<AbstractClaim<*>>.checkForDuplicateProperties(
fun Claims.checkForDuplicateProperties(
property: String? = null,
ignoreCase: Boolean = false,
message: String = "The claim collection contains duplicate keys."
) = check(!containsDuplicateProperties(property, ignoreCase)) { message }

/**
* Casts an [AbstractClaim] to the specified type.
*
* @param T The underlying [AbstractClaim] type to cast to.
* @param type The [AbstractClaim] type to cast to.
* @return Returns an instance of [T] cast from this [AbstractClaim].
* @throws ClassCastException if this instance cannot be cast to the specified type [T].
*/
fun <T : AbstractClaim<*>> AbstractClaim<*>.cast(type: Class<T>): T {
return type.cast(this)
}

/**
* Casts an [AbstractClaim] to the specified type.
*
* @param T The underlying [AbstractClaim] type to cast to.
* @return Returns an instance of [T] cast from this [AbstractClaim].
* @throws ClassCastException if this instance cannot be cast to the specified type [T].
*/
inline fun <reified T : AbstractClaim<*>> AbstractClaim<*>.cast(): T {
return cast(T::class.java)
}

/**
* Casts an [Iterable] of [AbstractClaim] to the specified type.
*
* @param T The underlying [AbstractClaim] type to cast to.
* @param type The [AbstractClaim] type to cast to.
* @return Returns an [Iterable] of [T] cast from this [Iterable] of [AbstractClaim].
* @throws ClassCastException if any instance cannot be cast to the specified type [T].
*/
fun <T : AbstractClaim<*>> Claims.cast(type: Class<T>): List<T> {
return map { it.cast(type) }
}

/**
* Casts an [Iterable] of [AbstractClaim] to the specified type.
*
* @param T The underlying [AbstractClaim] type to cast to.
* @return Returns an [Iterable] of [T] cast from this [Iterable] of [AbstractClaim].
* @throws ClassCastException if any instance cannot be cast to the specified type [T].
*/
inline fun <reified T : AbstractClaim<*>> Claims.cast(): List<T> {
return cast(T::class.java)
}

/**
* Filters an [Iterable] of [AbstractClaim] by the specified claim type, and optionally by the value type.
*
* @param T The underlying claim value type.
* @param U The underlying claim type.
* @param claimType The claim type to filter by.
* @param valueType The claim value type to filter by.
* @return Returns a [List] of [U] specified by the claim type, and optionally by the value type.
*/
fun <T, U : AbstractClaim<in T>> Claims.filterByType(claimType: Class<U>, valueType: Class<in T>? = null): List<U> {
return filter { it.javaClass == claimType }
.filterIsInstance(claimType)
.filter { claim -> valueType?.let { claim.value?.javaClass == it } ?: true }
}

/**
* Filters an [Iterable] of [AbstractClaim] by the specified claim type.
*
* @param T The underlying claim type.
* @return Returns a [List] of [T] specified by the claim type.
*/
inline fun <reified T : AbstractClaim<*>> Claims.filterByType(): List<T> {
val claimTypeInfo = object : ClaimTypeInfo<T>() {}
return filterByType(claimTypeInfo.claimType.toTypedClass(), claimTypeInfo.claimValueType)
}

/**
* Filters an [Iterable] of [AbstractClaim] by the specified property.
*
* @param T The underlying claim type.
* @param property The property to filter by.
* @param ignoreCase Determines whether to ignore the property case when filtering.
* @return Returns an [Iterable] of [AbstractClaim] by the specified property.
*/
fun <T : AbstractClaim<*>> Iterable<T>.filterByProperty(property: String, ignoreCase: Boolean = false): List<T> {
return filter { it.property.equals(property, ignoreCase) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2020-2021 ONIXLabs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.onixlabs.corda.identityframework.contract

import io.onixlabs.corda.identityframework.contract.accounts.Account
import io.onixlabs.corda.identityframework.contract.accounts.AccountParty
import net.corda.core.contracts.UniqueIdentifier
import net.corda.core.identity.AbstractParty

/**
* Gets the account linear ID from an [AccountParty], or null of this [AbstractParty] is not an [AccountParty].
*/
val AbstractParty.accountLinearId: UniqueIdentifier?
get() = if (this is AccountParty) accountLinearId else null

/**
* Gets the account type from an [AccountParty], or null of this [AbstractParty] is not an [AccountParty].
*/
val AbstractParty.accountType: Class<out Account>?
get() = if (this is AccountParty) accountType else null
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.onixlabs.corda.identityframework.contract

import io.onixlabs.corda.identityframework.contract.attestations.Attestation
import io.onixlabs.corda.identityframework.contract.attestations.AttestationPointer
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.LinearState
import net.corda.core.contracts.StateAndRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.onixlabs.corda.identityframework.contract

import io.onixlabs.corda.identityframework.contract.claims.CordaClaim
import io.onixlabs.corda.identityframework.contract.claims.LinearClaimPointer
import io.onixlabs.corda.identityframework.contract.claims.StaticClaimPointer
import net.corda.core.contracts.StateAndRef

/**
Expand All @@ -26,14 +29,25 @@ import net.corda.core.contracts.StateAndRef
* @param value The amended claim value.
* @return Returns an amended claim.
* @throws IllegalStateException if the amend function of the specified state type cannot be cast to [U].
*
*
* Note that this function tends to fail if you don't override the amend function of custom claim types.
*/
inline fun <T : Any, reified U : CordaClaim<T>> StateAndRef<U>.amend(value: T): U = try {
U::class.java.cast(state.data.amend(ref, value))
} catch (ex: ClassCastException) {
val message = "${ex.message}. Did you forget to override ${U::class.java.simpleName}.amend?"
throw IllegalStateException(message, ex)
inline fun <T : Any, reified U : CordaClaim<T>> StateAndRef<U>.amend(value: T): U {
val amendedClaim = state.data.amend(ref, value)

return try {
U::class.java.cast(amendedClaim)
} catch (classCastException: ClassCastException) {
val baseTypeName = CordaClaim::class.java.canonicalName
val derivedTypeName = U::class.java.canonicalName
val returnTypeName = amendedClaim.javaClass.canonicalName

throw IllegalStateException(buildString {
append("${classCastException.message}. ")
append("This typically occurs if a derived type of '$baseTypeName' does not override 'amend'. ")
append("The 'amend' function of '$derivedTypeName' appears to return '$returnTypeName' instead of '$derivedTypeName'.")
}, classCastException)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package io.onixlabs.corda.identityframework.contract

import io.onixlabs.corda.identityframework.contract.attestations.Attestation
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
import io.onixlabs.corda.identityframework.contract.attestations.LinearAttestationPointer
import io.onixlabs.corda.identityframework.contract.attestations.StaticAttestationPointer
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.LinearState
import net.corda.core.contracts.StateAndRef
Expand Down
Loading

0 comments on commit 0e7fd94

Please sign in to comment.