Skip to content

Commit

Permalink
Reference state sample (#7)
Browse files Browse the repository at this point in the history
Reference State Sample
  • Loading branch information
ashutoshmeher-r3 authored Jul 10, 2023
1 parent 8a1393e commit 9ce08d0
Show file tree
Hide file tree
Showing 35 changed files with 2,019 additions and 0 deletions.
10 changes: 10 additions & 0 deletions java-samples/referencestates-sanctionsbody/.ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@Library('[email protected]') _

cordaPipeline(
nexusAppId: 'com.corda.CSDE-Java.5.0',
publishRepoPrefix: '',
slimBuild: true,
runUnitTests: false,
dedicatedJobForSnykDelta: false,
slackChannel: '#corda-corda5-dev-ex-build-notifications'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library('[email protected]') _

cordaSnykScanPipeline (
snykTokenId: 'r3-snyk-corda5',
snykAdditionalCommands: "--all-sub-projects -d"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Check PR Title'
on:
pull_request:
types: [opened, edited, reopened]

jobs:
check-pr-title:
runs-on: ubuntu-latest
steps:
- uses: morrisoncole/[email protected]
with:
title-regex: '^((CORDA|EG|ENT|INFRA|CORE|ES)-\d+)(.*)'
on-failed-regex-comment: "PR title failed to match regex -> `%regex%`"
repo-token: "${{ secrets.GITHUB_TOKEN }}"
91 changes: 91 additions & 0 deletions java-samples/referencestates-sanctionsbody/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

# Eclipse, ctags, Mac metadata, log files
.classpath
.project
.settings
tags
.DS_Store
*.log
*.orig

# Created by .ignore support plugin (hsz.mobi)

.gradle
local.properties
.gradletasknamecache

# General build files
**/build/*

lib/quasar.jar

**/logs/*

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/*.xml
.idea/.name
.idea/copyright
.idea/inspectionProfiles
.idea/libraries
.idea/shelf
.idea/dataSources
.idea/markdown-navigator
.idea/runConfigurations
.idea/dictionaries


# Include the -parameters compiler option by default in IntelliJ required for serialization.
!.idea/codeStyleSettings.xml


## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
**/out/
/classes/



# vim
*.swp
*.swn
*.swo



# Directory generated during Resolve and TestOSGi gradle tasks
bnd/

# Ignore Gradle build output directory
build
/.idea/codeStyles/codeStyleConfig.xml
/.idea/codeStyles/Project.xml



# Ignore Visual studio directory
bin/



*.cpi
*.cpb
*.cpk
workspace/**
#CordaPID.dat
#*.pem
#*.pfx
#CPIFileStatus*.json
#GroupPolicy.json

# Ignore temporary data files
*.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="DebugCorDapp" type="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<option name="AUTO_RESTART" value="false" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="5005" />
<option name="LOCAL" value="false" />
</RunnerSettings>
<method v="2" />
</configuration>
</component>
22 changes: 22 additions & 0 deletions java-samples/referencestates-sanctionsbody/.snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.25.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JAVA-ORGJETBRAINSKOTLIN-2393744:
- '*':
reason: >-
This vulnerability relates to information exposure via creation of
temporary files (via Kotlin functions) with insecure permissions.
Corda does not use any of the vulnerable functions so it is not
susceptible to this vulnerability
expires: 2023-06-19T17:15:26.836Z
created: 2023-02-02T17:15:26.839Z
SNYK-JAVA-ORGJETBRAINSKOTLIN-2628385:
- '*':
reason: >-
corda-simulator-runtime is a testRuntimeOnly dependency, as such this
dependency will not be included in any cordaApp produced by the CSDE
project Template
expires: 2023-06-19T17:16:00.009Z
created: 2023-02-02T17:16:00.016Z
patch: {}
97 changes: 97 additions & 0 deletions java-samples/referencestates-sanctionsbody/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Sanctionbody -- ReferenceState

This CorDapp demonstrates the use of reference states in a transaction and in the verification method of a contract.

## Concepts
This CorDapp allows two nodes to enter into an IOU agreement, but enforces that both parties belong to a list of sanctioned entities. This list of sanctioned entities is taken from a referenced SanctionedEntities state.

## Usage


### Setting up

1. We will begin our test deployment with clicking the `startCorda`. This task will load up the combined Corda workers in docker.
A successful deployment will allow you to open the REST APIs at: https://localhost:8888/api/v1/swagger#. You can test out some
functions to check connectivity. (GET /cpi function call should return an empty list as for now.)
2. We will now deploy the cordapp with a click of `5-vNodeSetup` task. Upon successful deployment of the CPI, the GET /cpi function call should now return the meta data of the cpi you just upload



### Running the app

In Corda 5, flows will be triggered via `POST /flow/{holdingidentityshorthash}` and flow result will need to be view at `GET /flow/{holdingidentityshorthash}/{clientrequestid}`
* holdingidentityshorthash: the id of the network participants, ie SanctionBody, Bob, Charlie and DodgyParty. You can view all the short hashes of the network member with another gradle task called `ListVNodes`
* clientrequestid: the id you specify in the flow requestBody when you trigger a flow.


### Running the flows

Pick the SanctionBody VNode identity to issue the sanctions list
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(SanctionBody's hash) and request body:

{
"clientRequestId": "issue-sanction",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.IssueSanctionsListFlow",
"requestBody": {
}
}

Now that the sanctions list has been made, Next, we want to issue an IOU. Pick Bob VNode identity to issue the IOU.
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:

{
"clientRequestId": "issue-iou",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.IOUIssueFlow",
"requestBody": {
"iouValue": 100,
"otherParty": "CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB",
"sanctionsBody": "CN=SanctionsBody, OU=Test Dept, O=R3, L=London, C=GB"
}
}

We've seen how to successfully send an IOU to a non-sanctioned party, so what if we want to send one to a sanctioned party? First we need to update the sanction list.
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(SanctionBody's hash) and request body:

{
"clientRequestId": "update-sanction",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.UpdateSanctionListFlow",
"requestBody": {
"partyToSanction": "CN=DodgyParty, OU=Test Dept, O=R3, L=London, C=GB"
}
}


Now try an issue an IOU to DodgyParty. Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:

{
"clientRequestId": "issue-iou",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.IOUIssueFlow",
"requestBody": {
"iouValue": 100,
"otherParty": "CN=DodgyParty, OU=Test Dept, O=R3, L=London, C=GB",
"sanctionsBody": "CN=SanctionsBody, OU=Test Dept, O=R3, L=London, C=GB"
}
}

The flow will error with the message: The borrower O=DodgyParty, L=Moscow, C=RU is a sanctioned entity'!

You could use the GetIOUFlow and GetSanctionListFlow to query the vault and check the current unconsumed states
issued on the ledgers. Go to `POST /flow/{holdingidentityshorthash}`, enter the vnode's identity short hash and request body:

To Get IOU List:

{
"clientRequestId": "get-iou",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.GetIOUFlow",
"requestBody": {
}
}

To Get Sanction List:

{
"clientRequestId": "get-sanction",
"flowClassName": "com.r3.developers.samples.referencestate.workflows.GetSactionListFlow",
"requestBody": {
}
}
84 changes: 84 additions & 0 deletions java-samples/referencestates-sanctionsbody/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import static org.gradle.api.JavaVersion.VERSION_11

plugins {
id 'org.jetbrains.kotlin.jvm'
id 'net.corda.cordapp.cordapp-configuration'
id 'org.jetbrains.kotlin.plugin.jpa'
id 'java'
id 'maven-publish'
id 'net.corda.plugins.csde'
}

allprojects {
group 'com.r3.developers.csdetemplate'
version '1.0-SNAPSHOT'

def javaVersion = VERSION_11

// Configure the CSDE
csde {
cordaClusterURL = "https://localhost:8888"
networkConfigFile = "config/static-network-config.json"
r3RootCertFile = "config/r3-ca-key.pem"
corDappCpiName = "MyCorDapp"
notaryCpiName = "NotaryServer"
cordaRpcUser = "admin"
cordaRpcPasswd ="admin"
workflowsModuleName = workflowsModule
csdeWorkspaceDir = "workspace"
notaryVersion = cordaNotaryPluginsVersion
combinedWorkerVersion = combinedWorkerJarVersion
postgresJdbcVersion = "42.4.3"
cordaDbContainerName = "CSDEpostgresql"
cordaBinDir = "${System.getProperty("user.home")}/.corda/corda5"
cordaCliBinDir = "${System.getProperty("user.home")}/.corda/cli"
cpiUploadTimeout = cpiUploadDefault
}

// Declare the set of Java compiler options we need to build a CorDapp.
tasks.withType(JavaCompile) {
// -parameters - Needed for reflection and serialization to work correctly.
options.compilerArgs += [
"-parameters"
]
}

repositories {
// All dependencies are held in Maven Central
mavenLocal()
mavenCentral()

// R3 Internal repositories for dev
// Repository provides Corda 5 binaries that implement Corda-API.
// These will be made publicly available.
// Final location to be decided.
// Repository subject to change
maven {
url = "$artifactoryContextUrl/corda-os-maven"
authentication {
basic(BasicAuthentication)
}
credentials {
username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
}
}
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

}

publishing {
publications {
maven(MavenPublication) {
artifactId "corda-CSDE-java-sample"
groupId project.group
artifact jar
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB7zCCAZOgAwIBAgIEFyV7dzAMBggqhkjOPQQDAgUAMFsxCzAJBgNVBAYTAkdC
MQ8wDQYDVQQHDAZMb25kb24xDjAMBgNVBAoMBUNvcmRhMQswCQYDVQQLDAJSMzEe
MBwGA1UEAwwVQ29yZGEgRGV2IENvZGUgU2lnbmVyMB4XDTIwMDYyNTE4NTI1NFoX
DTMwMDYyMzE4NTI1NFowWzELMAkGA1UEBhMCR0IxDzANBgNVBAcTBkxvbmRvbjEO
MAwGA1UEChMFQ29yZGExCzAJBgNVBAsTAlIzMR4wHAYDVQQDExVDb3JkYSBEZXYg
Q29kZSBTaWduZXIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQDjSJtzQ+ldDFt
pHiqdSJebOGPZcvZbmC/PIJRsZZUF1bl3PfMqyG3EmAe0CeFAfLzPQtf2qTAnmJj
lGTkkQhxo0MwQTATBgNVHSUEDDAKBggrBgEFBQcDAzALBgNVHQ8EBAMCB4AwHQYD
VR0OBBYEFLMkL2nlYRLvgZZq7GIIqbe4df4pMAwGCCqGSM49BAMCBQADSAAwRQIh
ALB0ipx6EplT1fbUKqgc7rjH+pV1RQ4oKF+TkfjPdxnAAiArBdAI15uI70wf+xlL
zU+Rc5yMtcOY4/moZUq36r0Ilg==
-----END CERTIFICATE-----
Loading

0 comments on commit 9ce08d0

Please sign in to comment.