Skip to content

Commit 3b62376

Browse files
authored
Merge pull request #20 from corda/2020Q4-token-sample
New Token Sample
2 parents 25b507d + 9f46dea commit 3b62376

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+18829
-0
lines changed

Tokens/tokentofriend/App Design.pptx

50.6 KB
Binary file not shown.

Tokens/tokentofriend/LICENCE

+13
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.

Tokens/tokentofriend/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<p align="center">
2+
<img src="https://www.corda.net/wp-content/uploads/2016/11/fg005_corda_b.png" alt="Corda" width="500">
3+
</p>
4+
# tokentofriend
5+
6+
## Running the applications
7+
```
8+
./gradlew deployNodes
9+
./build/nodes/runnodes
10+
```
11+
12+
## Running in terminal:
13+
Go to the operator node:
14+
```
15+
flow start CreateMyToken myEmail: [email protected], recipients: [email protected], msg: Corda Number 1!
16+
17+
```
18+
then record the returned uuid
19+
```
20+
flow start IssueToken uuid: xxx-xxxx-xxxx-xxxx-xx
21+
```
22+
record the message returned, TokenId and storage node.
23+
24+
Go to that storage node terminal:
25+
```
26+
flow start QueryToken uuid: xxx-xxxx-xxxx-xxxx-xx, recipientEmai: [email protected]
27+
```
28+
29+
You should discover the message that was attached in the token.
30+
31+
## Runing in webapp
32+
Open a new window and run the blow code for token issuance
33+
```
34+
./gradlew runOperatoreServer
35+
```
36+
To retrieve the token, because most people will run the app locally, by default I have the gradle task to start only one storage node's web server.
37+
```
38+
./gradlew runUSWest1Server
39+
```
40+
After both servers started, go to localhost:10050 to issue a token and localhost:10053 to experience the retrieve. (The reason it is two different site is that communiticating among multiple local server is prohibit by CORS policy. In production environment, we do not need to go to a different site for retrieve.)
41+
42+
43+
44+
45+

Tokens/tokentofriend/TRADEMARK

+4
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/.

