Skip to content

Commit

Permalink
CORDA-001: Intial Commit (corda#1)
Browse files Browse the repository at this point in the history
* initial commit

* Update README.md

* add kotlin obligation

* add code comments

* fix notary name

* add README

* Update CODEOWNERS
  • Loading branch information
peterli-r3 authored Mar 30, 2023
1 parent a1b53e1 commit 3059de8
Show file tree
Hide file tree
Showing 109 changed files with 6,442 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Jenkinsfile @corda/blt
.ci/* @corda/blt
.github/* @corda/blt
Jenkinsfile @corda/developer-relations
.ci/* @corda/developer-relations
.github/* @corda/developer-relations
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
.gradle/
.idea
**/build/
**/bin/
*/.gradle/
*/.idea/*
**/.vscode/*
**/out/
**/logs/
**/node_modules/
*~*
Binary file added Corda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# corda5-samples
C5 Samples
# Corda5-Samples Repository
<p align="center">
<img src="./Corda.png" alt="Corda" width="500">
</p>

## Introduction

Welcome to the Corda5 samples folder! This folder contains a collection of sample CorDapp that showcase the capabilities
and features of Corda, a distributed ledger technology (DLT) platform designed specifically for financial services.

These samples cover a wide range of scenarios, from simple token issuance and trade finance to more complex use cases such
as KYC (know your customer) and supply chain management. Each sample includes detailed documentation and instructions
for deployment, making it easy for developers to get started with Corda and experiment with its capabilities.

Whether you're a seasoned blockchain developer or just getting started with DLTs, the Corda samples folder is the
perfect place to start exploring the possibilities of this powerful platform. So, dive in, explore the samples,
and discover the innovative ways that Corda can transform the world of finance and beyond!


## Duo Language Samples
All CorDapp samples are written in duo coding languages to accommodate our vast audience of app developers out there.
```
.
├── java-samples
└── kotlin-samples
```

## Star CorDapps
Out of our sample base, we would like to highlight a few signature CorDapp for you.

* Obligation CorDapp: This is Corda's most famous IOU app. It demonstrates creating a digital asset,
updating the digital asset, and transferring the digital asset.


## Contributing

Corda is an open-source project and contributions are welcome!

To find out how to contribute, please see our [docs](https://docs.r3.com/).

## License

[Apache 2.0](./LICENSE)
16 changes: 16 additions & 0 deletions java-samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Corda5 Java Samples

<p align="center">
<img src="./java.jpeg" alt="Corda" width="500">
</p>

All CorDapp samples are written in duo coding languages to accommodate our vast audience of app developers out there.
This is the Java Samples folder.

## Folder Structure
```
.
├── README.md
└── corda5-obligation-cordapp
```

10 changes: 10 additions & 0 deletions java-samples/corda5-obligation-cordapp/.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,5 @@
@Library('[email protected]') _

cordaNexusScanPipeline(
nexusAppId: 'com.corda.CSDE-Java.5.0'
)
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"
)
88 changes: 88 additions & 0 deletions java-samples/corda5-obligation-cordapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

# 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
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/corda5-obligation-cordapp/.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: {}
89 changes: 89 additions & 0 deletions java-samples/corda5-obligation-cordapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# C5-Obligation-CorDapp

This app is our signature CorDapp that we use to show the main functionalities of Corda, which are creating a digital asset,
updating the digital asset, and transferring the digital asset. This app depicts a simple use
case of money borrowing between two parties. In the app, the borrowed asset is called the `IOUState` (I-owe-you)
and it is quantifiable.

In this app you can:
1. Create a new IOUState with a counterparty. `IOUIssueFlow`
2. List out the IOU entries you had. `ListIOUFlow`
3. Settle(pau back) the IOUState `IOUSettleFlow`
4. Lender transfer the debt to a different person `IOUTransferFlow`

### 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 Bob, Alice, Charlie. 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.

#### Step 1: Create IOUState between two parties
Pick a VNode identity to initiate the IOU creation, and get its short hash. (Let's pick Alice. Don't pick Bob because Bob is the person who alice will borrow from).

Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
```
{
"clientRequestId": "createiou-1",
"flowClassName": "com.r3.developers.samples.obligation.workflows.IOUIssueFlow",
"requestBody": {
"amount":"20",
"lender":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"
}
}
```

After trigger the create-IOUflow, hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the short hash(Alice's hash) and client request id to view the flow result

#### Step 2: List created IOU state
In order to continue the app logics, we would need the IOU ID. This step will bring out all the IOU entries this entity (Alice) has.
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
```
{
"clientRequestId": "list-1",
"flowClassName": "com.r3.developers.samples.obligation.workflows.ListIOUFlow",
"requestBody": {}
}
```
After trigger the list-IOUs flow, again, we need to hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and check the result. Let's record that id.


#### Step 3: Partially settle the IOU with `IOUSettleFlow`
In this step, we will partially settle the IOU with some amount.
Goto `POST /flow/{holdingidentityshorthash}`, enter the identity short hash and request body. Note that the settle action can only be initiated by the borrower of the IOU
```
{
"clientRequestId": "settleiou-1",
"flowClassName": "com.r3.developers.samples.obligation.workflows.IOUSettleFlow",
"requestBody": {
"amountSettle":"10",
"iouID":" ** fill in id **"
}
}
```
And as for the result of this flow, go to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the required fields.

#### Step 4: Lastly, the lender of the IOU can transfer the IOU to a different owner.
Note this transfer action can only be initiated by the lender of the IOU. We will have Bob transfer his IOU to Charlie.
We will now take Bob's shorthash and enter the following request Body.
```
{
"clientRequestId": "transferiou-1",
"flowClassName": "com.r3.developers.samples.obligation.workflows.IOUTransferFlow",
"requestBody": {
"newLender":"CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB",
"iouID":" ** fill in id **"
}
}
```
And as for the result, you need to go to the Get API again and enter the short hash and client request ID.

Thus, we have concluded a full run through of the obligation app.
52 changes: 52 additions & 0 deletions java-samples/corda5-obligation-cordapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 'csde'
}

allprojects {
group 'net.corda.samples'
version '1.0-SNAPSHOT'

def javaVersion = VERSION_11

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

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

}

publishing {
publications {
maven(MavenPublication) {
artifactId "corda5-obligation-cordapp"
groupId project.group
artifact jar
}

}
}

clean.doFirst {
delete "${rootDir}/workspace/"
delete "${rootDir}/logs/"
}

Loading

0 comments on commit 3059de8

Please sign in to comment.