Skip to content

Commit ddc2168

Browse files
committed
dollartohouse revamp
1 parent 3ca549e commit ddc2168

File tree

19 files changed

+163
-201
lines changed

19 files changed

+163
-201
lines changed

Tokens/dollartohousetoken/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ We can now check the issued house token in PartyB's vault. Since we issued it as
6868

6969
Note that HouseState token is an evolvable token which is a [LinearState](https://docs.corda.net/docs/corda-os/api-states.html#linearstate), thus we can check PartyB's vault to view the [EvolvableToken](https://training.corda.net/libraries/tokens-sdk/#evolvabletokentype)
7070

71-
run vaultQuery contractStateType: net.corda.examples.dollartohousetoken.states.HouseState
71+
run vaultQuery contractStateType: HouseState
7272

7373
Note the linearId of the HouseState token from the previous step, we will need it to perform our DvP opearation. Goto PartyB's shell to initiate the token sale.
7474

Tokens/dollartohousetoken/build.gradle

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ allprojects {
4242
mavenCentral()
4343
maven { url 'https://software.r3.com/artifactory/corda' }
4444
maven { url 'https://jitpack.io' }
45-
// Can be removed post-release - used to get nightly snapshot build.
4645
maven { url 'https://software.r3.com/artifactory/corda-lib' }
47-
maven { url 'https://software.r3.com/artifactory/corda-lib-dev' }
4846
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
4947
}
5048

@@ -68,15 +66,6 @@ apply plugin: 'net.corda.plugins.cordapp'
6866
apply plugin: 'net.corda.plugins.cordformation'
6967
apply plugin: 'net.corda.plugins.quasar-utils'
7068

71-
cordapp {
72-
info {
73-
name "CorDapp dollartohousetoken"
74-
vendor "Corda Open Source"
75-
targetPlatformVersion corda_platform_version.toInteger()
76-
minimumPlatformVersion corda_platform_version.toInteger()
77-
}
78-
}
79-
8069
sourceSets {
8170
main {
8271
resources {
@@ -105,7 +94,6 @@ dependencies {
10594
// Token SDK dependencies.
10695
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
10796
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
108-
// cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
10997
}
11098

11199
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
@@ -163,18 +151,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
163151

164152
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
165153
}
166-
167-
node {
168-
name "O=PartyD,L=Mumbai,C=IN"
169-
p2pPort 10016
170-
rpcSettings {
171-
address("localhost:10017")
172-
adminAddress("localhost:10057")
173-
}
174-
extraConfig = ['h2Settings.address' : 'localhost:20044']
175-
176-
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
177-
}
178154
}
179155

180156
task installQuasar(type: Copy) {

Tokens/dollartohousetoken/contracts/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ dependencies {
2323

2424
// Token SDK dependencies.
2525
cordaCompile "$tokens_release_group:tokens-contracts:$tokens_release_version"
26-
// cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
2726
}

Tokens/dollartohousetoken/contracts/src/main/java/net/corda/examples/dollartohousetoken/contracts/HouseContract.java renamed to Tokens/dollartohousetoken/contracts/src/main/java/net/corda/samples/dollartohousetoken/contracts/HouseContract.java

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

33
import com.r3.corda.lib.tokens.contracts.EvolvableTokenContract;
4-
import net.corda.examples.dollartohousetoken.states.HouseState;
4+
import net.corda.samples.dollartohousetoken.states.HouseState;
55
import net.corda.core.contracts.Contract;
66
import net.corda.core.transactions.LedgerTransaction;
77
import org.jetbrains.annotations.NotNull;
88

9+
import static net.corda.core.contracts.ContractsDSL.requireThat;
10+
911
/*
1012
* HouseContract governs the evolution of HouseState token. Evolvable tokens must extend the EvolvableTokenContract abstract class, it defines the
1113
* additionalCreateChecks and additionalCreateChecks method to add custom logic to validate while creation and update of evolvable tokens respectively.
1214
* */
1315
public class HouseContract extends EvolvableTokenContract implements Contract {
1416

15-
@Override
16-
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
17-
HouseState outputState = (HouseState) tx.getOutput(0);
18-
if(!(tx.getCommand(0).getSigners().contains(outputState.getIssuer().getOwningKey())))
19-
throw new IllegalArgumentException("Issuer Signature Required");
20-
}
17+
public static final String CONTRACT_ID = "net.corda.samples.dollartohousetoken.contracts.HouseContract";
2118

2219
@Override
2320
public void additionalCreateChecks(@NotNull LedgerTransaction tx) {
2421
// Write contract validation logic to be performed while creation of token
2522
HouseState outputState = (HouseState) tx.getOutput(0);
26-
if(outputState.getValuation().getQuantity() < 1)
27-
throw new IllegalArgumentException("Valuation must be greater than zero");
23+
requireThat( require -> {
24+
require.using("Valuation cannot be zero",
25+
outputState.getValuation().getQuantity() > 0);
26+
return null;
27+
});
2828
}
2929

3030
@Override

Tokens/dollartohousetoken/contracts/src/main/java/net/corda/examples/dollartohousetoken/states/HouseState.java renamed to Tokens/dollartohousetoken/contracts/src/main/java/net/corda/samples/dollartohousetoken/states/HouseState.java

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

3-
import net.corda.examples.dollartohousetoken.contracts.HouseContract;
3+
import net.corda.samples.dollartohousetoken.contracts.HouseContract;
44
import com.google.common.collect.ImmutableList;
55
import com.r3.corda.lib.tokens.contracts.states.EvolvableTokenType;
66
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;

Tokens/dollartohousetoken/contracts/src/test/java/net/corda/examples/dollartohousetoken/contracts/contracts/ContractTests.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.corda.samples.dollartohousetoken.contracts;
2+
3+
import net.corda.core.contracts.Amount;
4+
import net.corda.core.contracts.UniqueIdentifier;
5+
import net.corda.core.identity.CordaX500Name;
6+
import net.corda.samples.dollartohousetoken.states.HouseState;
7+
import net.corda.testing.core.TestIdentity;
8+
import net.corda.testing.node.MockServices;
9+
import org.junit.Test;
10+
11+
import java.util.Arrays;
12+
13+
import static net.corda.testing.node.NodeTestUtils.ledger;
14+
15+
public class ContractTests {
16+
private final MockServices ledgerServices = new MockServices();
17+
TestIdentity Operator = new TestIdentity(new CordaX500Name("Alice", "TestLand", "US"));
18+
19+
//sample tests
20+
@Test
21+
public void valuationCannotBeZero() {
22+
HouseState tokenPass = new HouseState(new UniqueIdentifier(),
23+
Arrays.asList(Operator.getParty()),
24+
Amount.parseCurrency("1000 USD"),
25+
10,"500sqft",
26+
"none","NYC");
27+
HouseState tokenFail = new HouseState(new UniqueIdentifier(),
28+
Arrays.asList(Operator.getParty()),
29+
Amount.parseCurrency("0 USD"),
30+
10,"500sqft",
31+
"none","NYC");
32+
ledger(ledgerServices, l -> {
33+
l.transaction(tx -> {
34+
tx.output(HouseContract.CONTRACT_ID, tokenFail);
35+
tx.command(Operator.getPublicKey(), new com.r3.corda.lib.tokens.contracts.commands.Create());
36+
return tx.fails();
37+
});
38+
l.transaction(tx -> {
39+
tx.output(HouseContract.CONTRACT_ID, tokenPass);
40+
tx.command(Operator.getPublicKey(), new com.r3.corda.lib.tokens.contracts.commands.Create());
41+
return tx.verifies();
42+
});
43+
return null;
44+
});
45+
}
46+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.corda.samples.dollartohousetoken.contracts;
2+
3+
4+
import net.corda.samples.dollartohousetoken.states.HouseState;
5+
import net.corda.testing.node.MockServices;
6+
import org.junit.Test;
7+
public class StateTests {
8+
private final MockServices ledgerServices = new MockServices();
9+
10+
//sample State tests
11+
@Test
12+
public void hasConstructionAreaFieldOfCorrectType() throws NoSuchFieldException {
13+
// Does the message field exist?
14+
HouseState.class.getDeclaredField("constructionArea");
15+
// Is the message field of the correct type?
16+
assert(HouseState.class.getDeclaredField("constructionArea").getType().equals(String.class));
17+
}
18+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
name=Test
1+
name=Dollartohousetoken CorDapp
22
group=com.dollartohousetoken
3-
version=0.1
3+
version=1.0

Tokens/dollartohousetoken/workflows/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ dependencies {
5151
cordapp project(":contracts")
5252

5353
// Token SDK dependencies.
54-
// cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
5554
cordaCompile "$tokens_release_group:tokens-workflows:$tokens_release_version"
5655
}
5756

0 commit comments

Comments
 (0)