Corda: Piece class

This commit is contained in:
djmil 2023-09-07 09:57:54 +02:00
parent a9b70b963c
commit c1dbb3d213
3 changed files with 36 additions and 18 deletions

View File

@ -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<PublicKey> participants;
MemberX500Name sender;
MemberX500Name recipient;
Piece.Color recipientColor;
String message;
UUID id;
List<PublicKey> 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<PublicKey> participants
@ -53,7 +46,7 @@ public class GameProposalState implements ContractState {
return recipient;
}
public Color getRecipientColor() {
public Piece.Color getRecipientColor() {
return recipientColor;
}

View File

@ -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;
}

View File

@ -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();
}
}