Skip to content

Commit 96f4607

Browse files
committed
restructure of sendfile cordapp
1 parent 35ae9d4 commit 96f4607

File tree

15 files changed

+228
-79
lines changed

15 files changed

+228
-79
lines changed

Features/attachment-sendfile/build.gradle

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

55
ext {
6-
76
corda_release_group = constants.getProperty("cordaReleaseGroup")
87
corda_release_version = constants.getProperty("cordaVersion")
9-
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
109
corda_core_release_version = constants.getProperty("cordaCoreVersion")
1110
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
1211
junit_version = constants.getProperty("junitVersion")
@@ -20,7 +19,7 @@ buildscript {
2019
mavenLocal()
2120
mavenCentral()
2221
jcenter()
23-
maven { url 'https://software.r3.com/artifactory/corda' }
22+
maven { url 'https://software.r3.com/artifactory/corda' }
2423
}
2524

2625
dependencies {
@@ -47,7 +46,6 @@ allprojects {
4746
}
4847

4948

50-
5149
jar {
5250
// This makes the JAR's SHA-256 hash repeatable.
5351
preserveFileTimestamps = false
@@ -69,25 +67,79 @@ sourceSets {
6967
dependencies {
7068
// Corda dependencies.
7169
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
70+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
7271
cordaRuntime "$corda_release_group:corda:$corda_release_version"
7372

7473
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
7574
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
7675
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
76+
77+
cordapp project('contracts')
78+
cordapp project('workflows')
79+
}
80+
81+
task installQuasar(type: Copy) {
82+
destinationDir rootProject.file("lib")
83+
from(configurations.quasar) {
84+
rename 'quasar-core(.*).jar', 'quasar.jar'
85+
}
7786
}
7887

7988
cordapp {
8089
info {
81-
name "CorDapp Template"
90+
name "Attachment Sendfile"
8291
vendor "Corda Open Source"
8392
targetPlatformVersion corda_platform_version
8493
minimumPlatformVersion corda_platform_version
8594
}
8695
}
8796

88-
task installQuasar(type: Copy) {
89-
destinationDir rootProject.file("lib")
90-
from(configurations.quasar) {
91-
rename 'quasar-core(.*).jar', 'quasar.jar'
97+
apply plugin: 'net.corda.plugins.cordapp'
98+
apply plugin: 'net.corda.plugins.quasar-utils'
99+
apply plugin: 'net.corda.plugins.cordformation'
100+
apply plugin: 'java'
101+
102+
103+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
104+
105+
nodeDefaults {
106+
107+
projectCordapp {
108+
deploy = true
109+
}
110+
111+
cordapp project('contracts')
112+
cordapp project('workflows')
113+
runSchemaMigration = true
114+
}
115+
116+
node {
117+
name "O=Notary,L=London,C=GB"
118+
notary = [validating: false]
119+
p2pPort 10002
120+
rpcSettings {
121+
address("localhost:10003")
122+
adminAddress("localhost:10043")
123+
}
124+
}
125+
126+
node {
127+
name "O=Buyer,L=London,C=GB"
128+
p2pPort 10005
129+
rpcSettings {
130+
address("localhost:10006")
131+
adminAddress("localhost:10046")
132+
}
133+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
134+
}
135+
136+
node {
137+
name "O=Seller,L=New York,C=US"
138+
p2pPort 10008
139+
rpcSettings {
140+
address("localhost:10009")
141+
adminAddress("localhost:10049")
142+
}
143+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
92144
}
93145
}

Features/attachment-sendfile/contracts/build.gradle

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

15-
dependencies {
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+
}
1629

30+
dependencies {
1731
// Corda dependencies.
1832
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
19-
33+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
2034
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
21-
}
35+
}

Features/attachment-sendfile/contracts/src/main/java/net/corda/examples/sendfile/contracts/InvoiceContract.java renamed to Features/attachment-sendfile/contracts/src/main/java/net/corda/samples/sendfile/contracts/InvoiceContract.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
package net.corda.examples.sendfile.contracts;
1+
package net.corda.samples.sendfile.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.transactions.LedgerTransaction;
7-
import net.corda.examples.sendfile.states.InvoiceState;
7+
import net.corda.samples.sendfile.states.InvoiceState;
88
import org.jetbrains.annotations.NotNull;
99

1010
import java.util.List;
1111

12-
import static net.corda.core.contracts.ContractsDSL.*;
12+
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
13+
import static net.corda.core.contracts.ContractsDSL.requireThat;
14+
1315
// ************
1416
// * Contract *
1517
// ************
1618
public class InvoiceContract implements Contract {
1719
// Used to identify our contract when building a transaction.
18-
public final static String ID = "net.corda.examples.sendfile.contracts.InvoiceContract";
20+
public final static String ID = "net.corda.samples.sendfile.contracts.InvoiceContract";
1921

2022
@Override
2123
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
@@ -32,6 +34,7 @@ public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentExceptio
3234
}
3335

3436
public interface Commands extends CommandData {
35-
class Issue implements Commands {}
37+
class Issue implements Commands {
38+
}
3639
}
3740
}

Features/attachment-sendfile/contracts/src/main/java/net/corda/examples/sendfile/states/InvoiceState.java renamed to Features/attachment-sendfile/contracts/src/main/java/net/corda/samples/sendfile/states/InvoiceState.java

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

33
import net.corda.core.contracts.BelongsToContract;
44
import net.corda.core.contracts.ContractState;
55
import net.corda.core.identity.AbstractParty;
6-
import net.corda.core.identity.Party;
7-
import net.corda.examples.sendfile.contracts.InvoiceContract;
6+
import net.corda.samples.sendfile.contracts.InvoiceContract;
87
import org.jetbrains.annotations.NotNull;
98

109
import java.util.List;
11-
import java.util.stream.Collectors;
1210

1311
// *********
1412
// * State *
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package net.corda.samples.sendfile.contracts;
2+
3+
import net.corda.core.contracts.CommandData;
4+
import net.corda.core.contracts.Contract;
5+
import net.corda.core.contracts.TypeOnlyCommandData;
6+
import net.corda.core.identity.CordaX500Name;
7+
import net.corda.samples.sendfile.states.InvoiceState;
8+
import net.corda.testing.core.DummyCommandData;
9+
import net.corda.testing.core.TestIdentity;
10+
import net.corda.testing.node.MockServices;
11+
import org.junit.Test;
12+
13+
import java.util.Arrays;
14+
15+
import static net.corda.testing.node.NodeTestUtils.transaction;
16+
import static org.jgroups.util.Util.assertEquals;
17+
18+
public class InvoiceContractTests {
19+
20+
// A pre-defined dummy command.
21+
public interface Commands extends CommandData {
22+
class DummyCommand extends TypeOnlyCommandData implements Commands {
23+
}
24+
}
25+
26+
private MockServices ledgerServices = new MockServices(
27+
Arrays.asList("net.corda.samples.sendfile.contracts")
28+
);
29+
30+
31+
private TestIdentity a = new TestIdentity(new CordaX500Name("Alice", "", "GB"));
32+
private TestIdentity b = new TestIdentity(new CordaX500Name("Bob", "", "GB"));
33+
34+
private final String STRINGID = "StringID that is unique";
35+
private InvoiceState st = new InvoiceState(STRINGID, Arrays.asList(a.getParty(), b.getParty()));
36+
37+
38+
@Test
39+
public void constructorTest() {
40+
assertEquals(STRINGID, st.getInvoiceAttachmentID());
41+
}
42+
43+
@Test
44+
public void InvoiceContractImplementsContract() {
45+
assert (new InvoiceContract() instanceof Contract);
46+
}
47+
48+
49+
@Test
50+
public void contractRequiresOneCommandInTheTransaction() {
51+
transaction(ledgerServices, tx -> {
52+
tx.output(InvoiceContract.ID, st);
53+
// Has two commands, will fail.
54+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new InvoiceContract.Commands.Issue());
55+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new InvoiceContract.Commands.Issue());
56+
tx.fails();
57+
return null;
58+
});
59+
60+
transaction(ledgerServices, tx -> {
61+
tx.output(InvoiceContract.ID, st);
62+
// Has one command, will verify.
63+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new InvoiceContract.Commands.Issue());
64+
tx.verifies();
65+
return null;
66+
});
67+
}
68+
69+
@Test
70+
public void contractRequiresTheTransactionsCommandToBeAnIssueCommand() {
71+
transaction(ledgerServices, tx -> {
72+
// Has wrong command type, will fail.
73+
tx.output(InvoiceContract.ID, st);
74+
tx.command(Arrays.asList(a.getPublicKey()), DummyCommandData.INSTANCE);
75+
tx.fails();
76+
return null;
77+
});
78+
79+
transaction(ledgerServices, tx -> {
80+
// Has correct command type, will verify.
81+
tx.output(InvoiceContract.ID, st);
82+
tx.command(Arrays.asList(a.getPublicKey(), b.getPublicKey()), new InvoiceContract.Commands.Issue());
83+
tx.verifies();
84+
return null;
85+
});
86+
}
87+
88+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.corda.samples.sendfile.contracts;
2+
3+
import net.corda.core.identity.CordaX500Name;
4+
import net.corda.core.identity.Party;
5+
import net.corda.samples.sendfile.states.InvoiceState;
6+
import net.corda.testing.core.TestIdentity;
7+
import org.junit.Test;
8+
9+
import java.util.Arrays;
10+
11+
import static org.jgroups.util.Util.assertEquals;
12+
13+
public class InvoiceStateTests {
14+
15+
private final Party a = new TestIdentity(new CordaX500Name("Alice", "", "GB")).getParty();
16+
private final Party b = new TestIdentity(new CordaX500Name("Bob", "", "GB")).getParty();
17+
18+
private final String STRINGID = "StringID that is unique";
19+
20+
@Test
21+
public void constructorTest() {
22+
InvoiceState st = new InvoiceState(STRINGID, Arrays.asList(a, b));
23+
24+
assertEquals(STRINGID, st.getInvoiceAttachmentID());
25+
}
26+
27+
28+
}
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.sendfile
1+
name=Attachment Sendfile
2+
group=com.sendfile
33
version=0.1

Features/attachment-sendfile/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

Features/attachment-sendfile/workflows/build.gradle

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cordapp {
77
targetPlatformVersion corda_platform_version
88
minimumPlatformVersion corda_platform_version
99
workflow {
10-
name "sendfile Flows"
10+
name "Attachment Sendfile"
1111
vendor "Corda Open Source"
1212
licence "Apache License, Version 2.0"
1313
versionId 1
@@ -58,39 +58,3 @@ task integrationTest(type: Test, dependsOn: []) {
5858
classpath = sourceSets.integrationTest.runtimeClasspath
5959
}
6060

61-
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
62-
nodeDefaults {
63-
projectCordapp {
64-
deploy = true
65-
}
66-
cordapp project(':contracts')
67-
runSchemaMigration = true
68-
}
69-
node {
70-
name "O=Notary,L=London,C=GB"
71-
notary = [validating : false]
72-
p2pPort 10002
73-
rpcSettings {
74-
address("localhost:10003")
75-
adminAddress("localhost:10043")
76-
}
77-
}
78-
node {
79-
name "O=Buyer,L=London,C=GB"
80-
p2pPort 10005
81-
rpcSettings {
82-
address("localhost:10006")
83-
adminAddress("localhost:10046")
84-
}
85-
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
86-
}
87-
node {
88-
name "O=Seller,L=New York,C=US"
89-
p2pPort 10008
90-
rpcSettings {
91-
address("localhost:10009")
92-
adminAddress("localhost:10049")
93-
}
94-
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
95-
}
96-
}

Features/attachment-sendfile/workflows/src/integrationTest/java/net/corda/examples/sendfile/DriverBasedTest.java renamed to Features/attachment-sendfile/workflows/src/integrationTest/java/net/corda/samples/sendfile/DriverBasedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.corda.examples.sendfile;
1+
package net.corda.samples.sendfile;
22

33
import net.corda.core.identity.CordaX500Name;
44
import net.corda.testing.core.TestIdentity;

0 commit comments

Comments
 (0)