Skip to content

Commit

Permalink
Persistence Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshmeher-r3 committed Aug 17, 2023
1 parent b43b8a3 commit 7df0833
Show file tree
Hide file tree
Showing 34 changed files with 2,070 additions and 0 deletions.
91 changes: 91 additions & 0 deletions java-samples/persistence-carinsurance/.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
22 changes: 22 additions & 0 deletions java-samples/persistence-carinsurance/.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: {}
99 changes: 99 additions & 0 deletions java-samples/persistence-carinsurance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Car Insurance -- Persistence

This CorDapp demonstrates how Persistence works in Next Gen Corda.
Corda allows developers to have the ability to expose some or all parts of their states to a custom database table using an ORM tools. To support this feature the state must implement QueryableState.


## 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.persistence.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.persistence.workflows.IOUIssueFlow",
"requestBody": {
"iouValue": 100,
"lenderName": "CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB",
"sanctionAuthority": "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.persistence.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-1",
"flowClassName": "com.r3.developers.samples.persistence.workflows.IOUIssueFlow",
"requestBody": {
"iouValue": 100,
"lenderName": "CN=DodgyParty, OU=Test Dept, O=R3, L=London, C=GB",
"sanctionAuthority": "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.persistence.workflows.GetIOUFlow",
"requestBody": {
}
}

To Get Sanction List:

{
"clientRequestId": "get-sanction",
"flowClassName": "com.r3.developers.samples.persistence.workflows.GetSanctionListFlow",
"requestBody": {
}
}
68 changes: 68 additions & 0 deletions java-samples/persistence-carinsurance/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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"
}

// 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()

}

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

}

publishing {
publications {
maven(MavenPublication) {
artifactId "persistence-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-----
51 changes: 51 additions & 0 deletions java-samples/persistence-carinsurance/config/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %X - %msg%n"/>
</Console>

<RollingFile name="App"
fileName="logs/corda.log"
filePattern="logs/corda.%d{MM-dd-yyyy}.%i.log"
ignoreExceptions="false">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} %X - %msg%n"/>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="logs/">
<IfFileName glob="logs/corda.*.log">
<IfAny>
<IfAccumulatedFileSize exceeds="500 MB" />
<IfAccumulatedFileCount exceeds="10" />
</IfAny>
</IfFileName>
<IfLastModified age="7d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<logger name="Console">
<AppenderRef ref="Console" level="info"/>
</logger>

<!-- log warn only for these 3rd party libs -->
<Logger name="com.zaxxer.hikari" level="warn" />
<Logger name="io.javalin.Javalin" level="warn" />
<Logger name="org.apache.aries.spifly" level="warn" />
<Logger name="org.apache.kafka" level="warn" />
<Logger name="org.eclipse.jetty" level="warn" />
<Logger name="org.hibernate" level="warn" />

<!-- default to warn only for OSGi logging -->
<Logger name="net.corda.osgi.framework.OSGiFrameworkWrap" level="warn" />

<root level="debug">
<AppenderRef ref="App" level="info"/>
</root>
</Loggers>
</Configuration>
32 changes: 32 additions & 0 deletions java-samples/persistence-carinsurance/config/r3-ca-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFkDCCA3igAwIBAgIQBZsbV56OITLiOQe9p3d1XDANBgkqhkiG9w0BAQwFADBi
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSEwHwYDVQQDExhEaWdpQ2VydCBUcnVzdGVkIFJvb3Qg
RzQwHhcNMTMwODAxMTIwMDAwWhcNMzgwMTE1MTIwMDAwWjBiMQswCQYDVQQGEwJV
UzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQu
Y29tMSEwHwYDVQQDExhEaWdpQ2VydCBUcnVzdGVkIFJvb3QgRzQwggIiMA0GCSqG
SIb3DQEBAQUAA4ICDwAwggIKAoICAQC/5pBzaN675F1KPDAiMGkz7MKnJS7JIT3y
ithZwuEppz1Yq3aaza57G4QNxDAf8xukOBbrVsaXbR2rsnnyyhHS5F/WBTxSD1If
xp4VpX6+n6lXFllVcq9ok3DCsrp1mWpzMpTREEQQLt+C8weE5nQ7bXHiLQwb7iDV
ySAdYyktzuxeTsiT+CFhmzTrBcZe7FsavOvJz82sNEBfsXpm7nfISKhmV1efVFiO
DCu3T6cw2Vbuyntd463JT17lNecxy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