Corda: dao updates

This commit is contained in:
djmil 2023-09-03 22:58:02 +02:00
parent 7a2a366dd5
commit beadaba27e
5 changed files with 26 additions and 38 deletions

View File

@ -31,7 +31,7 @@ public class GameProposalContract implements net.corda.v5.ledger.utxo.Contract {
GameProposalState outputState = trx.getOutputStates(GameProposalState.class).get(0); GameProposalState outputState = trx.getOutputStates(GameProposalState.class).get(0);
requireThat(outputState != null, CREATE_OUTPUT_STATE); 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 } else
if (command instanceof Accept) { if (command instanceof Accept) {
// TODO outputState -> Game // 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_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_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_INPUT_STATE = "Reject command should have exactly one GameProposal state";
static final String REJECT_OUTPUT_STATE = "Reject command should have no output states"; static final String REJECT_OUTPUT_STATE = "Reject command should have no output states";

View File

@ -22,8 +22,8 @@ public class GameProposalState implements ContractState {
public final MemberX500Name sender; public final MemberX500Name sender;
public final MemberX500Name recipient; public final MemberX500Name recipient;
public final Color youPlayAs; public final Color recipientColor;
public final String additionalMessage; public final String message;
public final UUID id; public final UUID id;
public final List<PublicKey> participants; public final List<PublicKey> participants;
@ -32,14 +32,14 @@ public class GameProposalState implements ContractState {
public GameProposalState( public GameProposalState(
MemberX500Name sender, MemberX500Name sender,
MemberX500Name recipient, MemberX500Name recipient,
Color youPlayAs, Color recipientColor,
String additionalMessage, String message,
UUID id, UUID id,
List<PublicKey> participants) { List<PublicKey> participants) {
this.sender = sender; this.sender = sender;
this.recipient = recipient; this.recipient = recipient;
this.youPlayAs = youPlayAs; this.recipientColor = recipientColor;
this.additionalMessage = additionalMessage; this.message = message;
this.id = id; this.id = id;
this.participants = participants; this.participants = participants;
} }
@ -52,12 +52,12 @@ public class GameProposalState implements ContractState {
return recipient; return recipient;
} }
public Color getYouPlayAs() { public Color getRecipientColor() {
return youPlayAs; return recipientColor;
} }
public String getAdditionalMessage() { public String getMessage() {
return additionalMessage; return message;
} }
public UUID getId() { public UUID getId() {
@ -67,12 +67,4 @@ public class GameProposalState implements ContractState {
public List<PublicKey> getParticipants() { public List<PublicKey> getParticipants() {
return participants; return participants;
} }
public String getRecipientCommonName() {
return recipient == null ? "" : recipient.getCommonName();
}
public String getSenderCommonName() {
return sender == null ? "" : sender.getCommonName();
}
} }

View File

@ -93,7 +93,7 @@ public class CreateFlow implements ClientStartableFlow{
myInfo.getName(), myInfo.getName(),
opponentInfo.getName(), opponentInfo.getName(),
GameProposalState.Color.valueOf(args.opponentColor), GameProposalState.Color.valueOf(args.opponentColor),
args.additionalMessage, args.message,
UUID.randomUUID(), UUID.randomUUID(),
Arrays.asList(myInfo.getLedgerKeys().get(0), opponentInfo.getLedgerKeys().get(0)) Arrays.asList(myInfo.getLedgerKeys().get(0), opponentInfo.getLedgerKeys().get(0))
); );

View File

@ -3,16 +3,12 @@ package djmil.cordacheckers.gameproposal;
public class CreateFlowArgs { public class CreateFlowArgs {
public final String opponentName; public final String opponentName;
public final String opponentColor; public final String opponentColor;
public final String additionalMessage; public final String message;
public CreateFlowArgs(String opponentName, String opponentColor, String additionalMessage) {
this.opponentName = opponentName;
this.opponentColor = opponentColor;
this.additionalMessage = additionalMessage;
}
// Serialisation service requires a default constructor // Serialisation service requires a default constructor
public CreateFlowArgs() { public CreateFlowArgs() {
this(null, null, null); opponentName = null;
opponentColor = null;
message = null;
} }
} }

View File

@ -12,24 +12,24 @@ import djmil.cordacheckers.states.GameProposalState;
public class ListItem { public class ListItem {
public final String sender; public final String sender;
public final String recipient; public final String recipient;
public final String youPlayAs; public final String recipientColor;
public final String additionalMessage; public final String message;
public final UUID id; public final UUID id;
// Serialisation service requires a default constructor // Serialisation service requires a default constructor
public ListItem() { public ListItem() {
this.sender = null; this.sender = null;
this.recipient = null; this.recipient = null;
this.youPlayAs = null; this.recipientColor = null;
this.additionalMessage = null; this.message = null;
this.id = null; this.id = null;
} }
public ListItem(GameProposalState state) { public ListItem(GameProposalState state) {
this.sender = state.getSenderCommonName(); this.sender = state.getSender().getCommonName();
this.recipient = state.getRecipientCommonName(); this.recipient = state.getRecipient().getCommonName();
this.youPlayAs = state.getYouPlayAs().name(); this.recipientColor = state.getRecipientColor().name();
this.additionalMessage = state.getAdditionalMessage(); this.message = state.getMessage();
this.id = state.getId(); this.id = state.getId();
} }
} }