Skip to content

Commit 3ca549e

Browse files
committed
bike market revamp
1 parent 148a658 commit 3ca549e

File tree

18 files changed

+197
-142
lines changed

18 files changed

+197
-142
lines changed

Tokens/bikemarket/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ if you have any questions during setup, please go to https://docs.corda.net/gett
6767
Once all four nodes are started up, in BikeCo's node shell, run:
6868
```
6969
flow start CreateFrameToken frameSerial: F4561
70-
flow start CreateWheelToken wheelSerial: W7894
70+
flow start CreateWheelToken wheelsSerial: W7894
7171
```
7272
After this step, we have created 2 Tokens representing the physical bike part with unique serial number (which will be unique in the manufacturing).
7373
Then run:
7474
```
75-
flow start IssueNewBike frameSerial: F4561, wheelSerial: W7894, holder: LicensedDealership
75+
flow start IssueNewBike frameSerial: F4561, wheelsSerial: W7894, holder: LicensedDealership
7676
```
7777
This line of command will transfer the Tokens (2 Tokens together represents a single bike) to the licensed dealership.
7878

@@ -82,7 +82,7 @@ run vaultQuery contractStateType: com.r3.corda.lib.tokens.contracts.states.NonFu
8282
```
8383
Continue to the business flow, the licensed dealership will sell the bike to the Buyer. Run:
8484
```
85-
flow start TransferBikeToken frameSerial: F4561, wheelSerial: W7894, holder: Buyer
85+
flow start TransferBikeToken frameSerial: F4561, wheelsSerial: W7894, holder: Buyer
8686
```
8787

8888
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 +95,7 @@ flow start TotalPart part: frame, serialNumber: F4561
9595
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
9696
this pair of wheels to the used parts agency. We will achieve it by running:
9797
```
98-
flow start TransferPartToken part: wheel, serialNumber: W7894, holder: UsedPartsAgency
98+
flow start TransferPartToken part: wheels, serialNumber: W7894, holder: UsedPartsAgency
9999
```
100100
At the end of the flow logic, we will find the frame Token is destroyed and the used parts agency holds the wheel Token.
101101

Tokens/bikemarket/build.gradle

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ apply plugin: 'net.corda.plugins.cordapp'
7373
apply plugin: 'net.corda.plugins.cordformation'
7474
apply plugin: 'net.corda.plugins.quasar-utils'
7575

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-
8576
sourceSets {
8677
main {
8778
resources {
@@ -115,14 +106,7 @@ dependencies {
115106
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
116107

117108
}
118-
cordapp {
119-
info {
120-
name "CorDapp Template"
121-
vendor "Corda Open Source"
122-
targetPlatformVersion corda_platform_version
123-
minimumPlatformVersion corda_platform_version
124-
}
125-
}
109+
126110
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
127111
nodeDefaults {
128112
projectCordapp {
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
package net.corda.examples.bikemarket.contracts;
1+
package net.corda.samples.bikemarket.contracts;
22

33
import com.r3.corda.lib.tokens.contracts.EvolvableTokenContract;
44
import net.corda.core.contracts.Contract;
55
import net.corda.core.transactions.LedgerTransaction;
6+
import net.corda.samples.bikemarket.states.FrameTokenState;
67
import org.jetbrains.annotations.NotNull;
78

9+
import static net.corda.core.contracts.ContractsDSL.requireThat;
10+
811
public class FrameContract extends EvolvableTokenContract implements Contract {
12+
13+
public static final String CONTRACT_ID = "net.corda.samples.bikemarket.contracts.FrameContract";
14+
915
@Override
1016
public void additionalCreateChecks(@NotNull LedgerTransaction tx) {
11-
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+
});
1222
}
1323

1424
@Override
1525
public void additionalUpdateChecks(@NotNull LedgerTransaction tx) {
16-
26+
/*This additional check does not apply to this use case.
27+
*This sample does not allow token update */
1728
}
1829
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
package net.corda.examples.bikemarket.contracts;
1+
package net.corda.samples.bikemarket.contracts;
22

33
import com.r3.corda.lib.tokens.contracts.EvolvableTokenContract;
44
import net.corda.core.contracts.Contract;
55
import net.corda.core.transactions.LedgerTransaction;
6+
import net.corda.samples.bikemarket.states.WheelsTokenState;
67
import org.jetbrains.annotations.NotNull;
78

9+
import static net.corda.core.contracts.ContractsDSL.requireThat;
10+
811
public class WheelsContract extends EvolvableTokenContract implements Contract {
12+
13+
public static final String CONTRACT_ID = "net.corda.samples.bikemarket.contracts.WheelsContract";
14+
915
@Override
1016
public void additionalCreateChecks(@NotNull LedgerTransaction tx) {
11-
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+
});
1222
}
1323

1424
@Override
1525
public void additionalUpdateChecks(@NotNull LedgerTransaction tx) {
16-
26+
/*This additional check does not apply to this use case.
27+
*This sample does not allow token update */
1728
}
1829
}

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/samples/bikemarket/states/WheelsTokenState.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.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,17 +18,17 @@ 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;
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1-
package net.corda.examples.bikemarket.contracts;
1+
package net.corda.samples.bikemarket.contracts;
22

3+
import net.corda.core.contracts.UniqueIdentifier;
4+
import net.corda.core.identity.CordaX500Name;
5+
import net.corda.samples.bikemarket.states.FrameTokenState;
6+
import net.corda.testing.core.TestIdentity;
37
import net.corda.testing.node.MockServices;
48
import org.junit.Test;
9+
import static net.corda.testing.node.NodeTestUtils.ledger;
510

611
public class ContractTests {
712
private final MockServices ledgerServices = new MockServices();
13+
TestIdentity Operator = new TestIdentity(new CordaX500Name("Alice", "TestLand", "US"));
814

15+
//sample tests
916
@Test
10-
public void dummyTest() {
11-
17+
public void SerialNumberCannotBeEmpty() {
18+
FrameTokenState tokenPass = new FrameTokenState(Operator.getParty(),new UniqueIdentifier(),0,"8742");
19+
FrameTokenState tokenFail = new FrameTokenState(Operator.getParty(),new UniqueIdentifier(),0,"");
20+
ledger(ledgerServices, l -> {
21+
l.transaction(tx -> {
22+
tx.output(FrameContract.CONTRACT_ID, tokenFail);
23+
tx.command(Operator.getPublicKey(), new com.r3.corda.lib.tokens.contracts.commands.Create()); // Wrong type.
24+
return tx.fails();
25+
});
26+
l.transaction(tx -> {
27+
tx.output(FrameContract.CONTRACT_ID, tokenPass);
28+
tx.command(Operator.getPublicKey(), new com.r3.corda.lib.tokens.contracts.commands.Create()); // Wrong type.
29+
return tx.verifies();
30+
});
31+
return null;
32+
});
1233
}
1334
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
package net.corda.samples.bikemarket.contracts;public class StateTests {
2-
}
1+
package net.corda.samples.bikemarket.contracts;
2+
3+
import net.corda.samples.bikemarket.states.WheelsTokenState;
4+
import net.corda.testing.node.MockServices;
5+
import org.junit.Test;
6+
public class StateTests {
7+
private final MockServices ledgerServices = new MockServices();
8+
9+
//sample State tests
10+
@Test
11+
public void hasSerialNumFieldOfCorrectType() throws NoSuchFieldException {
12+
// Does the message field exist?
13+
WheelsTokenState.class.getDeclaredField("serialNum");
14+
// Is the message field of the correct type?
15+
assert(WheelsTokenState.class.getDeclaredField("serialNum").getType().equals(String.class));
16+
}
17+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
name=Test
1+
name=Bikemarket Cordapp
22
group=com.bikemarket
3-
version=0.1
3+
version=1.0

Tokens/bikemarket/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)