Skip to content

Commit 608f86d

Browse files
authored
Merge pull request #49 from corda/bn-extension
Add Business extension sample
2 parents fd00a2d + 162da01 commit 608f86d

File tree

36 files changed

+1661
-50
lines changed

36 files changed

+1661
-50
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cordaReleaseGroup=net.corda
2+
cordaCoreReleaseGroup=net.corda
3+
cordaVersion=4.7
4+
cordaCoreVersion=4.7
5+
gradlePluginsVersion=5.0.12
6+
kotlinVersion=1.2.71
7+
junitVersion=4.12
8+
quasarVersion=0.7.10
9+
log4jVersion =2.11.2
10+
platformVersion=9
11+
slf4jVersion=1.7.25
12+
nettyVersion=4.1.22.Final
13+
corda_bn_extension_version=1.1-RC03
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016, R3 Limited.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
108 KB
Loading
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Insurance Business Network
2+
3+
4+
This sample will show you how to deploy and manage a business network. Our example use case is a mock insurance consortium.
5+
6+
<p align="center">
7+
<img src="./MockDiagram.jpeg" alt="Corda">
8+
</p>
9+
10+
### Concept:
11+
In this app, we will have a global insurance network, where participants are either insurance companies or different kind of health care providers.
12+
With the help of business network extension, we can further breakdown the global network into smaller pieces as groups, such as APAC_Insurance_Alliance.
13+
14+
In our sample, we will have three nodes, named as:
15+
* NetworkOperator <- Business Network Operator
16+
* Insurance <- Insurance Company that is in the network
17+
* CarePro <- Care Provider of the network
18+
19+
The NetworkOperator will be create and primarily manage the network. As introduced in the SDK docs, NetworkOperator will be the default authorized user of this global network. And the other two nodes will fill the roles which can be easily tell by its name.
20+
21+
#### The corDapp will run with the following steps:
22+
1. Network creations by NetworkOperator
23+
2. The rest of the nodes request join the network
24+
3. The NetworkOperator will query all the request and active the membership status for the other nodes.
25+
4. The NetworkOperator will then create a sub group out of the global insurance network called APAC_Insurance_Alliance, and include the two other nodes in the network.
26+
5. The NetworkOperator will then assign custom network identity to the nodes. The insurer node will get an insurance identity, the carePro node will get a health care provider identity.
27+
6. Custom network identity comes with custom roles. We will give the insurer node a policy.
28+
As of now, the network setup is done. The very last step is to run a transaction between the insurer and the carePro node
29+
30+
### Usage
31+
32+
#### Running the CorDapp
33+
34+
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
35+
```
36+
./gradlew clean deployNodes
37+
```
38+
Then type: (to run the nodes)
39+
```
40+
./build/nodes/runnodes
41+
```
42+
#### Interacting with the CorDapp
43+
44+
**Step 1:** Create the network in NetwprkOperator's terminal
45+
```
46+
flow start CreateNetwork
47+
```
48+
Sample output:
49+
```
50+
Mon Apr 12 10:35:47 EDT 2021>>> flow start CreateNetwork
51+
52+
✅ Starting
53+
➡️ Done
54+
Flow completed with result:
55+
A network was created with NetworkID: 121577cf-30bf-4e20-9c7d-97f0b4628b06 <- This is what you need in Step 2
56+
```
57+
**Step 2:** 2 non-member makes the request to join the network. Fill in the networkId with what was return from Step1
58+
```
59+
flow start RequestMembership authorisedParty: NetworkOperator, networkId: <xxxx-xxxx-NETWORK-ID-xxxxx>
60+
```
61+
**Step 3:** go back to the admin node, and query all the membership requests.
62+
```
63+
flow start QueryAllMembers
64+
```
65+
**Step 4:** In this step, Network Operator will active the pending memberships
66+
Insurance: fill in the Insurance node MembershipId that is display in the previous query
67+
```
68+
flow start ActiveMembers membershipId: <xxxx-xxxx-INSURANCE-ID-xxxxx>
69+
```
70+
CarePro: fill in the CarePro node MembershipId that is display in the previous query
71+
```
72+
flow start ActiveMembers membershipId: <xxxx-xxxx-CAREPRO-ID-xxxxx>
73+
```
74+
75+
**Step 5:** Admin create subgroup and add group members.
76+
```
77+
flow start CreateNetworkSubGroup networkId: <xxxx-FROM-STEP-ONE-xxxxx>, groupName: APAC_Insurance_Alliance, groupParticipants: [<xxxx-NETWORKOPERATOR-ID-xxxxx>, <xxxx-xxxx-INSURANCE-ID-xxxxx>, <xxxx-xxxx-CAREPRO-ID-xxxxx>]
78+
```
79+
**Step 6:** Admin assign business identity to a member.
80+
```
81+
flow start AssignBNIdentity firmType: InsuranceFirm, membershipId: <xxxx-xxxx-INSURANCE-ID-xxxxx>, bnIdentity: APACIN76CZX
82+
```
83+
**Step 7:** Admin assign business identity to the second member
84+
```
85+
flow start AssignBNIdentity firmType: CareProvider, membershipId: <xxxx-xxxx-CAREPRO-ID-xxxxx>, bnIdentity: APACCP44OJS
86+
```
87+
**Step 8:** Admin assign business identity related ROLE to the member.
88+
```
89+
flow start AssignPolicyIssuerRole membershipId: <xxxx-xxxx-INSURANCE-ID-xxxxx>, networkId: <xxxx-xxxx-NETWORK-ID-xxxxx>
90+
```
91+
Now to see our membership states, we can run these vault queries.
92+
```
93+
run vaultQuery contractStateType: net.corda.core.contracts.ContractState
94+
run vaultQuery contractStateType: net.corda.bn.states.MembershipState
95+
```
96+
-------------------Network setup is done, and business flow begins--------------------------
97+
98+
**Step 9:** The insurance Company will issue a policy to insuree. The flow initiator (the insurance company) has to be a member of the Business network, has to have a insuranceIdentity, and has to have issuer Role, and has to have issuance permission.
99+
```
100+
flow start IssuePolicyInitiator networkId: <xxxx-xxxx-NETWORK-ID-xxxxx>, careProvider: CarePro, insuree: PeterLi
101+
```
102+
**Step 10:** Query the state from the CarePro node.
103+
```
104+
run vaultQuery contractStateType: net.corda.samples.businessmembership.states.InsuranceState
105+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.
2+
3+
For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
4+
https://www.r3.com/trademark-policy/.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
buildscript {//properties that you need to build the project
2+
Properties constants = new Properties()
3+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
4+
5+
ext {
6+
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
10+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
12+
junit_version = constants.getProperty("junitVersion")
13+
quasar_version = constants.getProperty("quasarVersion")
14+
log4j_version = constants.getProperty("log4jVersion")
15+
slf4j_version = constants.getProperty("slf4jVersion")
16+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
17+
//springboot
18+
spring_boot_version = '2.0.2.RELEASE'
19+
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
20+
//Membership Attestation
21+
corda_bn_extension_version=constants.getProperty("corda_bn_extension_version")
22+
}
23+
24+
repositories {
25+
mavenLocal()
26+
mavenCentral()
27+
jcenter()
28+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
29+
}
30+
31+
dependencies {
32+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
33+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
34+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
35+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
36+
}
37+
}
38+
39+
allprojects {//Properties that you need to compile your project (The application)
40+
apply from: "${rootProject.projectDir}/repositories.gradle"
41+
apply plugin: 'java'
42+
43+
repositories {
44+
mavenLocal()
45+
jcenter()
46+
mavenCentral()
47+
maven { url 'https://software.r3.com/artifactory/corda' }
48+
maven { url 'https://jitpack.io' }
49+
}
50+
51+
tasks.withType(JavaCompile) {
52+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
53+
}
54+
55+
jar {
56+
// This makes the JAR's SHA-256 hash repeatable.
57+
preserveFileTimestamps = false
58+
reproducibleFileOrder = true
59+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
60+
}
61+
}
62+
63+
apply plugin: 'net.corda.plugins.cordapp'
64+
apply plugin: 'net.corda.plugins.cordformation'
65+
apply plugin: 'net.corda.plugins.quasar-utils'
66+
67+
sourceSets {
68+
main {
69+
resources {
70+
srcDir rootProject.file("config/dev")
71+
}
72+
}
73+
}
74+
//Module dependencis
75+
dependencies {
76+
// Corda dependencies.
77+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
78+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
79+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
80+
81+
// CorDapp dependencies.
82+
cordapp project(":workflows")
83+
cordapp project(":contracts")
84+
cordapp("net.corda.bn:business-networks-contracts:$corda_bn_extension_version")
85+
cordapp("net.corda.bn:business-networks-workflows:$corda_bn_extension_version")
86+
87+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
88+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
89+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
90+
}
91+
92+
93+
//Task to deploy the nodes in order to bootstrap a network
94+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
95+
96+
/* This property will load the CorDapps to each of the node by default, including the Notary. You can find them
97+
* in the cordapps folder of the node at build/nodes/Notary/cordapps. However, the notary doesn't really understand
98+
* the notion of cordapps. In production, Notary does not need cordapps as well. This is just a short cut to load
99+
* the Corda network bootstrapper.
100+
*/
101+
nodeDefaults {
102+
projectCordapp {
103+
deploy = false
104+
}
105+
cordapp project(':contracts')
106+
cordapp project(':workflows')
107+
cordapp("net.corda.bn:business-networks-contracts:$corda_bn_extension_version")
108+
cordapp("net.corda.bn:business-networks-workflows:$corda_bn_extension_version")
109+
runSchemaMigration = true //This configuration is for any CorDapps with custom schema, We will leave this as true to avoid
110+
//problems for developers who are not familiar with Corda. If you are not using custom schemas, you can change
111+
//it to false for quicker project compiling time.
112+
}
113+
node {
114+
name "O=Notary,L=London,C=GB"
115+
notary = [validating : false]
116+
p2pPort 10002
117+
rpcSettings {
118+
address("localhost:10003")
119+
adminAddress("localhost:10043")
120+
}
121+
}
122+
node {
123+
name "O=NetworkOperator,L=London,C=GB"
124+
p2pPort 10005
125+
rpcSettings {
126+
address("localhost:10006")
127+
adminAddress("localhost:10046")
128+
}
129+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
130+
}
131+
node {
132+
name "O=Insurance,L=New York,C=US"
133+
p2pPort 10008
134+
rpcSettings {
135+
address("localhost:10009")
136+
adminAddress("localhost:10049")
137+
}
138+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
139+
}
140+
node {
141+
name "O=CarePro,L=New York,C=US"
142+
p2pPort 10011
143+
rpcSettings {
144+
address("localhost:10012")
145+
adminAddress("localhost:10052")
146+
}
147+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
148+
}
149+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="info">
3+
4+
<Properties>
5+
<Property name="log-path">logs</Property>
6+
<Property name="log-name">node-${hostName}</Property>
7+
<Property name="archive">${log-path}/archive</Property>
8+
</Properties>
9+
10+
<ThresholdFilter level="trace"/>
11+
12+
<Appenders>
13+
<Console name="Console-Appender" target="SYSTEM_OUT">
14+
<PatternLayout>
15+
<pattern>
16+
%highlight{%level{length=1} %d{HH:mm:ss} %T %c{1}.%M - %msg%n}{INFO=white,WARN=red,FATAL=bright red blink}
17+
</pattern>>
18+
</PatternLayout>
19+
</Console>
20+
21+
<!-- Will generate up to 10 log files for a given day. During every rollover it will delete
22+
those that are older than 60 days, but keep the most recent 10 GB -->
23+
<RollingFile name="RollingFile-Appender"
24+
fileName="${log-path}/${log-name}.log"
25+
filePattern="${archive}/${log-name}.%d{yyyy-MM-dd}-%i.log.gz">
26+
27+
<PatternLayout pattern="[%-5level] %d{ISO8601}{GMT+0} [%t] %c{1} - %msg%n"/>
28+
29+
<Policies>
30+
<TimeBasedTriggeringPolicy/>
31+
<SizeBasedTriggeringPolicy size="10MB"/>
32+
</Policies>
33+
34+
<DefaultRolloverStrategy min="1" max="10">
35+
<Delete basePath="${archive}" maxDepth="1">
36+
<IfFileName glob="${log-name}*.log.gz"/>
37+
<IfLastModified age="60d">
38+
<IfAny>
39+
<IfAccumulatedFileSize exceeds="10 GB"/>
40+
</IfAny>
41+
</IfLastModified>
42+
</Delete>
43+
</DefaultRolloverStrategy>
44+
45+
</RollingFile>
46+
</Appenders>
47+
48+
<Loggers>
49+
<Root level="info">
50+
<AppenderRef ref="Console-Appender"/>
51+
<AppenderRef ref="RollingFile-Appender"/>
52+
</Root>
53+
<Logger name="net.corda" level="info" additivity="false">
54+
<AppenderRef ref="Console-Appender"/>
55+
<AppenderRef ref="RollingFile-Appender"/>
56+
</Logger>
57+
</Loggers>
58+
59+
</Configuration>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="info">
3+
<Appenders>
4+
<Console name="Console-Appender" target="SYSTEM_OUT">
5+
<PatternLayout>
6+
<pattern>
7+
[%-5level] %d{HH:mm:ss.SSS} [%t] %c{1}.%M - %msg%n
8+
</pattern>>
9+
</PatternLayout>
10+
</Console>
11+
</Appenders>
12+
<Loggers>
13+
<Root level="info">
14+
<AppenderRef ref="Console-Appender"/>
15+
</Root>
16+
<Logger name="net.corda" level="info" additivity="false">
17+
<AppenderRef ref="Console-Appender"/>
18+
</Logger>
19+
</Loggers>
20+
</Configuration>

0 commit comments

Comments
 (0)