Skip to content

Commit 513128e

Browse files
committed
revamp working referencestates
1 parent 966f3d1 commit 513128e

File tree

20 files changed

+397
-257
lines changed

20 files changed

+397
-257
lines changed

Features/referencestates-sanctionsbody/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Next, we want to issue an IOU. Run from the IOUPartyA shell:
5252

5353
flow start IOUIssueFlow iouValue: 5, otherParty: IOUPartyB, sanctionsBody: SanctionsBody
5454

55-
We've seen how to successfully send an IOU to a non-sanctioned party, so what if we want to send one to a sanctioned party? First we need to update the sanction list so, from the SanctionsParty shell, run:
55+
We've seen how to successfully send an IOU to a non-sanctioned party, so what if we want to send one to a sanctioned party? First we need to update the sanction list so, from the SanctionsBody shell, run:
5656

5757
flow start UpdateSanctionsListFlow partyToSanction: DodgyParty
5858

Features/referencestates-sanctionsbody/build.gradle

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ buildscript {
44

55
ext {
66
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
78
corda_release_version = constants.getProperty("cordaVersion")
8-
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
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 {
20+
mavenLocal()
1921
mavenCentral()
2022
jcenter()
21-
maven {
22-
url 'https://software.r3.com/artifactory/corda-releases'
23-
}
24-
mavenLocal()
23+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
2524
}
2625

2726
dependencies {
@@ -31,9 +30,115 @@ buildscript {
3130
}
3231
}
3332

34-
allprojects {
35-
apply plugin: 'java'
33+
allprojects { //Properties that you need to compile your project (The application)
3634
apply from: "${rootProject.projectDir}/repositories.gradle"
35+
apply plugin: 'java'
36+
37+
repositories {
38+
mavenLocal()
39+
jcenter()
40+
mavenCentral()
41+
maven { url 'https://software.r3.com/artifactory/corda' }
42+
maven { url 'https://jitpack.io' }
43+
}
44+
45+
tasks.withType(JavaCompile) {
46+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
47+
}
48+
49+
jar {
50+
// This makes the JAR's SHA-256 hash repeatable.
51+
preserveFileTimestamps = false
52+
reproducibleFileOrder = true
53+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
54+
}
55+
}
56+
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")
65+
}
66+
}
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"
74+
75+
// CorDapp dependencies.
76+
cordapp project(":workflows")
77+
cordapp project(":contracts")
3778

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+
}
83+
84+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
85+
86+
nodeDefaults {
87+
projectCordapp {
88+
deploy = false
89+
}
90+
91+
cordapp project(":contracts")
92+
cordapp project(":workflows")
93+
94+
rpcUsers = [['username': "user1", 'password': "test", 'permissions': ['ALL']]]
95+
96+
runSchemaMigration = false
97+
}
98+
99+
node {
100+
name "O=Notary,L=London,C=GB"
101+
notary = [validating: false]
102+
p2pPort 10000
103+
rpcSettings {
104+
address("localhost:10001")
105+
adminAddress("localhost:10002")
106+
}
107+
}
38108

109+
node {
110+
name "O=SanctionsBody,L=London,C=GB"
111+
p2pPort 10004
112+
rpcSettings {
113+
address("localhost:10005")
114+
adminAddress("localhost:10006")
115+
}
116+
}
117+
118+
node {
119+
name "O=IOUPartyA,L=New York,C=US"
120+
p2pPort 10008
121+
rpcSettings {
122+
address("localhost:10009")
123+
adminAddress("localhost:10010")
124+
}
125+
}
126+
127+
node {
128+
name "O=IOUPartyB,L=Paris,C=FR"
129+
p2pPort 10012
130+
rpcSettings {
131+
address("localhost:10013")
132+
adminAddress("localhost:10014")
133+
}
134+
}
135+
136+
node {
137+
name "O=DodgyParty,L=Moscow,C=RU"
138+
p2pPort 10016
139+
rpcSettings {
140+
address("localhost:10017")
141+
adminAddress("localhost:10018")
142+
}
143+
}
39144
}

Features/referencestates-sanctionsbody/contracts/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ cordapp {
66
targetPlatformVersion corda_platform_version.toInteger()
77
minimumPlatformVersion corda_platform_version.toInteger()
88
contract {
9-
name "Reference States Cordapp"
9+
name "Reference States SanctionsBody"
1010
vendor "Corda Open Source"
1111
licence "Apache License, Version 2.0"
1212
versionId 1
1313
}
1414
}
1515

