Skip to content

Commit c434d5a

Browse files
authored
Merge pull request #31 from corda/2020Q4-token-sample
New Token sample
2 parents 8977a33 + 6830878 commit c434d5a

File tree

49 files changed

+18974
-0
lines changed

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

+18974
-0
lines changed
50.6 KB
Binary file not shown.

Tokens/tokentofriend/LICENCE

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.

Tokens/tokentofriend/README.md

Lines changed: 45 additions & 0 deletions
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

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

Tokens/tokentofriend/build.gradle

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

0 commit comments

Comments
 (0)