Skip to content

Commit de000f8

Browse files
committed
tictacthor revamp
1 parent 057315f commit de000f8

File tree

30 files changed

+239
-209
lines changed

30 files changed

+239
-209
lines changed

Accounts/tictacthor/build.gradle

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ buildscript {
1515
log4j_version = constants.getProperty("log4jVersion")
1616
slf4j_version = constants.getProperty("slf4jVersion")
1717
corda_platform_version = constants.getProperty("platformVersion").toInteger()
18+
1819
//springboot
1920
spring_boot_version = '2.0.2.RELEASE'
2021
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
22+
2123
//account
2224
accounts_release_group = 'com.r3.corda.lib.accounts'
2325
accounts_release_version = '1.0'
@@ -30,11 +32,7 @@ buildscript {
3032
mavenLocal()
3133
mavenCentral()
3234
jcenter()
33-
maven { url 'http://software.r3.com/artifactory/corda-lib-dev' }
34-
maven { url 'http://software.r3.com/artifactory/corda-lib' }
35-
maven { url 'https://software.r3.com/artifactory/corda' }
36-
// Corda dependencies for the patched Quasar version
37-
maven { url "https://software.r3.com/artifactory/corda-dependencies" } // access to the patched Quasar version
35+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
3836
}
3937

4038
dependencies {
@@ -55,11 +53,11 @@ allprojects {
5553
jcenter()
5654
mavenCentral()
5755
maven { url 'https://software.r3.com/artifactory/corda' }
58-
// Can be removed post-release - used to get nightly snapshot build.
59-
maven { url 'https://software.r3.com/artifactory/corda-lib' }
60-
maven { url 'https://software.r3.com/artifactory/corda-lib-dev' }
6156
maven { url 'https://jitpack.io' }
62-
maven { url "https://repo.gradle.org/gradle/libs-releases-local" }
57+
//SDK lib
58+
maven { url 'https://software.r3.com/artifactory/corda-lib' }
59+
//Gradle Plugins
60+
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
6361
}
6462

6563
tasks.withType(JavaCompile) {
@@ -109,30 +107,6 @@ dependencies {
109107
cordapp "$accounts_release_group:accounts-workflows:$accounts_release_version"
110108
}
111109

112-
cordapp {
113-
info {
114-
name "CorDapp tictacthor"
115-
vendor "Corda Open Source"
116-
targetPlatformVersion corda_platform_version
117-
minimumPlatformVersion corda_platform_version
118-
}
119-
}
120-
121-
task ganache {
122-
subprojects {
123-
if (it.project.name != "clients") {
124-
dependsOn jar
125-
doLast {
126-
copy {
127-
from "${buildDir}/libs"
128-
into "${rootDir}/build/libs"
129-
}
130-
}
131-
}
132-
}
133-
}
134-
135-
136110
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
137111
nodeDefaults {
138112
projectCordapp {
@@ -173,15 +147,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
173147
}
174148
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
175149
}
176-
// node {
177-
// name "O=Observer,L=Chicago,C=US,CN=John"
178-
// p2pPort 10011
179-
// rpcSettings {
180-
// address("localhost:10010")
181-
// adminAddress("localhost:10050")
182-
// }
183-
// rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
184-
// }
185150
}
186151

187152
task installQuasar(type: Copy) {

Accounts/tictacthor/clients/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ dependencies {
2727
}
2828

2929
springBoot {
30-
mainClassName = "com.tictacthor.webserver.Server"
30+
mainClassName = "net.corda.samples.tictacthor.webserver"
3131
}
3232

3333
task bootRunDevRel(type: JavaExec, dependsOn: jar) {
3434
classpath = sourceSets.main.runtimeClasspath
35-
main = 'com.tictacthor.webserver.Starter'
35+
main = 'net.corda.samples.tictacthor.webserver.Starter'
3636
args '--server.port=8080', '--config.rpc.host=localhost', '--config.rpc.port=10006', '--config.rpc.username=user1', '--config.rpc.password=test'
3737
}
3838

3939
task bootRunSOE(type: JavaExec, dependsOn: jar) {
4040
classpath = sourceSets.main.runtimeClasspath
41-
main = 'com.tictacthor.webserver.Starter'
41+
main = 'net.corda.samples.tictacthor.webserver.Starter'
4242
args '--server.port=8090', '--config.rpc.host=localhost', '--config.rpc.port=10009', '--config.rpc.username=user1', '--config.rpc.password=test'
4343
}

Accounts/tictacthor/clients/src/main/java/com/tictacthor/Client.java renamed to Accounts/tictacthor/clients/src/main/java/net/corda/samples/tictacthor/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.tictacthor;
1+
package net.corda.samples.tictacthor;
22

33
import net.corda.client.rpc.CordaRPCClient;
44
import net.corda.core.messaging.CordaRPCOps;

Accounts/tictacthor/clients/src/main/java/com/tictacthor/webserver/Controller.java renamed to Accounts/tictacthor/clients/src/main/java/net/corda/samples/tictacthor/webserver/Controller.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package com.tictacthor.webserver;
1+
package net.corda.samples.tictacthor.webserver;
22

33

44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.tictacthor.accountUtilities.CreateNewAccount;
6-
import com.tictacthor.accountUtilities.ShareAccountTo;
7-
import com.tictacthor.accountUtilities.myGame;
8-
import com.tictacthor.flows.EndGameFlow;
9-
import com.tictacthor.flows.StartGameFlow;
10-
import com.tictacthor.flows.SubmitTurnFlow;
11-
import com.tictacthor.states.BoardState;
5+
import net.corda.samples.tictacthor.accountUtilities.CreateNewAccount;
6+
import net.corda.samples.tictacthor.accountUtilities.ShareAccountTo;
7+
import net.corda.samples.tictacthor.accountUtilities.myGame;
8+
import net.corda.samples.tictacthor.flows.EndGameFlow;
9+
import net.corda.samples.tictacthor.flows.StartGameFlow;
10+
import net.corda.samples.tictacthor.flows.SubmitTurnFlow;
11+
import net.corda.samples.tictacthor.states.BoardState;
1212
import net.corda.client.jackson.JacksonSupport;
1313
import net.corda.core.contracts.UniqueIdentifier;
1414
import net.corda.core.identity.CordaX500Name;

Accounts/tictacthor/clients/src/main/java/com/tictacthor/webserver/NodeRPCConnection.java renamed to Accounts/tictacthor/clients/src/main/java/net/corda/samples/tictacthor/webserver/NodeRPCConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.tictacthor.webserver;
1+
package net.corda.samples.tictacthor.webserver;
22

33
import net.corda.client.rpc.CordaRPCClient;
44
import net.corda.client.rpc.CordaRPCConnection;

Accounts/tictacthor/clients/src/main/java/com/tictacthor/webserver/Starter.java renamed to Accounts/tictacthor/clients/src/main/java/net/corda/samples/tictacthor/webserver/Starter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.tictacthor.webserver;
1+
package net.corda.samples.tictacthor.webserver;
22

33
import org.springframework.boot.Banner;
44
import org.springframework.boot.SpringApplication;

Accounts/tictacthor/contracts/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ dependencies {
3232
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
3333
cordaRuntime "$corda_release_group:corda:$corda_release_version"
3434
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
35-
// Token Account dependencies.
35+
// Account dependencies.
3636
cordaCompile "$accounts_release_group:accounts-contracts:$accounts_release_version"
3737
}

Accounts/tictacthor/contracts/src/main/java/com/tictacthor/contracts/BoardContract.java renamed to Accounts/tictacthor/contracts/src/main/java/net/corda/samples/tictacthor/contracts/BoardContract.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
1-
package com.tictacthor.contracts;
1+
package net.corda.samples.tictacthor.contracts;
22

3-
import com.tictacthor.states.BoardState;
4-
import kotlin.Pair;
53
import net.corda.core.contracts.CommandData;
64
import net.corda.core.contracts.CommandWithParties;
75
import net.corda.core.contracts.Contract;
6+
import net.corda.core.contracts.ContractState;
87
import net.corda.core.transactions.LedgerTransaction;
8+
import net.corda.samples.tictacthor.states.BoardState;
9+
10+
import java.util.List;
11+
912
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
13+
import static net.corda.core.contracts.ContractsDSL.requireThat;
1014

1115
// ************
1216
// * Contract *
1317
// ************
1418
public class BoardContract implements Contract {
1519
// This is used to identify our contract when building a transaction.
16-
public static final String ID = "com.tictacthor.contracts.BoardContract";
20+
public static final String ID = "net.corda.samples.tictacthor.contracts.BoardContract";
1721

1822
// A transaction is valid if the verify() function of the contract of all the transaction's input and output states
1923
// does not throw an exception.
2024
@Override
2125
public void verify(LedgerTransaction tx) {
26+
final CommandWithParties<BoardContract.Commands> command = requireSingleCommand(tx.getCommands(), BoardContract.Commands.class);
27+
28+
List<ContractState> inputs = tx.getInputStates();
29+
List<ContractState> outputs = tx.getOutputStates();
30+
31+
if (command.getValue() instanceof BoardContract.Commands.StartGame) {
32+
33+
// Using Corda DSL function requireThat to replicate conditions-checks
34+
requireThat(require -> {
35+
require.using("No inputs should be consumed when creating a new Invoice State.", inputs.isEmpty());
36+
require.using("Transaction must have exactly one output.", outputs.size() == 1);
37+
BoardState output = (BoardState) outputs.get(0);
38+
require.using("Output board must have status GAME_IN_PROGRESS", output.getStatus() == BoardState.Status.GAME_IN_PROGRESS);
39+
require.using("You cannot play a game with yourself.", output.getPlayerO() != output.getPlayerX());
40+
return null;
41+
});
2242

23-
/* We can use the requireSingleCommand function to extract command data from transaction.
24-
* However, it is possible to have multiple commands in a signle transaction.*/
25-
final CommandWithParties<Commands> command = requireSingleCommand(tx.getCommands(), Commands.class);
26-
final Commands commandData = command.getValue();
43+
} else if (command.getValue() instanceof BoardContract.Commands.SubmitTurn){
44+
45+
}else if (command.getValue() instanceof BoardContract.Commands.EndGame){
46+
47+
}else{
48+
throw new IllegalArgumentException("Command not found!");
49+
}
2750

2851
}
2952

@@ -33,10 +56,8 @@ public interface Commands extends CommandData {
3356
class StartGame implements Commands {}
3457
class SubmitTurn implements Commands {}
3558
class EndGame implements Commands {}
36-
3759
}
3860

39-
4061
public static class BoardUtils{
4162
public static Boolean isGameOver(char[][] board){
4263
return (board[0][0] == board [0][1] && board[0][0] == board [0][2] && (board[0][0] == 'X' || board[0][0] == 'O')) ||

Accounts/tictacthor/contracts/src/main/java/com/tictacthor/states/BoardState.java renamed to Accounts/tictacthor/contracts/src/main/java/net/corda/samples/tictacthor/states/BoardState.java

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

3-
import com.tictacthor.contracts.BoardContract;
3+
import net.corda.samples.tictacthor.contracts.BoardContract;
44
//import javafx.util.Pair;
55

66
import kotlin.Pair;
@@ -113,7 +113,6 @@ public BoardState returnNewBoardAfterMove(Pair<Integer,Integer> pos, AnonymousPa
113113

114114

115115
//getter setter
116-
117116
public UniqueIdentifier getPlayerO() {
118117
return playerO;
119118
}

Accounts/tictacthor/contracts/src/test/java/com/tictacthor/contracts/ContractTests.java

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

0 commit comments

Comments
 (0)