Skip to content

Commit 5230f7f

Browse files
committed
whistleblower revamp working
1 parent 9ed70c5 commit 5230f7f

File tree

15 files changed

+225
-100
lines changed

15 files changed

+225
-100
lines changed

Features/confidentialidentity-whistleblower/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ First, go the the shell of BraveEmployee, and report BadCompany to the TradeBody
4545

4646
To see the whistle-blowing case stored on the whistle-blowing node, run:
4747

48-
run vaultQuery contractStateType: net.corda.examples.whistleblower.states.BlowWhistleState
48+
run vaultQuery contractStateType: BlowWhistleState
4949

5050
[ {
5151
"badCompany" : "C=KE,L=Eldoret,O=BadCompany",

Features/confidentialidentity-whistleblower/build.gradle

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ buildscript {
33
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
44

55
ext {
6-
7-
//corda_gradle_plugins_version = '4.0.45'
8-
96
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
108
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
1110
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
1212
junit_version = constants.getProperty("junitVersion")
1313
quasar_version = constants.getProperty("quasarVersion")
1414
log4j_version = constants.getProperty("log4jVersion")
1515
slf4j_version = constants.getProperty("slf4jVersion")
1616
corda_platform_version = constants.getProperty("platformVersion").toInteger()
17+
1718
//springboot
1819
spring_boot_version = '2.0.2.RELEASE'
1920
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
@@ -35,7 +36,7 @@ buildscript {
3536
}
3637
}
3738

38-
allprojects {
39+
allprojects {//Properties that you need to compile your project (The application)
3940
apply from: "${rootProject.projectDir}/repositories.gradle"
4041
apply plugin: 'java'
4142

@@ -48,18 +49,19 @@ allprojects {
4849
}
4950

5051
tasks.withType(JavaCompile) {
51-
options.compilerArgs << "-parameters" // Required for shell commands.
52+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
5253
}
5354

54-
5555
jar {
5656
// This makes the JAR's SHA-256 hash repeatable.
5757
preserveFileTimestamps = false
5858
reproducibleFileOrder = true
59+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
5960
}
6061
}
6162

6263
apply plugin: 'net.corda.plugins.cordapp'
64+
apply plugin: 'net.corda.plugins.cordformation'
6365
apply plugin: 'net.corda.plugins.quasar-utils'
6466

6567
sourceSets {
@@ -70,34 +72,74 @@ sourceSets {
7072
}
7173
}
7274

75+
//Module dependencis
7376
dependencies {
7477
// Corda dependencies.
75-
cordaCompile "$corda_release_group:corda-core:$corda_release_version"
78+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
7679
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
7780
cordaRuntime "$corda_release_group:corda:$corda_release_version"
7881

7982
// CorDapp dependencies.
80-
cordaCompile "$corda_release_group:corda-confidential-identities:$corda_release_version"
83+
cordapp project(":workflows")
84+
cordapp project(":contracts")
8185

8286
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
8387
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
8488
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
85-
cordapp "$corda_release_group:corda-confidential-identities:$corda_release_version"
8689
}
8790

88-
cordapp {
89-
info {
90-
name "CorDapp Whistleblower"
91-
vendor "Corda Open Source"
92-
targetPlatformVersion corda_platform_version
93-
minimumPlatformVersion corda_platform_version
91+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
92+
93+
nodeDefaults {
94+
95+
projectCordapp {
96+
deploy = false
97+
}
98+
99+
cordapp project('workflows')
100+
cordapp project('contracts')
101+
102+
runSchemaMigration = true
103+
}
104+
105+
node {
106+
name "O=Notary,L=Nakuru,C=KE"
107+
notary = [validating: true]
108+
p2pPort 10006
109+
rpcSettings {
110+
address("localhost:10007")
111+
adminAddress("localhost:10008")
112+
}
94113
}
95-
}
96114

97-
task installQuasar(type: Copy) {
98-
destinationDir rootProject.file("lib")
99-
from(configurations.quasar) {
100-
rename 'quasar-core(.*).jar', 'quasar.jar'
115+
node {
116+
name "O=BraveEmployee,L=Nairobi,C=KE"
117+
p2pPort 10009
118+
rpcSettings {
119+
address("localhost:10010")
120+
adminAddress("localhost:10011")
121+
}
122+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
101123
}
102-
}
103124

125+
node {
126+
name "O=TradeBody,L=Kisumu,C=KE"
127+
p2pPort 10013
128+
rpcSettings {
129+
address("localhost:10014")
130+
adminAddress("localhost:10015")
131+
}
132+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
133+
}
134+
135+
node {
136+
name "O=BadCompany,L=Eldoret,C=KE"
137+
p2pPort 10017
138+
rpcSettings {
139+
address("localhost:10018")
140+
adminAddress("localhost:10019")
141+
}
142+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
143+
}
144+
145+
}

Features/confidentialidentity-whistleblower/contracts/build.gradle

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ cordapp {
55
targetPlatformVersion corda_platform_version
66
minimumPlatformVersion corda_platform_version
77
contract {
8-
name "Whistleblower CorDapp"
8+
name "Confidential Identity Whistleblower"
99
vendor "Corda Open Source"
1010
licence "Apache License, Version 2.0"
1111
versionId 1
1212
}
1313
}
1414

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+
1530
dependencies {
1631
// Corda dependencies.
1732
cordaCompile "$corda_release_group:corda-core:$corda_release_version"
1833
compileOnly "$corda_release_group:corda-testserver-impl:$corda_release_version"
1934
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
20-
}
35+
}

Features/confidentialidentity-whistleblower/contracts/src/main/java/net/corda/examples/whistleblower/contracts/BlowWhistleContract.java renamed to Features/confidentialidentity-whistleblower/contracts/src/main/java/net/corda/samples/whistleblower/contracts/BlowWhistleContract.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
package net.corda.examples.whistleblower.contracts;
1+
package net.corda.samples.whistleblower.contracts;
22

33
import net.corda.core.contracts.CommandData;
44
import net.corda.core.contracts.CommandWithParties;
55
import net.corda.core.contracts.Contract;
66
import net.corda.core.identity.AbstractParty;
77
import net.corda.core.transactions.LedgerTransaction;
8-
import net.corda.examples.whistleblower.states.BlowWhistleState;
8+
import net.corda.samples.whistleblower.states.BlowWhistleState;
99
import org.jetbrains.annotations.NotNull;
1010

1111
import java.util.stream.Collectors;
1212

13-
import static net.corda.core.contracts.ContractsDSL.*;
13+
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
14+
import static net.corda.core.contracts.ContractsDSL.requireThat;
1415

1516
/**
1617
* A contract supporting two state transitions:
1718
* - Blowing the whistle on a company
1819
* - Transferring an existing case to a new investigator
1920
*/
2021
public class BlowWhistleContract implements Contract {
21-
public final static String ID = "net.corda.examples.whistleblower.contracts.BlowWhistleContract";
22+
public final static String ID = "net.corda.samples.whistleblower.contracts.BlowWhistleContract";
2223

2324
@Override
2425
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
@@ -42,7 +43,10 @@ public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentExceptio
4243
}
4344

4445
public interface Commands extends CommandData {
45-
/** Blowing the whistle on a company. */
46-
class BlowWhistleCmd implements Commands {}
46+
/**
47+
* Blowing the whistle on a company.
48+
*/
49+
class BlowWhistleCmd implements Commands {
50+
}
4751
}
4852
}

Features/confidentialidentity-whistleblower/contracts/src/main/java/net/corda/examples/whistleblower/states/BlowWhistleState.java renamed to Features/confidentialidentity-whistleblower/contracts/src/main/java/net/corda/samples/whistleblower/states/BlowWhistleState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.corda.examples.whistleblower.states;
1+
package net.corda.samples.whistleblower.states;
22

33
import com.google.common.collect.ImmutableList;
44
import net.corda.core.contracts.BelongsToContract;
@@ -7,14 +7,14 @@
77
import net.corda.core.identity.AbstractParty;
88
import net.corda.core.identity.AnonymousParty;
99
import net.corda.core.identity.Party;
10-
import net.corda.examples.whistleblower.contracts.BlowWhistleContract;
10+
import net.corda.samples.whistleblower.contracts.BlowWhistleContract;
1111
import org.jetbrains.annotations.NotNull;
1212

1313
import java.util.List;
1414

1515
/**
1616
* A state representing a whistle-blowing case.
17-
*
17+
* <p>
1818
* The identity of both the whistle-blower and the investigator is kept confidential through the
1919
* use of [AnonymousParty].
2020
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package net.corda.samples.whistleblower.contracts;
2+
3+
import net.corda.core.contracts.Contract;
4+
import net.corda.core.identity.CordaX500Name;
5+
import net.corda.samples.whistleblower.states.BlowWhistleState;
6+
import net.corda.testing.core.DummyCommandData;
7+
import net.corda.testing.core.TestIdentity;
8+
import net.corda.testing.node.MockServices;
9+
import org.junit.Test;
10+
11+
import java.util.Arrays;
12+
13+
import static net.corda.testing.node.NodeTestUtils.transaction;
14+
15+
public class BlowWhistleContractTests {
16+
17+
private final TestIdentity a = new TestIdentity(new CordaX500Name("alice", "", "GB"));
18+
private final TestIdentity b = new TestIdentity(new CordaX500Name("bob", "", "GB"));
19+
private final TestIdentity c = new TestIdentity(new CordaX500Name("bad corp", "", "GB"));
20+
21+
private MockServices ledgerServices = new MockServices(
22+
Arrays.asList("net.corda.samples.whistleblower.contracts")
23+
);
24+
25+
BlowWhistleState st = new BlowWhistleState(c.getParty(), a.getParty().anonymise(), b.getParty().anonymise());
26+
27+
@Test
28+
public void SantaSessionContractImplementsContract() {
29+
assert (new BlowWhistleContract() instanceof Contract);
30+
}
31+
32+
@Test
33+
public void contractRequiresZeroInputsInTheTransaction() {
34+
35+
transaction(ledgerServices, tx -> {
36+
// Has an input, will fail.
37+
tx.output(BlowWhistleContract.ID, st);
38+
tx.output(BlowWhistleContract.ID, st);
39+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new BlowWhistleContract.Commands.BlowWhistleCmd());
40+
tx.fails();
41+
return null;
42+
});
43+
44+
transaction(ledgerServices, tx -> {
45+
// Has no input, will verify.
46+
tx.output(BlowWhistleContract.ID, st);
47+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new BlowWhistleContract.Commands.BlowWhistleCmd());
48+
tx.verifies();
49+
return null;
50+
});
51+
}
52+
53+
@Test
54+
public void contractRequiresSpecificCommand() {
55+
transaction(ledgerServices, tx -> {
56+
// Has wrong command type, will fail.
57+
tx.output(BlowWhistleContract.ID, st);
58+
tx.command(Arrays.asList(a.getPublicKey()), DummyCommandData.INSTANCE);
59+
tx.fails();
60+
return null;
61+
});
62+
63+
transaction(ledgerServices, tx -> {
64+
// Has correct command type, will verify.
65+
tx.output(BlowWhistleContract.ID, st);
66+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new BlowWhistleContract.Commands.BlowWhistleCmd());
67+
tx.verifies();
68+
return null;
69+
});
70+
71+
}
72+
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package net.corda.samples.whistleblower.states;
2+
3+
import net.corda.core.contracts.ContractState;
4+
import net.corda.core.contracts.LinearState;
5+
import net.corda.core.contracts.UniqueIdentifier;
6+
import net.corda.core.identity.CordaX500Name;
7+
import net.corda.testing.core.TestIdentity;
8+
import org.junit.Test;
9+
10+
import static org.jgroups.util.Util.assertEquals;
11+
import static org.jgroups.util.Util.assertTrue;
12+
13+
public class BlowWhistleStateTests {
14+
15+
private final TestIdentity a = new TestIdentity(new CordaX500Name("alice", "", "GB"));
16+
private final TestIdentity b = new TestIdentity(new CordaX500Name("bob", "", "GB"));
17+
private final TestIdentity c = new TestIdentity(new CordaX500Name("bad corp", "", "GB"));
18+
19+
@Test
20+
public void constructorTest() {
21+
22+
// here, c is the bad corporation, a is the Whistleblower, and b is the investigator
23+
BlowWhistleState st = new BlowWhistleState(c.getParty(), a.getParty().anonymise(), b.getParty().anonymise());
24+
25+
assertEquals(a.getParty(), st.getWhistleBlower());
26+
assertEquals(c.getParty(), st.getBadCompany());
27+
assertEquals(b.getParty(), st.getInvestigator());
28+
29+
assertTrue(st.getParticipants().contains(a.getParty()));
30+
assertTrue(st.getParticipants().contains(b.getParty()));
31+
}
32+
33+
@Test
34+
public void stateImplementTests() {
35+
BlowWhistleState st = new BlowWhistleState(c.getParty(), a.getParty().anonymise(), b.getParty().anonymise());
36+
assertTrue(st instanceof ContractState);
37+
assertTrue(st instanceof LinearState);
38+
assertTrue(st.getLinearId() instanceof UniqueIdentifier);
39+
}
40+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
name=Test
2-
group=net.corda.examples.whistleblower
1+
name=Confidential Identity Whistleblower
2+
group=com.whistleblower
33
version=0.1

Features/confidentialidentity-whistleblower/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)