Tokens/tokentofriend/build.gradle

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
buildscript { //properties that you need to build the project
2+
3+
Properties constants = new Properties()
4+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
5+
6+
ext {
7+
corda_release_group = constants.getProperty("cordaReleaseGroup")
8+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
9+
corda_release_version = constants.getProperty("cordaVersion")
10+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
11+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
12+
kotlin_version = constants.getProperty("kotlinVersion")
13+
junit_version = constants.getProperty("junitVersion")
14+
quasar_version = constants.getProperty("quasarVersion")
15+
log4j_version = constants.getProperty("log4jVersion")
16+
slf4j_version = constants.getProperty("slf4jVersion")
17+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
18+
//springboot
19+
spring_boot_version = '2.0.2.RELEASE'
20+
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
21+
//Token
22+
tokens_release_group = 'com.r3.corda.lib.tokens'
23+
tokens_release_version = '1.2'
24+
//CI
25+
confidential_id_release_group = "com.r3.corda.lib.ci"
26+
confidential_id_release_version = "1.0"
27+
}
28+
29+
repositories {
30+
mavenLocal()
31+
mavenCentral()
32+
jcenter()
33+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
34+
}
35+
36+
dependencies {
37+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
38+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
39+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
40+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
41+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
42+
}
43+
}
44+
45+
allprojects { //Properties that you need to compile your project (The application)
46+
apply from: "${rootProject.projectDir}/repositories.gradle"
47+
apply plugin: 'kotlin'
48+
49+
repositories {
50+
mavenLocal()
51+
jcenter()
52+
mavenCentral()
53+
maven { url 'https://software.r3.com/artifactory/corda' }
54+
maven { url 'https://jitpack.io' }
55+
//corda lib
56+
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-lib' }
57+
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-tokens-dev' }
58+
59+
}
60+
61+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
62+
kotlinOptions {
63+
languageVersion = "1.2"
64+
apiVersion = "1.2"
65+
jvmTarget = "1.8"
66+
javaParameters = true // Useful for reflection.
67+
}
68+
}
69+
70+
jar {
71+
// This makes the JAR's SHA-256 hash repeatable.
72+
preserveFileTimestamps = false
73+
reproducibleFileOrder = true
74+
}
75+
}
76+
77+
apply plugin: 'net.corda.plugins.cordapp'
78+
apply plugin: 'net.corda.plugins.cordformation'
79+
apply plugin: 'net.corda.plugins.quasar-utils'
80+
81+
sourceSets {
82+
main {
83+
resources {
84+
srcDir rootProject.file("config/dev")
85+
}
86+
}
87+
}
88+
89+
//Module dependencis
90+
dependencies {
91+
// Corda dependencies.
92+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
93+
cordaRuntime "$corda_release_group:corda-node-api:$corda_release_version"
94+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
95+
96+
// CorDapp dependencies.
97+
cordapp project(":workflows")
98+
cordapp project(":contracts")
99+
100+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
101+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
102+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
103+
104+
// Token SDK dependencies.
105+
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
106+
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
107+
// CI dependencies
108+
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
109+
}
110+
111+
//Task to build the jar for ganache.
112+
task ganache {
113+
subprojects {
114+
if (it.project.name != "clients") {
115+
dependsOn jar
116+
doLast {
117+
copy {
118+
from "${buildDir}/libs"
119+
into "${rootDir}/build/libs"
120+
}
121+
}
122+
}
123+
}
124+
}
125+
126+
//Task to deploy the nodes in order to bootstrap a network
127+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
128+
129+
/* This property will load the CorDapps to each of the node by default, including the Notary. You can find them
130+
* in the cordapps folder of the node at build/nodes/Notary/cordapps. However, the notary doesn't really understand
131+
* the notion of cordapps. In production, Notary does not need cordapps as well. This is just a short cut to load
132+
* the Corda network bootstrapper.
133+
*/
134+
nodeDefaults {
135+
projectCordapp {
136+
deploy = false
137+
}
138+
cordapp project(':contracts')
139+
cordapp project(':workflows')
140+
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
141+
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
142+
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
143+
runSchemaMigration = true //This configuration is for any CorDapps with custom schema, We will leave this as true to avoid
144+
//problems for developers who are not familiar with Corda. If you are not using custom schemas, you can change
145+
//it to false for quicker project compiling time.
146+
}
147+
node {
148+
name "O=Notary,L=London,C=GB"
149+
notary = [validating : false]
150+
p2pPort 10002
151+
rpcSettings {
152+
address("localhost:10003")
153+
adminAddress("localhost:10043")
154+
}
155+
}
156+
node {
157+
name "O=Operator,L=London,C=GB"
158+
p2pPort 10005
159+
rpcSettings {
160+
address("localhost:10006")
161+
adminAddress("localhost:10046")
162+
}
163+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
164+
}
165+
node {
166+
name "O=USEast3,L=New York,C=US"
167+
p2pPort 10008
168+
rpcSettings {
169+
address("localhost:10009")
170+
adminAddress("localhost:10049")
171+
}
172+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
173+
}
174+
node {
175+
name "O=AsiaEast,L=Beijing,C=CN"
176+
p2pPort 10011
177+
rpcSettings {
178+
address("localhost:10012")
179+
adminAddress("localhost:10052")
180+
}
181+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
182+
}
183+
node {
184+
name "O=USWest1,L=San Diego,C=US"
185+
p2pPort 10014
186+
rpcSettings {
187+
address("localhost:10015")
188+
adminAddress("localhost:10055")
189+
}
190+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
191+
}
192+
193+
}
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
buildscript {
2+
repositories {
3+
maven {
4+
url = uri("https://plugins.gradle.org/m2/")
5+
}
6+
}
7+
dependencies {
8+
classpath("com.moowork.gradle:gradle-node-plugin:1.3.1")
9+
}
10+
}
11+
12+
apply plugin: "com.moowork.node"
13+
apply plugin: 'org.springframework.boot'
14+
15+
sourceSets {
16+
main {
17+
resources {
18+
srcDir rootProject.file("config/dev")
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
25+
implementation 'com.google.code.gson:gson:2.8.5'
26+
27+
// Corda dependencies.
28+
compile "$corda_release_group:corda-rpc:$corda_release_version"
29+
30+
// CorDapp dependencies.
31+
compile project(":contracts")
32+
compile project(":workflows")
33+
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
34+
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
35+
}
36+
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
37+
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
38+
compile "org.slf4j:jul-to-slf4j:$slf4j_version"
39+
}
40+
41+
42+
springBoot {
43+
mainClassName = "com.tokentofriend.webserver.ServerKt"
44+
}
45+
46+
task copyWebApp(type: Copy) {
47+
from 'src/main/webapp/build'
48+
into 'build/resources/main/static/.'
49+
}
50+
51+
task appNpmInstall(type: NpmTask) {
52+
description = "Installs all dependencies from package.json"
53+
workingDir = file("${project.projectDir}/src/main/webapp")
54+
args = ["install"]
55+
}
56+
57+
task appNpmBuild(type: NpmTask) {
58+
description = "Builds production version of the webapp"
59+
workingDir = file("${project.projectDir}/src/main/webapp")
60+
args = ["run", "build"]
61+
}
62+
63+
appNpmBuild.dependsOn appNpmInstall
64+
copyWebApp.dependsOn appNpmBuild
65+
compileJava.dependsOn copyWebApp
66+
67+
node {
68+
download = true
69+
70+
// Set the work directory for unpacking node
71+
workDir = file("${project.buildDir}/nodejs")
72+
73+
// Set the work directory for NPM
74+
npmWorkDir = file("${project.buildDir}/npm")
75+
}
76+
77+
/* The Client is the communication channel between the external and the node. This task will help you immediately
78+
* execute your rpc methods in the main method of the client.kt. You can somewhat see this as a quick test of making
79+
* RPC calls to your nodes.
80+
*/
81+
task runOperatorClient(type: JavaExec, dependsOn: assemble) {
82+
classpath = sourceSets.main.runtimeClasspath
83+
main = 'com.tokentofriend.ClientKt'
84+
args 'localhost:10006', 'user1', 'test'
85+
}
86+
87+
/* This task will start the springboot server that connects to your node (via RPC connection). All of the http requests
88+
* are in the Controller file. You can leave the Server.kt and NodeRPCConnection.kt file untouched for your use.
89+
*/
90+
task runOperatoreServer(type: JavaExec, dependsOn: assemble) {
91+
classpath = sourceSets.main.runtimeClasspath
92+
main = 'com.tokentofriend.webserver.ServerKt'
93+
args '--server.port=10050', '--config.rpc.host=localhost', '--config.rpc.port=10006', '--config.rpc.username=user1', '--config.rpc.password=test'
94+
}
95+
96+
/* This task will start the springboot server that connects to your node (via RPC connection). All of the http requests
97+
* are in the Controller file. You can leave the Server.kt and NodeRPCConnection.kt file untouched for your use.
98+
*/
99+
task runUSWest1Server(type: JavaExec, dependsOn: assemble) {
100+
classpath = sourceSets.main.runtimeClasspath
101+
main = 'com.tokentofriend.webserver.ServerKt'
102+
args '--server.port=10053', '--config.rpc.host=localhost', '--config.rpc.port=10015', '--config.rpc.username=user1', '--config.rpc.password=test'
103+
}

0 commit comments

Comments
 (0)