1616
sourceSets {
17-
main{
17+
main {
1818
java {
1919
srcDir 'src/main/java'
2020
java.outputDir = file('bin/main')
@@ -34,7 +34,3 @@ dependencies {
3434
cordaRuntime "$corda_release_group:corda:$corda_release_version"
3535

3636
}
37-
38-
tasks.withType(JavaCompile) {
39-
options.compilerArgs << "-parameters" // Required for shell commands.
40-
}

Features/referencestates-sanctionsbody/contracts/src/main/java/com.example/contract/SanctionableIOUContract.java

Lines changed: 0 additions & 86 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package net.corda.samples.referencestates.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.identity.Party;
8+
import net.corda.core.transactions.LedgerTransaction;
9+
import net.corda.samples.referencestates.states.SanctionableIOUState;
10+
import net.corda.samples.referencestates.states.SanctionedEntities;
11+
12+
import java.security.PublicKey;
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
import static net.corda.core.contracts.ContractsDSL.requireThat;
17+
18+
/**
19+
* A implementation of a basic smart contracts in Corda.
20+
* <p>
21+
* This contracts enforces rules regarding the creation of a valid [SanctionableIOUState], which in turn encapsulates an [IOU].
22+
* <p>
23+
* For a new [IOU] to be issued onto the ledger, a transaction is required which takes:
24+
* - Zero input states.
25+
* - One output states: the new [IOU].
26+
* - An Create() command with the public keys of both the lender and the borrower.
27+
* <p>
28+
* All contracts must sub-class the [Contract] interface.
29+
*/
30+
31+
public class SanctionableIOUContract implements Contract {
32+
public static String IOU_CONTRACT_ID = "net.corda.samples.referencestates.contracts.SanctionableIOUContract";
33+
34+
/**
35+
* The verify() function of all the states' contracts must not throw an exception for a transaction to be
36+
* considered valid.
37+
*/
38+
@Override
39+
public void verify(LedgerTransaction tx) throws IllegalArgumentException {
40+
final CommandWithParties command = tx.getCommands().get(0);
41+
requireThat(require -> {
42+
require.using("All transactions require a list of sanctioned entities", tx.referenceInputRefsOfType(SanctionedEntities.class).size() > 0);
43+
SanctionedEntities sanctionedEntities = tx.referenceInputRefsOfType(SanctionedEntities.class).get(0).getState().getData();
44+
require.using(sanctionedEntities.getIssuer().getName().getOrganisation() + " is an invalid issuer of sanctions lists for this contracts", sanctionedEntities.getIssuer().getName().equals(((Commands.Create) (command.getValue())).getSanctionsBody().getName()));
45+
require.using("No inputs should be consumed when issuing an IOU.", tx.getInputs().isEmpty());
46+
require.using("Only one output states should be created.", tx.getOutputs().size() == 1);
47+
SanctionableIOUState out = tx.outputsOfType(SanctionableIOUState.class).get(0);
48+
require.using("The lender and the borrower cannot be the same entity.", !(out.getLender().equals(out.getBorrower())));
49+
List<PublicKey> signerKeys = new ArrayList<>();
50+
for (AbstractParty party : out.getParticipants()
51+
) {
52+
signerKeys.add(party.getOwningKey());
53+
54+
}
55+
require.using("All of the participants must be signers.", command.getSigners().containsAll(signerKeys));
56+
57+
// IOU-specific constraints.
58+
require.using("The IOU's value must be non-negative.", out.getValue() > 0);
59+
60+
// IOU cannot involve a sanctioned entity
61+
require.using("The lender " + out.getLender().getName() + " is a sanctioned entity", !sanctionedEntities.getBadPeople().contains(out.getLender()));
62+
require.using("The borrower " + out.getBorrower().getName() + " is a sanctioned entity", !sanctionedEntities.getBadPeople().contains(out.getBorrower()));
63+
64+
return null;
65+
});
66+
}
67+
68+
/**
69+
* This contracts only implements one command, Create.
70+
*/
71+
public interface Commands extends CommandData {
72+
class Create implements Commands {
73+
private Party sanctionsBody;
74+
75+
public Create(Party sanctionsBody) {
76+
this.sanctionsBody = sanctionsBody;
77+
}
78+
79+
public Party getSanctionsBody() {
80+
return sanctionsBody;
81+
}
82+
}
83+
84+
;
85+
}
86+
}
87+
88+

0 commit comments

Comments
 (0)