Skip to content

Commit ec566d8

Browse files
committed
commit of contracts sample
1 parent 9bc9adc commit ec566d8

File tree

37 files changed

+2187
-0
lines changed

37 files changed

+2187
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!groovy
2+
/**
3+
* Jenkins pipeline to build the java CorDapp template
4+
*/
5+
6+
/**
7+
* Kill already started job.
8+
* Assume new commit takes precedence and results from previousunfinished builds are not required.
9+
* This feature doesn't play well with disableConcurrentBuilds() option
10+
*/
11+
@Library('corda-shared-build-pipeline-steps')
12+
import static com.r3.build.BuildControl.killAllExistingBuildsForJob
13+
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
14+
15+
pipeline {
16+
agent {
17+
label 'eight-cores'
18+
}
19+
options {
20+
ansiColor('xterm')
21+
timestamps()
22+
timeout(3*60) // 3 hours
23+
buildDiscarder(logRotator(daysToKeepStr: '7', artifactDaysToKeepStr: '7'))
24+
}
25+
stages {
26+
stage('Build') {
27+
steps {
28+
sh './gradlew --no-daemon -s clean build test deployNodes'
29+
}
30+
}
31+
}
32+
post {
33+
cleanup {
34+
deleteDir()
35+
}
36+
}
37+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Eclipse, ctags, Mac metadata, log files
2+
.classpath
3+
.project
4+
tags
5+
.DS_Store
6+
*.log
7+
*.log.gz
8+
*.orig
9+
10+
.gradle
11+
12+
# General build files
13+
**/build/*
14+
!docs/build/*
15+
16+
lib/dokka.jar
17+
18+
### JetBrains template
19+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
20+
21+
*.iml
22+
23+
## Directory-based project format:
24+
#.idea
25+
26+
# if you remove the above rule, at least ignore the following:
27+
28+
# Specific files to avoid churn
29+
.idea/*.xml
30+
.idea/copyright
31+
.idea/jsLibraryMappings.xml
32+
33+
# User-specific stuff:
34+
.idea/tasks.xml
35+
.idea/dictionaries
36+
37+
# Sensitive or high-churn files:
38+
.idea/dataSources.ids
39+
.idea/dataSources.xml
40+
.idea/sqlDataSources.xml
41+
.idea/dynamic.xml
42+
.idea/uiDesigner.xml
43+
44+
# Gradle:
45+
.idea/libraries
46+
47+
# Mongo Explorer plugin:
48+
.idea/mongoSettings.xml
49+
50+
## File-based project format:
51+
*.ipr
52+
*.iws
53+
54+
## Plugin-specific files:
55+
56+
# IntelliJ
57+
/out/
58+
/workflows/out/
59+
/contracts/out/
60+
clients/out/
61+
*/bin/*
62+
63+
# mpeltonen/sbt-idea plugin
64+
.idea_modules/
65+
66+
# JIRA plugin
67+
atlassian-ide-plugin.xml
68+
69+
# Crashlytics plugin (for Android Studio and IntelliJ)
70+
com_crashlytics_export_strings.xml
71+
crashlytics.properties
72+
crashlytics-build.properties
73+
74+
# docs related
75+
docs/virtualenv/
76+
77+
# if you use the installQuasar task
78+
lib
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
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.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Contract SDK - Record Player Maintenance
2+
3+
4+
If you're familiar with record players you probably know how difficult it is to make sure that they run in pristine condition, especially if it's a collectible.
5+
6+
![](blob:https://imgur.com/04eac7f3-0849-424d-93ca-f2c11d9b3d0d)
7+
8+
9+
This cordapp simulates how you could model the process of a limited edition record player (the cordagraf) that is manufactured and issued to specific dealers, and those dealers are the only entities that can service those record players after the fact and report stats back to the manufacturer about how the players are being used.
10+
11+
Record Players are issued as `LinearState`s and are updated by dealers, that act functionally as the only entity that can update the `RecordPlayer` state.
12+
13+
14+
### Using the Contract SDK
15+
16+
The [contract sdk](https://github.com/corda/contract-sdk) is a series of Annotations that you can use in your corda contracts. It's great for putting together cleaner contract code and writing it faster.
17+
18+
This repository demonstrates how you can configure and use it in your own projects.
19+
20+
Configuration is essentially three small steps:
21+
22+
- adding `maven { url 'https://software.r3.com/artifactory/corda-lib-dev' }` to `repositories.gradle`
23+
- adding `compile "com.r3.corda.lib.contracts:contract-sdk:0.9-SNAPSHOT"` to the `build.gradle` file of your contract module in your cordapp
24+
- adding the annotations to your apps!
25+
26+
27+
To show how convenient this can be, here's an example demonstrating how to configure a simple issuance command with one output and no inputs.
28+
29+
```java
30+
// note the annotations here from the Contracts SDK
31+
@RequireNumberOfStatesOnInput(value = 0)
32+
@RequireNumberOfStatesOnOutput(value = 1)
33+
class Issue implements Commands {}
34+
```
35+
36+
If you've written contracts before you might be used to outlining the verify method, applying a conditional for issuance commands and configuring a lot of the same verification for contract inputs. This removes the need for those tools.
37+
38+
Take a look at the small RecordPlayerContract sample in this repository to see how this works in practice.
39+
40+
41+
### Sources
42+
43+
If you're looking to find more information on record players specifically, I included some sources for how we modeled record players in the state class.
44+
45+
- [You can find much more information on the contract sdk on github here](https://github.com/corda/contract-sdk)
46+
- [The notes on the number of turns in a record player cartridge coil was sourced from here](https://www.vinylengine.com/turntable_forum/viewtopic.php?t=35449)
47+
- [The info on other aspects of amplifiers was sourced from here](https://www.cambridgeaudio.com/usa/en/blog/amplifier-specifications)
48+
49+
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: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
18+
// springboot
19+
spring_boot_version = '2.0.2.RELEASE'
20+
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
21+
}
22+
23+
repositories {
24+
mavenLocal()
25+
mavenCentral()
26+
jcenter()
27+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
28+
}
29+
30+
dependencies {
31+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
32+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
33+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
34+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
35+
}
36+
}
37+
38+
allprojects {//Properties that you need to compile your project (The application)
39+
apply from: "${rootProject.projectDir}/repositories.gradle"
40+
apply plugin: 'java'
41+
42+
repositories {
43+
mavenLocal()
44+
jcenter()
45+
mavenCentral()
46+
maven { url 'https://software.r3.com/artifactory/corda' }
47+
maven { url 'https://jitpack.io' }
48+
}
49+
50+
tasks.withType(JavaCompile) {
51+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
52+
}
53+
54+
jar {
55+
// This makes the JAR's SHA-256 hash repeatable.
56+
preserveFileTimestamps = false
57+
reproducibleFileOrder = true
58+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
59+
}
60+
}
61+
62+
apply plugin: 'net.corda.plugins.cordapp'
63+
apply plugin: 'net.corda.plugins.cordformation'
64+
apply plugin: 'net.corda.plugins.quasar-utils'
65+
66+
sourceSets {
67+
main {
68+
resources {
69+
srcDir rootProject.file("config/dev")
70+
}
71+
}
72+
}
73+
//Module dependencis
74+
dependencies {
75+
// Corda dependencies.
76+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
77+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
78+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
79+
80+
// CorDapp dependencies.
81+
cordapp project(":contracts")
82+
cordapp project(":workflows")
83+
84+
85+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
86+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
87+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
88+
}
89+
90+
91+
//Task to deploy the nodes in order to bootstrap a network
92+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
93+
94+
/* This property will load the CorDapps to each of the node by default, including the Notary. You can find them
95+
* in the cordapps folder of the node at build/nodes/Notary/cordapps. However, the notary doesn't really understand
96+
* the notion of cordapps. In production, Notary does not need cordapps as well. This is just a short cut to load
97+
* the Corda network bootstrapper.
98+
*/
99+
nodeDefaults {
100+
projectCordapp {
101+
deploy = false
102+
}
103+
cordapp project(':contracts')
104+
cordapp project(':workflows')
105+
runSchemaMigration = true //This configuration is for any CorDapps with custom schema, We will leave this as true to avoid
106+
//problems for developers who are not familiar with Corda. If you are not using custom schemas, you can change
107+
//it to false for quicker project compiling time.
108+
}
109+
node {
110+
name "O=Notary,L=London,C=GB"
111+
notary = [validating : false]
112+
p2pPort 10002
113+
rpcSettings {
114+
address("localhost:10010")
115+
adminAddress("localhost:10011")
116+
}
117+
}
118+
node {
119+
name "O=Manufacturer,L=London,C=GB"
120+
p2pPort 10005
121+
rpcSettings {
122+
address("localhost:10021")
123+
adminAddress("localhost:10022")
124+
}
125+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
126+
}
127+
128+
node {
129+
name "O=Alice Audio,L=New York,C=US"
130+
p2pPort 10008
131+
rpcSettings {
132+
address("localhost:10030")
133+
adminAddress("localhost:10033")
134+
}
135+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
136+
}
137+
138+
node {
139+
name "O=Bob Hustle Records,L=Egypt,C=US"
140+
p2pPort 10008
141+
rpcSettings {
142+
address("localhost:10040")
143+
adminAddress("localhost:10044")
144+
}
145+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
146+
}
147+
148+
node {
149+
name "O=Carl Chords,L=Greece,C=US"
150+
p2pPort 10008
151+
rpcSettings {
152+
address("localhost:10040")
153+
adminAddress("localhost:10044")
154+
}
155+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
156+
}
157+
158+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'org.springframework.boot'
2+
3+
sourceSets {
4+
main {
5+
resources {
6+
srcDir rootProject.file("config/dev")
7+
}
8+
}
9+
}
10+
11+
dependencies {
12+
// Corda dependencies.
13+
compile "$corda_release_group:corda-rpc:$corda_release_version"
14+
15+
// CorDapp dependencies.
16+
compile project(":contracts")
17+
compile project(":workflows")
18+
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
19+
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
20+
}
21+
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
22+
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
23+
compile "org.slf4j:jul-to-slf4j:$slf4j_version"
24+
}
25+
26+
springBoot {
27+
mainClassName = "com.template.webserver.Server"
28+
}
29+
30+
/* The Client is the communication channel between the external and the node. This task will help you immediately
31+
* execute your rpc methods in the main method of the client.kt. You can somewhat see this as a quick test of making
32+
* RPC calls to your nodes.
33+
*/
34+
task runTemplateClient(type: JavaExec, dependsOn: assemble) {
35+
classpath = sourceSets.main.runtimeClasspath
36+
main = 'com.template.Client'
37+
args 'localhost:10006', 'user1', 'test'
38+
}
39+
40+
/* This task will start the springboot server that connects to your node (via RPC connection). All of the http requests
41+
* are in the Controller file. You can leave the Server.kt and NodeRPCConnection.kt file untouched for your use.
42+
*/
43+
task runTemplateServer(type: JavaExec, dependsOn: assemble) {
44+
classpath = sourceSets.main.runtimeClasspath
45+
main = 'com.template.webserver.Starter'
46+
args '--server.port=10050', '--config.rpc.host=localhost', '--config.rpc.port=10006', '--config.rpc.username=user1', '--config.rpc.password=test'
47+
}

0 commit comments

Comments
 (0)