Skip to content

Commit

Permalink
Initial Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
synechron-finlabs committed Jun 28, 2018
0 parents commit efb1817
Show file tree
Hide file tree
Showing 71 changed files with 2,439 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016, R3 Limited.

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.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Three-way flows - DvP atomic transaction - CorDapp

This CorDapp creates Delivery-vs-Payment atomic transaction for on ledger `Asset` transfer for `Cash` with three participants.

**CorDapp Nodes:**

* Security Seller: This party is owner of `Asset` state of type `OwnableState` on ledger. He sells these assets for cash by creating Corda transaction.
* Security Buyer: This party has some `Cash` tokens on his ledger. He purchases `Asset` securities for Cash.
* Clearing House: coordinates `Seller` and `Buyer` parties to process the settlement transaction. It initiate settlement of `Asset` transfer request and collect the required states (i.e. Asset and Cash) from counterparties (i.e. Seller and Buyer) in-order to complete the transaction.
* Notary: notary node to check double-spend of input states then verify and sign final transaction.

**This CorDapp example business-logic flows as below:**

* 1. The `Seller` party creates the `Asset` state of type `OwnableState` on ledger.
* 2. Create `AssetTransfer` state and share it with `Buyer` party who willing to buy the `Asset`.
* 3. The `Buyer` party review and accept the `AssetTransfer` transaction and further share this state with `ClearingHouse` party.
* 4. The `ClearingHouse` party - offline review and validate the `Asset` data received along with `AssetTransfer` state. If everything is good, he initiate the `AssetSettlementInitiatorFlow` flow to create the settlement transaction with three participants. On completion of settlement transaction `Buyer` party became owner of `Asset` state and issues `Cash` tokens equals to the amount of `Asset.purchaseCost` to `Seller` party on ledger.

## Interacting with the CorDapp via Corda Shell

Use relevant node's Shell console to initiate the flows.

**Let's start flows from each Corda node's shell console step-by-step:**

**1.** To create `Asset` - run below command on `SecuritySeller` node's console:
```console
flow start com.synechron.cordapp.seller.flows.CreateAssetStateFlow$Initiator cusip: "CUSIP222", assetName: "US Bond", purchaseCost: $10000
```
To see state created run below command:
```console
run vaultQuery contractStateType: com.synechron.cordapp.state.Asset
```
Now we have on ledger asset of type OwnableState and ready to sell it to other party on network.

**2.** To create `AssetTransfer` - run below command again on `SecuritySeller` node's console:
```console
flow start com.synechron.cordapp.seller.flows.CreateAssetTransferRequestInitiatorFlow cusip: "CUSIP222", securityBuyer: "O=SecurityBuyer,L=New York,C=US"
```
To see `AssetTransfer` state created run below command again:
```console
run vaultQuery contractStateType: com.synechron.cordapp.state.AssetTransfer
```
You can see the AssetTransfer state data and **copy** the `linearId.id` *field value* of it and save it with you as we required it in next step.

**3.** The `Buyer` party confirm `AssetTransfer` request received by running below command on counterparty `SecurityBuyer` node's console:
```console
flow start com.synechron.cordapp.buyer.flows.ConfirmAssetTransferRequestInitiatorFlow linearId: "<Replace with AssetTransfer.linearId.id>", clearingHouse: "O=ClearingHouse,L=New York,C=US"
```
This flow update the `AssetTransfer.status` value to `PENDING` from it's initial value `PENDING_CONFIRMATION`.

**4.** The `Buyer` party self-issue the `Cash` tokens on ledger using:
```console
flow start net.corda.finance.flows.CashIssueFlow amount: $20000, issuerBankPartyRef: 1234, notary: "O=Notary,L=New York,C=US"
```
To see the issued cash balance run:
```console
run vaultQuery contractStateType: net.corda.finance.contracts.asset.Cash$State
```
**5.** Run below command on the `ClearingHouse` party node's console to create settlement transaction and distribute to three participants:
```console
flow start com.synechron.cordapp.clearinghouse.flows.AssetSettlementInitiatorFlow linearId: "<Replace with AssetTransfer.linearId.id>"
```
On successful completion of flows the `AssetTransfer.status` field value became `TRANSFERRED`. Now you can cross-check the available `Asset` and `Cash` states on each counterparty corda node.
4 changes: 4 additions & 0 deletions TRADEMARK
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.

For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
https://www.r3.com/trademark-policy/.
165 changes: 165 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
buildscript {
ext.corda_release_group = 'net.corda'
ext.corda_release_version = '3.1-corda'
ext.corda_gradle_plugins_version = '3.1.0'
ext.kotlin_version = '1.1.60'
ext.junit_version = '4.12'
ext.quasar_version = '0.7.9'

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
}
}

repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
}

apply plugin: 'kotlin'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.quasar-utils'

sourceSets {
main {
resources {
srcDir "config/dev"
}
}
test {
resources {
srcDir "config/test"
}
}
integrationTest {
kotlin {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/kotlin')
}
}
}

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "junit:junit:$junit_version"

