Skip to content

Commit c995975

Browse files
authored
Merge pull request #33 from corda/tokenrevamp
Tokenrevamp
2 parents 65d81cc + 7c0b326 commit c995975

File tree

131 files changed

+1071
-1144
lines changed

Some content is hidden

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

131 files changed

+1071
-1144
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
**/.vscode/*
99
**/out/
1010
**/logs/
11+
**/node_modules/
1112
corda-nodeinfo/corda-nodeinfo.iml
1213
*~*

Tokens/README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
## samples-java/token-cordapps
1+
## Tokens CorDapp Samples
22

33
This folder features [TokenSDK](https://training.corda.net/libraries/tokens-sdk/) sample projects.
44

5-
### [bike market](./bikemarket):
6-
This sample Cordapp demonstrate some simple flows related to the token SDK.
5+
### [Fungible House Token](./fungiblehousetoken):
6+
This Cordapp serves as a basic example to demostrate how to tokenize an asset into [Fungible](https://training.corda.net/libraries/tokens-sdk/#fungibletoken) tokens in Corda utilizing the TokenSDK.
77

8-
### [dollar to Token DvP](./dollartohousetoken):
9-
This CorDapp serves as a basic example to create, issue and perform a DvP (Delivery vs Payment) of an [Evolvable](https://training.corda.net/libraries/tokens-sdk/#evolvabletokentype), [NonFungible](https://training.corda.net/libraries/tokens-sdk/#nonfungibletoken) token in Corda utilizing the TokenSDK.
8+
### [Bike Market](./bikemarket):
9+
This sample Cordapp demonstrate all four out-of-box TokenSDK flows (Create, Issue, Move, and Redeem flows). The cordapp demonstrate how to tokenize an asset as non-fungible tokens and excute a few transacting procedures.
10+
<p align="center">
11+
<img src="./bikemarket/diagram/pic1.png" alt="Corda" width="500">
12+
</p>
1013

11-
### [fungible house token](./fungiblehousetoken):
12-
This Cordapp serves as a basic example to create, issue, move [Fungible](https://training.corda.net/libraries/tokens-sdk/#fungibletoken) tokens in Corda utilizing the TokenSDK.
14+
### [Dollar To House Token](./dollartohousetoken):
15+
This CorDapp demonstrate a DvP (Delivery vs Payment) of an [Evolvable](https://training.corda.net/libraries/tokens-sdk/#evolvabletokentype), [NonFungible](https://training.corda.net/libraries/tokens-sdk/#nonfungibletoken) house token in Corda utilizing the TokenSDK.
1316

14-
### [stock pay dividend](./stockpaydividend):
17+
### [Stock Pay Dividend](./stockpaydividend):
1518
This CorDapp aims to demonstrate the usage of TokenSDK, especially the concept of [EvolvableToken](https://training.corda.net/libraries/tokens-sdk/#evolvabletokentype) which represents stock. You will find the StockState extends from EvolvableToken which allows the stock details(eg. announcing dividends) to be updated without affecting the parties who own the stock.
1619

17-
### [spaceships-javaAPIs](./spaceships-javaAPIs):
18-
This CorDapp contains examples using new [Java APIs](https://medium.com/corda/corda-tokens-made-easy-with-new-java-apis-83095693d72) introduced in Token SDK 1.2 - It makes of use of utility functions and the new Java Token Builders.
20+
### [Spaceships-javaAPIs](./spaceships-javaAPIs):
21+
This CorDapp contains examples using new [Java APIs](https://medium.com/corda/corda-tokens-made-easy-with-new-java-apis-83095693d72) introduced in Token SDK 1.2 - It makes of use of utility functions and the new Java Token Builders. The lastes Java APIs were indeed later implmented for all of the samples above as well.
22+
23+
### [Token To Friend](./tokentofriend):
24+
This CorDapp showcase a simple token issuance use case. You can attach a secret message with the token and your friend can retrive it with the credential that you inputed when creating the token. This cordapp come with a nice looking front end using Reactjs. Feel free to give a try on the app!
25+
<p align="center">
26+
<img src="./tokentofriend/diagram.png" alt="Corda" width="600">
27+
</p>

Tokens/bikemarket/README.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,11 @@ Throughout the sample, we will see how to create, transact, and redeem a Token.
3333

3434

3535
### Flows
36-
37-
38-
We'll create bike parts using the flows for CreateFrameToken and CreateWheelToken.
39-
40-
41-
We can create the Tokens with [CreateFrameToken](./workflows/src/main/java/net/corda/examples/bikemarket/flows/CreateFrameToken.java) and [CreateWheelToken](./workflows/src/main/java/net/corda/examples/bikemarket/flows/CreateWheelToken.java).
42-
43-
44-
We'll create a bike with the [IssueNewBike](./workflows/src/main/java/net/corda/examples/bikemarket/flows/IssueNewBike.java) flow.
45-
46-
47-
We can transfer bike Tokens using the [TransferBikeToken](./workflows/src/main/java/net/corda/examples/bikemarket/flows/TransferBikeTokens.java) flow.
48-
49-
50-
We can total bike Tokens using the [TotalPart](./workflows/src/main/java/net/corda/examples/bikemarket/flows/TotalParts.java) flow.
51-
52-
53-
We can transfer part Tokens using the [TransferPartToken](./workflows/src/main/java/net/corda/examples/bikemarket/flows/TransferPartTokens.java) flow.
36+
1. We'll create bike parts using the flows for `CreateFrameToken` and `CreateWheelToken`.
37+
2. We'll create a bike with the `IssueNewBike` flow.
38+
3. We can transfer bike Tokens using the `TransferBikeToken` flow.
39+
4. We can total bike Tokens using the `TotalPart` flow.
40+
5. We can transfer part Tokens using the `TransferPartToken` flow.
5441

5542

5643
## Usage
@@ -67,12 +54,12 @@ if you have any questions during setup, please go to https://docs.corda.net/gett
6754
Once all four nodes are started up, in BikeCo's node shell, run:
6855
```
6956
flow start CreateFrameToken frameSerial: F4561
70-
flow start CreateWheelToken wheelSerial: W7894
57+
flow start CreateWheelToken wheelsSerial: W7894
7158
```
7259
After this step, we have created 2 Tokens representing the physical bike part with unique serial number (which will be unique in the manufacturing).
7360
Then run:
7461
```
75-
flow start IssueNewBike frameSerial: F4561, wheelSerial: W7894, holder: LicensedDealership
62+
flow start IssueNewBike frameSerial: F4561, wheelsSerial: W7894, holder: LicensedDealership
7663
```
7764
This line of command will transfer the Tokens (2 Tokens together represents a single bike) to the licensed dealership.
7865

@@ -82,7 +69,7 @@ run vaultQuery contractStateType: com.r3.corda.lib.tokens.contracts.states.NonFu
8269
```
8370
Continue to the business flow, the licensed dealership will sell the bike to the Buyer. Run:
8471
```
85-
flow start TransferBikeToken frameSerial: F4561, wheelSerial: W7894, holder: Buyer
72+
flow start TransferBikeToken frameSerial: F4561, wheelsSerial: W7894, holder: Buyer
8673
```
8774

8875
Now we can check at the Buyer's node shell to see if the buyer received the Token by running the same `vaultQuery` we just ran at the dealership's shell.
@@ -95,7 +82,7 @@ flow start TotalPart part: frame, serialNumber: F4561
9582
At the buyer's shell, if we do the [vaultQuery](https://docs.corda.net/docs/corda-os/api-vault-query.html#api-vault-query) again, we will see we now only have a wheel Token (the frame Token is gone). With the wheel Token, we can sell
9683
this pair of wheels to the used parts agency. We will achieve it by running:
9784
```
98-
flow start TransferPartToken part: wheel, serialNumber: W7894, holder: UsedPartsAgency
85+
flow start TransferPartToken part: wheels, serialNumber: W7894, holder: UsedPartsAgency
9986
```
10087
At the end of the flow logic, we will find the frame Token is destroyed and the used parts agency holds the wheel Token.
10188

Tokens/bikemarket/build.gradle

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ buildscript {
33
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
44

55
ext {
6-
76
corda_release_group = constants.getProperty("cordaReleaseGroup")
87
corda_release_version = constants.getProperty("cordaVersion")
98
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
@@ -13,12 +12,10 @@ buildscript {
1312
slf4j_version = constants.getProperty("slf4jVersion")
1413
corda_platform_version = constants.getProperty("platformVersion").toInteger()
1514
guava_version = constants.getProperty("guavaVersion")
15+
1616
//Tokens
1717
tokens_release_group = 'com.r3.corda.lib.tokens'
1818
tokens_release_version = '1.2'
19-
//CI
20-
confidential_id_release_group = "com.r3.corda.lib.ci"
21-
confidential_id_release_version = "1.0"
2219
}
2320

2421
repositories {
@@ -45,9 +42,10 @@ allprojects {
4542
mavenCentral()
4643
maven { url 'https://software.r3.com/artifactory/corda' }
4744
maven { url 'https://jitpack.io' }
48-
// Can be removed post-release - used to get nightly snapshot build.
45+
//SDK lib
4946
maven { url 'https://software.r3.com/artifactory/corda-lib' }
50-
maven { url 'https://software.r3.com/artifactory/corda-tokens-dev' }
47+
//Gradle Plugins
48+
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
5149
}
5250

5351
tasks.withType(JavaCompile) {
@@ -73,15 +71,6 @@ apply plugin: 'net.corda.plugins.cordapp'
7371
apply plugin: 'net.corda.plugins.cordformation'
7472
apply plugin: 'net.corda.plugins.quasar-utils'
7573

76-
cordapp {
77-
info {
78-
name "CorDapp bikemarket"
79-
vendor "Corda Open Source"
80-
targetPlatformVersion corda_platform_version.toInteger()
81-
minimumPlatformVersion corda_platform_version.toInteger()
82-
}
83-
}
84-
8574
sourceSets {
8675
main {
8776
resources {
@@ -110,27 +99,15 @@ dependencies {
11099
// Token SDK dependencies.
111100
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
112101
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
113-
114-
// CI dependencies
115-
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
116-
117-
}
118-
cordapp {
119-
info {
120-
name "CorDapp Template"
121-
vendor "Corda Open Source"
122-
targetPlatformVersion corda_platform_version
123-
minimumPlatformVersion corda_platform_version
124-
}
125102
}
103+
126104
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
127105
nodeDefaults {
128106
projectCordapp {
129107
deploy = false
130108
}
131109
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
132110
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
133-
cordapp("$confidential_id_release_group:ci-workflows:$confidential_id_release_version")
134111
cordapp project(':contracts')
135112
cordapp project(':workflows')
136113
runSchemaMigration = true

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/contracts/FrameContract.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/contracts/WheelsContract.java

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.corda.samples.bikemarket.contracts;
2+
3+
import com.r3.corda.lib.tokens.contracts.EvolvableTokenContract;
4+
import net.corda.core.contracts.Contract;
5+
import net.corda.core.transactions.LedgerTransaction;
6+
import net.corda.samples.bikemarket.states.FrameTokenState;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import static net.corda.core.contracts.ContractsDSL.requireThat;
10+
11+
public class FrameContract extends EvolvableTokenContract implements Contract {
12+
13+
public static final String CONTRACT_ID = "net.corda.samples.bikemarket.contracts.FrameContract";
14+
15+
@Override
16+
public void additionalCreateChecks(@NotNull LedgerTransaction tx) {
17+
FrameTokenState newToken = (FrameTokenState) tx.getOutputStates().get(0);
18+
requireThat( require -> {
19+
require.using("Serial Number cannot be empty",(!newToken.getserialNum().equals("")));
20+
return null;
21+
});
22+
}
23+
24+
@Override
25+
public void additionalUpdateChecks(@NotNull LedgerTransaction tx) {
26+
/*This additional check does not apply to this use case.
27+
*This sample does not allow token update */
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.corda.samples.bikemarket.contracts;
2+
3+
import com.r3.corda.lib.tokens.contracts.EvolvableTokenContract;
4+
import net.corda.core.contracts.Contract;
5+
import net.corda.core.transactions.LedgerTransaction;
6+
import net.corda.samples.bikemarket.states.WheelsTokenState;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import static net.corda.core.contracts.ContractsDSL.requireThat;
10+
11+
public class WheelsContract extends EvolvableTokenContract implements Contract {
12+
13+
public static final String CONTRACT_ID = "net.corda.samples.bikemarket.contracts.WheelsContract";
14+
15+
@Override
16+
public void additionalCreateChecks(@NotNull LedgerTransaction tx) {
17+
WheelsTokenState newToken = (WheelsTokenState) tx.getOutputStates().get(0);
18+
requireThat( require -> {
19+
require.using("Serial Number cannot be empty",(!newToken.getserialNum().equals("")));
20+
return null;
21+
});
22+
}
23+
24+
@Override
25+
public void additionalUpdateChecks(@NotNull LedgerTransaction tx) {
26+
/*This additional check does not apply to this use case.
27+
*This sample does not allow token update */
28+
}
29+
}

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/states/FrameTokenState.java renamed to Tokens/bikemarket/contracts/src/main/java/net/corda/samples/bikemarket/states/FrameTokenState.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package net.corda.examples.bikemarket.states;
1+
package net.corda.samples.bikemarket.states;
22

33
import com.google.common.collect.ImmutableList;
44
import com.r3.corda.lib.tokens.contracts.states.EvolvableTokenType;
55
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
66
import net.corda.core.contracts.LinearPointer;
7-
import net.corda.examples.bikemarket.contracts.FrameContract;
7+
import net.corda.samples.bikemarket.contracts.FrameContract;
88
import net.corda.core.contracts.BelongsToContract;
99
import net.corda.core.contracts.UniqueIdentifier;
1010
import net.corda.core.identity.Party;
@@ -18,17 +18,17 @@ public class FrameTokenState extends EvolvableTokenType {
1818
private final Party maintainer;
1919
private final UniqueIdentifier uniqueIdentifier;
2020
private final int fractionDigits;
21-
private final String ModelNum;
21+
private final String serialNum;
2222

23-
public FrameTokenState(Party maintainer, UniqueIdentifier uniqueIdentifier, int fractionDigits, String ModelNum) {
23+
public FrameTokenState(Party maintainer, UniqueIdentifier uniqueIdentifier, int fractionDigits, String serialNum) {
2424
this.maintainer = maintainer;
2525
this.uniqueIdentifier = uniqueIdentifier;
2626
this.fractionDigits = fractionDigits;
27-
this.ModelNum = ModelNum;
27+
this.serialNum = serialNum;
2828
}
2929

30-
public String getModelNum() {
31-
return ModelNum;
30+
public String getserialNum() {
31+
return serialNum;
3232
}
3333

3434

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/states/WheelsTokenState.java renamed to Tokens/bikemarket/contracts/src/main/java/net/corda/samples/bikemarket/states/WheelsTokenState.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package net.corda.examples.bikemarket.states;
1+
package net.corda.samples.bikemarket.states;
22

33
import com.google.common.collect.ImmutableList;
44
import com.r3.corda.lib.tokens.contracts.states.EvolvableTokenType;
55
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
66
import net.corda.core.contracts.LinearPointer;
7-
import net.corda.examples.bikemarket.contracts.WheelsContract;
7+
import net.corda.samples.bikemarket.contracts.WheelsContract;
88
import net.corda.core.contracts.BelongsToContract;
99
import net.corda.core.contracts.UniqueIdentifier;
1010
import net.corda.core.identity.Party;
@@ -18,21 +18,22 @@ public class WheelsTokenState extends EvolvableTokenType {
1818
private final Party maintainer;
1919
private final UniqueIdentifier uniqueIdentifier;
2020
private final int fractionDigits;
21-
private final String modelNum;
21+
private final String serialNum;
2222

23-
public WheelsTokenState(Party maintainer, UniqueIdentifier uniqueIdentifier, int fractionDigits, String modelNum) {
23+
public WheelsTokenState(Party maintainer, UniqueIdentifier uniqueIdentifier, int fractionDigits, String serialNum) {
2424
this.maintainer = maintainer;
2525
this.uniqueIdentifier = uniqueIdentifier;
2626
this.fractionDigits = fractionDigits;
27-
this.modelNum = modelNum;
27+
this.serialNum = serialNum;
2828
}
2929

30-
public String getModelNum() {
31-
return modelNum;
30+
public String getserialNum() {
31+
return serialNum;
3232
}
3333
public Party getIssuer() {
3434
return maintainer;
3535
}
36+
3637
@Override
3738
public int getFractionDigits() {
3839
return this.fractionDigits;

0 commit comments

Comments
 (0)