diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java index ec3324d..c95ae5f 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java @@ -335,6 +335,7 @@ public class CordaClient { } if (responseBody.isFlowCompleted() && responseBody.flowResult() != null) { + System.out.println("resp: "+ responseBody.flowResult()); return responseBody.flowResult(); } } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameBoard.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameBoard.java index d2c61f5..ff9f1a5 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameBoard.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameBoard.java @@ -14,8 +14,8 @@ public record GameBoard( Map board, GameBoardCommand previousCommand, String message, - UUID id) + UUID gameUuid) -implements CordaState { +implements GameState { } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameProposal.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameProposal.java index 0f9b8fd..c13a51b 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameProposal.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameProposal.java @@ -10,6 +10,8 @@ public record GameProposal( String acquier, Piece.Color acquierColor, String message, - UUID id) implements CordaState { + UUID gameUuid) + +implements GameState { } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameResult.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameResult.java index 91ef80e..2fff804 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameResult.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameResult.java @@ -9,8 +9,8 @@ public record GameResult( String whitePlayerName, String blackPlayerName, Piece.Color victoryColor, - UUID id) + UUID gameUuid) -implements CordaState { +implements GameState { } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/CordaState.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java similarity index 55% rename from backend/src/main/java/djmil/cordacheckers/cordaclient/dao/CordaState.java rename to backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java index 48460fc..2743b46 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/CordaState.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java @@ -2,6 +2,6 @@ package djmil.cordacheckers.cordaclient.dao; import java.util.UUID; -public interface CordaState { - public UUID id(); +public interface GameState { + public UUID gameUuid(); } diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/CordaClientTest.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/CordaClientTest.java index fac10a4..5c9b843 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/CordaClientTest.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/CordaClientTest.java @@ -16,7 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; -import djmil.cordacheckers.cordaclient.dao.CordaState; +import djmil.cordacheckers.cordaclient.dao.GameState; import djmil.cordacheckers.cordaclient.dao.GameBoard; import djmil.cordacheckers.cordaclient.dao.GameProposal; import djmil.cordacheckers.cordaclient.dao.GameResult; @@ -153,7 +153,7 @@ public class CordaClientTest { List gbListIssuer = cordaClient.gameBoardList( holdingIdentityResolver.getByUsername(gpIssuer)); - GameBoard gbAlice = findByUuid(gbListIssuer, gbState.id()); + GameBoard gbAlice = findByUuid(gbListIssuer, gbState.gameUuid()); assertThat(gbAlice).isNotNull(); assertThat(gbAlice.opponentName()).isEqualToIgnoringCase(gpAcquier); assertThat(gbAlice.opponentColor()).isEqualByComparingTo(gpAcquierColor); @@ -163,7 +163,7 @@ public class CordaClientTest { List gbListAcquier = cordaClient.gameBoardList( holdingIdentityResolver.getByUsername(gpAcquier)); - GameBoard bgBob = findByUuid(gbListAcquier, gbState.id()); + GameBoard bgBob = findByUuid(gbListAcquier, gbState.gameUuid()); assertThat(bgBob).isNotNull(); assertThat(bgBob.opponentName()).isEqualToIgnoringCase(gpIssuer); assertThat(bgBob.opponentColor()).isEqualByComparingTo(Piece.Color.BLACK); @@ -201,15 +201,15 @@ public class CordaClientTest { hiBob, gpUuid ); - System.out.println("New GameBoard UUID "+ gbState.id()); + System.out.println("New GameBoard UUID "+ gbState.gameUuid()); assertThatThrownBy(() -> { // Alice can not surrender, since it is Bob's turn cordaClient.gameBoardSurrender( - hiAlice, gbState.id()); + hiAlice, gbState.gameUuid()); }); final GameResult gameResult = cordaClient.gameBoardSurrender( - hiBob, gbState.id()); + hiBob, gbState.gameUuid()); assertThat(gameResult.whitePlayerName()).isEqualTo(hiBob.getName()); assertThat(gameResult.blackPlayerName()).isEqualTo(hiAlice.getName()); @@ -233,21 +233,21 @@ public class CordaClientTest { hiBob, gpUuid ); - System.out.println("New GameBoard UUID "+ gbState.id()); + System.out.println("New GameBoard UUID "+ gbState.gameUuid()); assertThatThrownBy(() -> { // Alice can not move, since it is Bob's turn cordaClient.gameBoardMove( - hiAlice, gbState.id(), + hiAlice, gbState.gameUuid(), Arrays.asList(1, 2)); }); final GameBoard gameBoard = cordaClient.gameBoardMove( - hiBob, gbState.id(), Arrays.asList(1, 2)); + hiBob, gbState.gameUuid(), Arrays.asList(1, 2)); } - private T findByUuid(List statesList, UUID uuid) { + private T findByUuid(List statesList, UUID uuid) { for (T state : statesList) { - if (state.id().compareTo(uuid) == 0) + if (state.gameUuid().compareTo(uuid) == 0) return state; }; return null; diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/states/Counterparty.java b/corda/contracts/src/main/java/djmil/cordacheckers/states/Game.java similarity index 90% rename from corda/contracts/src/main/java/djmil/cordacheckers/states/Counterparty.java rename to corda/contracts/src/main/java/djmil/cordacheckers/states/Game.java index 539bca7..28c4670 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/Counterparty.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/Game.java @@ -8,10 +8,13 @@ import net.corda.v5.base.annotations.CordaSerializable; import net.corda.v5.base.types.MemberX500Name; @CordaSerializable -public interface Counterparty { +public interface Game { @NotNull MemberX500Name getCounterpartyName(MemberX500Name myName) throws NotInvolved; + + @NotNull + UUID getGameUuid(); public static class NotInvolved extends RuntimeException { public NotInvolved(MemberX500Name myName, Class clazz, UUID uuid) { diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameBoardState.java b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameBoardState.java index f278de9..0010642 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameBoardState.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameBoardState.java @@ -14,7 +14,7 @@ import net.corda.v5.ledger.utxo.BelongsToContract; import net.corda.v5.ledger.utxo.ContractState; @BelongsToContract(GameBoardContract.class) -public class GameBoardState implements ContractState, Counterparty { +public class GameBoardState implements ContractState, Game { private final MemberX500Name whitePlayerName; private final MemberX500Name blackPlayerName; @@ -24,7 +24,7 @@ public class GameBoardState implements ContractState, Counterparty { private final Map board; private final String message; - private final UUID id; + private final UUID gameUuid; private final List participants; public GameBoardState( @@ -39,7 +39,7 @@ public class GameBoardState implements ContractState, Counterparty { this.board = new LinkedHashMap(initialBoard); this.message = null; - this.id = gameProposalState.getId(); + this.gameUuid = gameProposalState.getGameUuid(); this.participants = gameProposalState.getParticipants(); } @@ -55,21 +55,21 @@ public class GameBoardState implements ContractState, Counterparty { this.board = newBoard; this.message = null; - this.id = oldGameBoardState.getId(); + this.gameUuid = oldGameBoardState.getGameUuid(); this.participants = oldGameBoardState.getParticipants(); } @ConstructorForDeserialization public GameBoardState(MemberX500Name whitePlayerName, MemberX500Name blackPlayerName, Color moveColor, Integer moveNumber, Map board, String message, - UUID id, List participants) { + UUID gameUuid, List participants) { this.whitePlayerName = whitePlayerName; this.blackPlayerName = blackPlayerName; this.moveColor = moveColor; this.moveNumber = moveNumber; this.board = board; this.message = message; - this.id = id; + this.gameUuid = gameUuid; this.participants = participants; } @@ -97,8 +97,8 @@ public class GameBoardState implements ContractState, Counterparty { return message; } - public UUID getId() { - return id; + public UUID getGameUuid() { + return gameUuid; } public List getParticipants() { @@ -113,7 +113,7 @@ public class GameBoardState implements ContractState, Counterparty { if (blackPlayerName.compareTo(myName) == 0) return whitePlayerName; - throw new Counterparty.NotInvolved(myName, GameBoardState.class, this.id); + throw new Game.NotInvolved(myName, GameBoardState.class, this.gameUuid); } public Piece.Color getCounterpartyColor(MemberX500Name myName) throws NotInvolved { diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java index f396f47..b7c50bf 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java @@ -11,13 +11,13 @@ import net.corda.v5.ledger.utxo.BelongsToContract; import net.corda.v5.ledger.utxo.ContractState; @BelongsToContract(GameProposalContract.class) -public class GameProposalState implements ContractState, Counterparty { +public class GameProposalState implements ContractState, Game { private final MemberX500Name issuer; private final MemberX500Name acquier; private final Piece.Color acquierColor; private final String message; - private final UUID id; + private final UUID gameUuid; private final List participants; @ConstructorForDeserialization @@ -26,14 +26,14 @@ public class GameProposalState implements ContractState, Counterparty { MemberX500Name acquier, Piece.Color acquierColor, String message, - UUID id, + UUID gameUuid, List participants ) { this.issuer = issuer; this.acquier = acquier; this.acquierColor = acquierColor; this.message = message; - this.id = id; + this.gameUuid = gameUuid; this.participants = participants; } @@ -53,8 +53,8 @@ public class GameProposalState implements ContractState, Counterparty { return message; } - public UUID getId() { - return id; + public UUID getGameUuid() { + return gameUuid; } public List getParticipants() { @@ -77,7 +77,7 @@ public class GameProposalState implements ContractState, Counterparty { if (acquier.compareTo(myName) == 0) return issuer; - throw new Counterparty.NotInvolved(myName, GameProposalState.class, this.id); + throw new Game.NotInvolved(myName, GameProposalState.class, this.gameUuid); } } diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameResultState.java b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameResultState.java index 34b0e06..7b1c510 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameResultState.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameResultState.java @@ -11,23 +11,23 @@ import net.corda.v5.ledger.utxo.BelongsToContract; import net.corda.v5.ledger.utxo.ContractState; @BelongsToContract(GameResultContract.class) -public class GameResultState implements ContractState, Counterparty { +public class GameResultState implements ContractState, Game { private final MemberX500Name whitePlayerName; private final MemberX500Name blackPlayerName; private final Piece.Color victoryColor; - private final UUID id; + private final UUID gameUuid; private final List participants; @ConstructorForDeserialization public GameResultState(MemberX500Name whitePlayerName, MemberX500Name blackPlayerName, Piece.Color victoryColor, - UUID id, List participants) { + UUID gameUuid, List participants) { this.whitePlayerName = whitePlayerName; this.blackPlayerName = blackPlayerName; this.victoryColor = victoryColor; - this.id = id; + this.gameUuid = gameUuid; this.participants = participants; } @@ -36,7 +36,7 @@ public class GameResultState implements ContractState, Counterparty { this.blackPlayerName = stateGameBoard.getBlackPlayerName(); this.victoryColor = victoryColor; - this.id = stateGameBoard.getId(); + this.gameUuid = stateGameBoard.getGameUuid(); this.participants = stateGameBoard.getParticipants(); } @@ -52,8 +52,8 @@ public class GameResultState implements ContractState, Counterparty { return victoryColor; } - public UUID getId() { - return id; + public UUID getGameUuid() { + return gameUuid; } @Override @@ -69,7 +69,7 @@ public class GameResultState implements ContractState, Counterparty { if (blackPlayerName.compareTo(myName) == 0) return whitePlayerName; - throw new Counterparty.NotInvolved(myName, GameResultState.class, this.id); + throw new Game.NotInvolved(myName, GameResultState.class, this.gameUuid); } } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/CommandFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/CommandFlow.java index d5f5340..35b84da 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/CommandFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/CommandFlow.java @@ -85,7 +85,7 @@ public class CommandFlow implements ClientStartableFlow { return this.utxoLedgerService .findUnconsumedStatesByType(GameBoardState.class) .stream() - .filter(sar -> sar.getState().getContractState().getId().equals(gameBoardUuid)) + .filter(sar -> sar.getState().getContractState().getGameUuid().equals(gameBoardUuid)) .reduce((a, b) -> {throw new IllegalStateException("Multiple states: " +a +", " +b);}) .get(); } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/GameBoardView.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/GameBoardView.java index fa849c2..b73a4f3 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/GameBoardView.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/GameBoardView.java @@ -5,7 +5,7 @@ import java.util.UUID; import djmil.cordacheckers.contracts.GameBoardCommand; import djmil.cordacheckers.contracts.UtxoLedgerTransactionUtil; -import djmil.cordacheckers.states.Counterparty.NotInvolved; +import djmil.cordacheckers.states.Game.NotInvolved; import djmil.cordacheckers.states.GameBoardState; import djmil.cordacheckers.states.Piece; import net.corda.v5.base.types.MemberX500Name; @@ -21,7 +21,7 @@ public class GameBoardView { public final Map board; public final GameBoardCommand previousCommand; public final String message; - public final UUID id; + public final UUID gameUuid; /* * GameStatus enum: @@ -40,7 +40,7 @@ public class GameBoardView { this.board = null; this.previousCommand = null; this.message = null; - this.id = null; + this.gameUuid = null; } // A view from a perspective of a concrete player, on a ledger transaction that has @@ -62,7 +62,7 @@ public class GameBoardView { this.moveNumber = stateGameBoard.getMoveNumber(); this.board = stateGameBoard.getBoard(); this.message = stateGameBoard.getMessage(); - this.id = stateGameBoard.getId(); + this.gameUuid = stateGameBoard.getGameUuid(); } } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/ListFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/ListFlow.java index 8b5921b..c8f1252 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/ListFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameboard/ListFlow.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import djmil.cordacheckers.FlowResult; import djmil.cordacheckers.states.GameBoardState; -import djmil.cordacheckers.states.Counterparty.NotInvolved; +import djmil.cordacheckers.states.Game.NotInvolved; import net.corda.v5.application.flows.ClientRequestBody; import net.corda.v5.application.flows.ClientStartableFlow; import net.corda.v5.application.flows.CordaInject; diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CommandFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CommandFlow.java index 3a52791..2f4faa9 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CommandFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CommandFlow.java @@ -10,7 +10,7 @@ import djmil.cordacheckers.contracts.GameProposalCommand; import djmil.cordacheckers.gameboard.GameBoardView; import djmil.cordacheckers.states.GameBoardState; import djmil.cordacheckers.states.GameProposalState; -import djmil.cordacheckers.states.Counterparty.NotInvolved; +import djmil.cordacheckers.states.Game.NotInvolved; import net.corda.v5.application.flows.ClientRequestBody; import net.corda.v5.application.flows.ClientStartableFlow; import net.corda.v5.application.flows.CordaInject; @@ -86,7 +86,7 @@ public class CommandFlow implements ClientStartableFlow { return this.utxoLedgerService .findUnconsumedStatesByType(GameProposalState.class) .stream() - .filter(sar -> sar.getState().getContractState().getId().equals(uuidGameProposal)) + .filter(sar -> sar.getState().getContractState().getGameUuid().equals(uuidGameProposal)) .reduce((a, b) -> {throw new IllegalStateException("Multiple states: " +a +", " +b);}) .get(); } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java index fb7e4cb..8b8110c 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java @@ -62,7 +62,7 @@ public class CreateFlow implements ClientStartableFlow{ final SecureHash trxId = this.flowEngine .subFlow(new CommitSubFlow(trx, command.getRespondent(newGameProposal))); - return new FlowResult(newGameProposal.getId(), trxId) + return new FlowResult(newGameProposal.getGameUuid(), trxId) .toJsonEncodedString(jsonMarshallingService); } catch (Exception e) { diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java index f863500..a937190 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java @@ -31,6 +31,6 @@ public class ListItem { this.acquier = state.getAcquier().getCommonName(); this.acquierColor = state.getAcquierColor(); this.message = state.getMessage(); - this.id = state.getId(); + this.id = state.getGameUuid(); } } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultView.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultView.java index 9f0d710..f3fddc5 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultView.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultView.java @@ -23,7 +23,7 @@ public class GameResultView { this.whitePlayerName = gameResultState.getWhitePlayerName().getCommonName(); this.blackPlayerName = gameResultState.getBlackPlayerName().getCommonName(); this.victoryColor = gameResultState.getVictoryColor(); - this.id = gameResultState.getId(); + this.id = gameResultState.getGameUuid(); } }