Skip to content

Commit 17f804f

Browse files
committed
observablecordapp revamp
1 parent 89d9832 commit 17f804f

File tree

29 files changed

+397
-225
lines changed

29 files changed

+397
-225
lines changed

Features/cordaservice-autopayroll/contracts/src/test/java/net/corda/samples/autopayroll/contracts/ContractTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ContractTests {
1717
TestIdentity partyb = new TestIdentity(new CordaX500Name("Bob", "TestLand", "US"));
1818

1919
@Test
20-
public void GameCanOnlyCreatedWhenTwoDifferentPlayerPresented() {
20+
public void NoNegativePayCheckValue() {
2121
MoneyState tokenPass = new MoneyState(10,partyb.getParty());
2222
MoneyState tokenfail = new MoneyState(-10,partyb.getParty());
2323

Features/observablestates-tradereporting/.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 1 deletion
This file was deleted.

Features/observablestates-tradereporting/README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# observable states cordapp [<img src="../../webIDE.png" height=25 />](https://ide.corda.net/?folder=/home/coder/samples-java/Features/observablestates-tradereporting)
1+
# observable states cordapp
22

33
This CorDapp shows how Corda's [observable states](https://docs.corda.net/docs/corda-os/4.4/tutorial-observer-nodes.html#observer-nodes) feature works. Observable states is the ability for nodes who are not
44
participants in a transaction to still store them if the transactions are sent to them.
@@ -14,7 +14,7 @@ and national regulators. There are two ways to use observable states:
1414

1515
The two approaches are functionally identical.
1616

17-
In this CorDapp, the seller runs [the `TradeAndReport` flow](./workflows/src/main/java/com/observable/flows/TradeAndReport.java#L30-L48) to create [a new `HighlyRegulatedState`](./contracts/src/main/java/com/observable/states/HighlyRegulatedState.java#L19-L22). Then we can see that the seller will:
17+
In this CorDapp, the seller runs [the `TradeAndReport` flow](./workflows-kotlin/src/main/kotlin/com/observable/flows/TradeAndReport.kt) to create [a new `HighlyRegulatedState`](./contracts-kotlin/src/main/kotlin/com/observable/states/HighlyRegulatedState.kt). Then we can see that the seller will:
1818

1919
* Distribute the state to the buyer and the `state regulator` using `FinalityFlow`
2020
* Distribute the state to the `national regulator` manually using the `ReportManually` flow
@@ -26,17 +26,12 @@ In this CorDapp, the seller runs [the `TradeAndReport` flow](./workflows/src/mai
2626

2727
See https://docs.corda.net/getting-set-up.html.
2828

29-
### Running the CorDapp
3029

31-
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
30+
### Deploy and run the node
3231
```
33-
./gradlew clean deployNodes
32+
./greadlew deployNodes
33+
./build/node/runnodes
3434
```
35-
Then type: (to run the nodes)
36-
```
37-
./build/nodes/runnodes
38-
```
39-
4035

4136
### Interacting with the nodes:
4237

@@ -47,6 +42,6 @@ Go to the [CRaSH](https://docs.corda.net/docs/corda-os/shell.html) shell of Sell
4742
The state will be automatically reported to StateRegulator and NationalRegulator, even though they are not
4843
participants. Check this by going to the shell of either node and running:
4944

50-
run vaultQuery contractStateType: com.observable.states.HighlyRegulatedState
45+
run vaultQuery contractStateType: net.corda.samples.observable.states.HighlyRegulatedState
5146

5247
You will see the new `HighlyRegulatedState` in the vault of both nodes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.
22

33
For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
4-
https://www.r3.com/trademark-policy/.
4+
https://www.r3.com/trademark-policy/.
Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
buildscript {
1+
buildscript {//properties that you need to build the project
22
Properties constants = new Properties()
33
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
44

55
ext {
66
corda_release_group = constants.getProperty("cordaReleaseGroup")
7-
corda_release_version = constants.getProperty("cordaVersion")
87
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
99
corda_core_release_version = constants.getProperty("cordaCoreVersion")
1010
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
1112
junit_version = constants.getProperty("junitVersion")
1213
quasar_version = constants.getProperty("quasarVersion")
1314
log4j_version = constants.getProperty("log4jVersion")
1415
slf4j_version = constants.getProperty("slf4jVersion")
15-
corda_platform_version = constants.getProperty("platformVersion")
16+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
1617
}
1718

1819
repositories {
@@ -29,56 +30,107 @@ buildscript {
2930
}
3031
}
3132

32-
apply from: './repositories.gradle'
33+
allprojects {//Properties that you need to compile your project (The application)
34+
apply from: "${rootProject.projectDir}/repositories.gradle"
35+
apply plugin: 'java'
3336

34-
allprojects {
37+
repositories {
38+
mavenLocal()
39+
jcenter()
40+
mavenCentral()
41+
maven { url 'https://software.r3.com/artifactory/corda' }
42+
maven { url 'https://jitpack.io' }
43+
}
3544

36-
apply plugin: 'java'
37-
apply plugin: 'net.corda.plugins.cordapp'
38-
apply plugin: 'net.corda.plugins.cordformation'
39-
apply plugin: 'net.corda.plugins.quasar-utils'
45+
tasks.withType(JavaCompile) {
46+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
47+
}
4048

4149
jar {
42-
// CorDapps do not configure the Node's logging.
43-
exclude '**/log4j2*.xml'
50+
// This makes the JAR's SHA-256 hash repeatable.
51+
preserveFileTimestamps = false
52+
reproducibleFileOrder = true
53+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
4454
}
55+
}
4556

46-
configurations {
47-
compile {
48-
// We want to use SLF4J's version of these bindings: jcl-over-slf4j
49-
// Remove any transitive dependency on Apache's version.
50-
exclude group: 'commons-logging', module: 'commons-logging'
57+
apply plugin: 'net.corda.plugins.cordapp'
58+
apply plugin: 'net.corda.plugins.cordformation'
59+
apply plugin: 'net.corda.plugins.quasar-utils'
60+
61+
sourceSets {
62+
main {
63+
resources {
64+
srcDir rootProject.file("config/dev")
5165
}
5266
}
67+
}
68+
//Module dependencis
69+
dependencies {
70+
// Corda dependencies.
71+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
72+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
73+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
5374

54-
dependencies {
55-
testCompile "junit:junit:$junit_version"
75+
// CorDapp dependencies.
76+
cordapp project(":workflows")
77+
cordapp project(":contracts")
5678

57-
// Corda dependencies.
58-
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
59-
cordaCompile "$corda_release_group:corda-jackson:$corda_release_version"
60-
cordaCompile "$corda_release_group:corda-rpc:$corda_release_version"
61-
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
62-
cordaRuntime "$corda_release_group:corda:$corda_release_version"
79+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
80+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
81+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
82+
}
6383

64-
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
65-
cordaRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
84+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
85+
nodeDefaults {
86+
projectCordapp {
87+
deploy = true
88+
}
89+
cordapp project(':contracts')
90+
cordapp project(':workflows')
91+
runSchemaMigration = true
92+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
6693
}
67-
68-
tasks.withType(JavaCompile) {
69-
options.compilerArgs << "-parameters" // Required for shell commands.
94+
node {
95+
name "O=Notary,L=London,C=GB"
96+
notary = [validating : false]
97+
p2pPort 10002
98+
rpcSettings {
99+
address("localhost:10003")
100+
adminAddress("localhost:10004")
101+
}
102+
cordapps.clear()
70103
}
71-
72-
73-
cordapp {
74-
targetPlatformVersion corda_platform_version.toInteger()
75-
minimumPlatformVersion corda_platform_version.toInteger()
76-
workflow {
77-
name "CorDapp Name"
78-
vendor "Corda Open Source"
79-
licence "Apache License, Version 2.0"
80-
versionId 1
104+
node {
105+
name "O=Seller,L=London,C=GB"
106+
p2pPort 10005
107+
rpcSettings {
108+
address("localhost:10006")
109+
adminAddress("localhost:10007")
110+
}
111+
}
112+
node {
113+
name "O=Buyer,L=New York,C=US"
114+
p2pPort 10008
115+
rpcSettings {
116+
address("localhost:10009")
117+
adminAddress("localhost:10010")
118+
}
119+
}
120+
node {
121+
name "O=StateRegulator,L=New York,C=US"
122+
p2pPort 10011
123+
rpcSettings {
124+
address("localhost:10012")
125+
adminAddress("localhost:10013")
126+
}
127+
}
128+
node {
129+
name "O=NationalRegulator,L=New York,C=US"
130+
p2pPort 10014
131+
rpcSettings {
132+
address("localhost:10015")
133+
adminAddress("localhost:10016")
81134
}
82135
}
83-
84136
}

Features/observablestates-tradereporting/config/test/log4j2-test.xml renamed to Features/observablestates-tradereporting/config/test/log4j2.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Configuration status="info">
3-
<Properties>
4-
<Property name="log-path">build/logs</Property>
5-
<Property name="log-name">node-${hostName}</Property>
6-
</Properties>
7-
83
<Appenders>
94
<Console name="Console-Appender" target="SYSTEM_OUT">
105
<PatternLayout>
@@ -13,19 +8,13 @@
138
</pattern>>
149
</PatternLayout>
1510
</Console>
16-
<File name="File-Appender"
17-
fileName="${log-path}/${log-name}.log" immediateFlush="false" append="true">
18-
<PatternLayout pattern="[%-5level] %d{ISO8601}{GMT+0} [%t] %c{1} - %msg%n"/>
19-
</File>
2011
</Appenders>
2112
<Loggers>
2213
<Root level="info">
2314
<AppenderRef ref="Console-Appender"/>
24-
<AppenderRef ref="File-Appender"/>
2515
</Root>
2616
<Logger name="net.corda" level="info" additivity="false">
2717
<AppenderRef ref="Console-Appender"/>
28-
<AppenderRef ref="File-Appender"/>
2918
</Logger>
3019
</Loggers>
3120
</Configuration>
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
apply from: '../repositories.gradle'
1+
apply plugin: 'net.corda.plugins.cordapp'
2+
apply plugin: 'net.corda.plugins.cordformation'
23

34
cordapp {
4-
targetPlatformVersion corda_platform_version.toInteger()
5-
minimumPlatformVersion corda_platform_version.toInteger()
5+
targetPlatformVersion corda_platform_version
6+
minimumPlatformVersion corda_platform_version
67
contract {
7-
name "Observable States"
8+
name "Template Contracts"
89
vendor "Corda Open Source"
9-
licence "A liberal, open source licence"
10+
licence "Apache License, Version 2.0"
1011
versionId 1
1112
}
1213
}
14+
15+
sourceSets {
16+
main{
17+
java {
18+
srcDir 'src/main/java'
19+
java.outputDir = file('bin/main')
20+
}
21+
}
22+
test{
23+
java{
24+
srcDir 'src/test/java'
25+
java.outputDir = file('bin/test')
26+
}
27+
}
28+
}
29+
30+
dependencies {
31+
// Corda dependencies.
32+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
33+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
34+
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
35+
}

Features/observablestates-tradereporting/contracts/src/main/java/com/observable/contracts/HighlyRegulatedContract.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.corda.samples.observable.contracts;
2+
3+
import net.corda.core.contracts.CommandData;
4+
import net.corda.core.contracts.CommandWithParties;
5+
import net.corda.core.contracts.Contract;
6+
import net.corda.core.identity.AbstractParty;
7+
import net.corda.core.transactions.LedgerTransaction;
8+
import net.corda.samples.observable.states.HighlyRegulatedState;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.stream.Collectors;
12+
13+
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
14+
import static net.corda.core.contracts.ContractsDSL.requireThat;
15+
16+
public class HighlyRegulatedContract implements Contract {
17+
public static final String ID = "net.corda.samples.observable.contracts.HighlyRegulatedContract";
18+
19+
@Override
20+
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
21+
final CommandWithParties<Commands.Trade> command = requireSingleCommand(tx.getCommands(), Commands.Trade.class);
22+
requireThat(require -> {
23+
24+
final HighlyRegulatedState out = tx.outputsOfType(HighlyRegulatedState.class).get(0);
25+
require.using("The Buyer and the seller cannot be the same entity.",
26+
!out.getBuyer().equals(out.getSeller()));
27+
return null;
28+
});
29+
}
30+
31+
public interface Commands extends CommandData {
32+
class Trade implements Commands {}
33+
}
34+
}

Features/observablestates-tradereporting/contracts/src/main/java/com/observable/states/HighlyRegulatedState.java renamed to Features/observablestates-tradereporting/contracts/src/main/java/net/corda/samples/observable/states/HighlyRegulatedState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.observable.states;
1+
package net.corda.samples.observable.states;
22

3-
import com.observable.contracts.HighlyRegulatedContract;
43
import net.corda.core.contracts.BelongsToContract;
54
import net.corda.core.contracts.ContractState;
65
import net.corda.core.identity.AbstractParty;
76
import net.corda.core.identity.Party;
7+
import net.corda.samples.observable.contracts.HighlyRegulatedContract;
88
import org.jetbrains.annotations.NotNull;
99

1010
import java.util.Arrays;

0 commit comments

Comments
 (0)