// Corda integration dependencies
cordaCompile "$corda_release_group:corda-core:$corda_release_version"
cordaCompile "$corda_release_group:corda-finance:$corda_release_version"
cordaCompile "$corda_release_group:corda-jackson:$corda_release_version"
cordaCompile "$corda_release_group:corda-rpc:$corda_release_version"
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
cordaCompile "$corda_release_group:corda-webserver-impl:$corda_release_version"
cordaRuntime "$corda_release_group:corda:$corda_release_version"
cordaRuntime "$corda_release_group:corda-webserver:$corda_release_version"

testCompile "$corda_release_group:corda-node-driver:$corda_release_version"

// CorDapp dependencies
// Specify your CorDapp's dependencies below, including dependent CorDapps.
// We've defined Cash as a dependent CorDapp as an example.
cordapp project(":cordapp-contracts-states")
cordapp project(":cordapp-common")
cordapp project(":cordapp-security-buyer")
cordapp project(":cordapp-security-seller")
cordapp project(":cordapp-clearing-house")
cordapp "$corda_release_group:corda-finance:$corda_release_version"
}

task integrationTest(type: Test, dependsOn: []) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
languageVersion = "1.1"
apiVersion = "1.1"
jvmTarget = "1.8"
javaParameters = true // Useful for reflection.
}
}

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
directory "./build/nodes"
node {
name "O=Notary,L=New York,C=US"
notary = [validating: true]
p2pPort 10002
cordapps = [
"$project.group:cordapp-contracts-states:$project.version",
"$corda_release_group:corda-finance:$corda_release_version"
]
}
node {
name "O=SecuritySeller,L=New York,C=US"
p2pPort 10005
rpcSettings {
address("localhost:10006")
adminAddress("localhost:10046")
}
cordapps = [
"$corda_release_group:corda-finance:$corda_release_version",
"$project.group:cordapp-contracts-states:$project.version",
"$project.group:cordapp-common:$project.version",
"$project.group:cordapp-security-seller:$project.version"
]
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
}
node {
name "O=SecurityBuyer,L=New York,C=US"
p2pPort 10008
rpcSettings {
address("localhost:10009")
adminAddress("localhost:10049")
}
cordapps = [
"$corda_release_group:corda-finance:$corda_release_version",
"$project.group:cordapp-contracts-states:$project.version",
"$project.group:cordapp-common:$project.version",
"$project.group:cordapp-security-buyer:$project.version"
]
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
}
node {
name "O=ClearingHouse,L=New York,C=US"
p2pPort 10011
rpcSettings {
address("localhost:10012")
adminAddress("localhost:10412")
}
cordapps = [
"$corda_release_group:corda-finance:$corda_release_version",
"$project.group:cordapp-contracts-states:$project.version",
"$project.group:cordapp-common:$project.version",
"$project.group:cordapp-clearing-house:$project.version"
]
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
}
}

task runTemplateClient(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.synechron.ClientKt'
args 'localhost:10006'
}
59 changes: 59 additions & 0 deletions config/dev/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">

<Properties>
<Property name="log-path">logs</Property>
<Property name="log-name">node-${hostName}</Property>
<Property name="archive">${log-path}/archive</Property>
</Properties>

<ThresholdFilter level="trace"/>

<Appenders>
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
%highlight{%level{length=1} %d{HH:mm:ss} %T %c{1}.%M - %msg%n}{INFO=white,WARN=red,FATAL=bright red blink}
</pattern>>
</PatternLayout>
</Console>

<!-- Will generate up to 10 log files for a given day. During every rollover it will delete
those that are older than 60 days, but keep the most recent 10 GB -->
<RollingFile name="RollingFile-Appender"
fileName="${log-path}/${log-name}.log"
filePattern="${archive}/${log-name}.%d{yyyy-MM-dd}-%i.log.gz">

<PatternLayout pattern="[%-5level] %d{ISO8601}{GMT+0} [%t] %c{1} - %msg%n"/>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>

<DefaultRolloverStrategy min="1" max="10">
<Delete basePath="${archive}" maxDepth="1">
<IfFileName glob="${log-name}*.log.gz"/>
<IfLastModified age="60d">
<IfAny>
<IfAccumulatedFileSize exceeds="10 GB"/>
</IfAny>
</IfLastModified>
</Delete>
</DefaultRolloverStrategy>

</RollingFile>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="Console-Appender"/>
<AppenderRef ref="RollingFile-Appender"/>
</Root>
<Logger name="net.corda" level="DEBUG" additivity="false">
<AppenderRef ref="Console-Appender"/>
<AppenderRef ref="RollingFile-Appender"/>
</Logger>
</Loggers>

</Configuration>
20 changes: 20 additions & 0 deletions config/test/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Appenders>
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
[%-5level] %d{HH:mm:ss.SSS} [%t] %c{1}.%M - %msg%n
</pattern>>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console-Appender"/>
</Root>
<Logger name="net.corda" level="DEBUG" additivity="false">
<AppenderRef ref="Console-Appender"/>
</Logger>
</Loggers>
</Configuration>
Loading

0 comments on commit efb1817

Please sign in to comment.