From c1dbb3d21323158185aa6abcaa22b04eaca3a3e4 Mon Sep 17 00:00:00 2001 From: djmil Date: Thu, 7 Sep 2023 09:57:54 +0200 Subject: [PATCH] Corda: Piece class --- .../states/GameProposalState.java | 23 +++++++----------- .../djmil/cordacheckers/states/Piece.java | 24 +++++++++++++++++++ .../gameproposal/CreateFlow.java | 7 +++--- 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 corda/contracts/src/main/java/djmil/cordacheckers/states/Piece.java 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 82ff887..cafd9c6 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java @@ -6,7 +6,6 @@ import java.util.UUID; import djmil.cordacheckers.contracts.GameProposalContract; import net.corda.v5.base.annotations.ConstructorForDeserialization; -import net.corda.v5.base.annotations.CordaSerializable; import net.corda.v5.base.types.MemberX500Name; import net.corda.v5.ledger.utxo.BelongsToContract; import net.corda.v5.ledger.utxo.ContractState; @@ -14,25 +13,19 @@ import net.corda.v5.ledger.utxo.ContractState; @BelongsToContract(GameProposalContract.class) public class GameProposalState implements ContractState { - @CordaSerializable - public enum Color { - WHITE, - BLACK, - } - - public final MemberX500Name sender; - public final MemberX500Name recipient; - public final Color recipientColor; - public final String message; - public final UUID id; - public final List participants; + MemberX500Name sender; + MemberX500Name recipient; + Piece.Color recipientColor; + String message; + UUID id; + List participants; // Allows serialisation and to use a specified UUID @ConstructorForDeserialization public GameProposalState( MemberX500Name sender, MemberX500Name recipient, - Color recipientColor, + Piece.Color recipientColor, String message, UUID id, List participants @@ -53,7 +46,7 @@ public class GameProposalState implements ContractState { return recipient; } - public Color getRecipientColor() { + public Piece.Color getRecipientColor() { return recipientColor; } diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/states/Piece.java b/corda/contracts/src/main/java/djmil/cordacheckers/states/Piece.java new file mode 100644 index 0000000..634ae06 --- /dev/null +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/Piece.java @@ -0,0 +1,24 @@ +package djmil.cordacheckers.states; + +import net.corda.v5.base.annotations.CordaSerializable; + +@CordaSerializable +public class Piece { + + @CordaSerializable + public enum Type { + MAN, + KING, + } + + @CordaSerializable + public enum Color { + WHITE, + BLACK, + } + + Color color; + Type type; + + +} 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 e29c6cf..a5dd10c 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import djmil.cordacheckers.FlowResult; import djmil.cordacheckers.contracts.GameProposalContract; import djmil.cordacheckers.states.GameProposalState; +import djmil.cordacheckers.states.Piece; import net.corda.v5.application.flows.ClientRequestBody; import net.corda.v5.application.flows.ClientStartableFlow; import net.corda.v5.application.flows.CordaInject; @@ -77,10 +78,10 @@ public class CreateFlow implements ClientStartableFlow{ private GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) { CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class); - GameProposalState.Color opponentColor = GameProposalState.Color.valueOf(args.opponentColor); + Piece.Color opponentColor = Piece.Color.valueOf(args.opponentColor); if (opponentColor == null) { throw new RuntimeException("Allowed values for opponentColor are: " - + GameProposalState.Color.WHITE.name() +", " + GameProposalState.Color.BLACK.name() + + Piece.Color.WHITE.name() +", " + Piece.Color.BLACK.name() + ". Actual value was: " + args.opponentColor); } @@ -119,6 +120,6 @@ public class CreateFlow implements ClientStartableFlow{ ledgerService.finalize(signedTransaction, sessionsList); - return gameProposal.id.toString(); + return gameProposal.getId().toString(); } }