From beadaba27ef9d883b7407cb349dbbdd8987ea5f3 Mon Sep 17 00:00:00 2001 From: djmil Date: Sun, 3 Sep 2023 22:58:02 +0200 Subject: [PATCH] Corda: dao updates --- .../contracts/GameProposalContract.java | 4 +-- .../states/GameProposalState.java | 28 +++++++------------ .../gameproposal/CreateFlow.java | 2 +- .../gameproposal/CreateFlowArgs.java | 14 ++++------ .../cordacheckers/gameproposal/ListItem.java | 16 +++++------ 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameProposalContract.java b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameProposalContract.java index 11e35b1..0ecd7b1 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameProposalContract.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameProposalContract.java @@ -31,7 +31,7 @@ public class GameProposalContract implements net.corda.v5.ledger.utxo.Contract { GameProposalState outputState = trx.getOutputStates(GameProposalState.class).get(0); requireThat(outputState != null, CREATE_OUTPUT_STATE); - requireThat(outputState.getYouPlayAs() != null, CREATE_NOT_NULL_YOU_PLAY_AS); + requireThat(outputState.getRecipientColor() != null, NON_NULL_RECIPIENT_COLOR); } else if (command instanceof Accept) { // TODO outputState -> Game @@ -63,7 +63,7 @@ public class GameProposalContract implements net.corda.v5.ledger.utxo.Contract { static final String CREATE_INPUT_STATE = "Create command should have no input states"; static final String CREATE_OUTPUT_STATE = "Create command should output exactly one GameProposal state"; - static final String CREATE_NOT_NULL_YOU_PLAY_AS = "GameProposal.youPlayAs field can not be null"; + static final String NON_NULL_RECIPIENT_COLOR = "GameProposal.recipientColor field can not be null"; static final String REJECT_INPUT_STATE = "Reject command should have exactly one GameProposal state"; static final String REJECT_OUTPUT_STATE = "Reject command should have no output states"; 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 cf935b5..c1bae80 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/states/GameProposalState.java @@ -22,8 +22,8 @@ public class GameProposalState implements ContractState { public final MemberX500Name sender; public final MemberX500Name recipient; - public final Color youPlayAs; - public final String additionalMessage; + public final Color recipientColor; + public final String message; public final UUID id; public final List participants; @@ -32,14 +32,14 @@ public class GameProposalState implements ContractState { public GameProposalState( MemberX500Name sender, MemberX500Name recipient, - Color youPlayAs, - String additionalMessage, + Color recipientColor, + String message, UUID id, List participants) { this.sender = sender; this.recipient = recipient; - this.youPlayAs = youPlayAs; - this.additionalMessage = additionalMessage; + this.recipientColor = recipientColor; + this.message = message; this.id = id; this.participants = participants; } @@ -52,12 +52,12 @@ public class GameProposalState implements ContractState { return recipient; } - public Color getYouPlayAs() { - return youPlayAs; + public Color getRecipientColor() { + return recipientColor; } - public String getAdditionalMessage() { - return additionalMessage; + public String getMessage() { + return message; } public UUID getId() { @@ -67,12 +67,4 @@ public class GameProposalState implements ContractState { public List getParticipants() { return participants; } - - public String getRecipientCommonName() { - return recipient == null ? "" : recipient.getCommonName(); - } - - public String getSenderCommonName() { - return sender == null ? "" : sender.getCommonName(); - } } 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 2678a35..47aebed 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java @@ -93,7 +93,7 @@ public class CreateFlow implements ClientStartableFlow{ myInfo.getName(), opponentInfo.getName(), GameProposalState.Color.valueOf(args.opponentColor), - args.additionalMessage, + args.message, UUID.randomUUID(), Arrays.asList(myInfo.getLedgerKeys().get(0), opponentInfo.getLedgerKeys().get(0)) ); diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlowArgs.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlowArgs.java index 9c7928c..17149b1 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlowArgs.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlowArgs.java @@ -3,16 +3,12 @@ package djmil.cordacheckers.gameproposal; public class CreateFlowArgs { public final String opponentName; public final String opponentColor; - public final String additionalMessage; - - public CreateFlowArgs(String opponentName, String opponentColor, String additionalMessage) { - this.opponentName = opponentName; - this.opponentColor = opponentColor; - this.additionalMessage = additionalMessage; - } + public final String message; // Serialisation service requires a default constructor - public CreateFlowArgs() { - this(null, null, null); + public CreateFlowArgs() { + opponentName = null; + opponentColor = null; + message = null; } } 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 f1c1c79..5e7c259 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/ListItem.java @@ -12,24 +12,24 @@ import djmil.cordacheckers.states.GameProposalState; public class ListItem { public final String sender; public final String recipient; - public final String youPlayAs; - public final String additionalMessage; + public final String recipientColor; + public final String message; public final UUID id; // Serialisation service requires a default constructor public ListItem() { this.sender = null; this.recipient = null; - this.youPlayAs = null; - this.additionalMessage = null; + this.recipientColor = null; + this.message = null; this.id = null; } public ListItem(GameProposalState state) { - this.sender = state.getSenderCommonName(); - this.recipient = state.getRecipientCommonName(); - this.youPlayAs = state.getYouPlayAs().name(); - this.additionalMessage = state.getAdditionalMessage(); + this.sender = state.getSender().getCommonName(); + this.recipient = state.getRecipient().getCommonName(); + this.recipientColor = state.getRecipientColor().name(); + this.message = state.getMessage(); this.id = state.getId(); } }