diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameCommand.java b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameCommand.java index ceeacfb..53d9442 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameCommand.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/GameCommand.java @@ -73,10 +73,10 @@ public class GameCommand implements Command { return move; } - /* * Session initiator/respondent */ + public MemberX500Name getCounterparty(StateAndRef gameStateSar) { final GameState gameState = gameStateSar.getState().getContractState(); return gameState.getOpponentName(getInitiator(gameState)); @@ -191,9 +191,7 @@ public class GameCommand implements Command { requireThat(inActors.containsAll(outActors) && outActors.containsAll(inActors), IN_OUT_PARTICIPANTS); - final var activePlayerName = getInitiator(inGameBoardState); - requireThat(inGameBoardState.getActivePlayerName().compareTo(activePlayerName) == 0, SURRENDER_ACTOR + "expected " +inGameBoardState.getActivePlayerName() +" actual " +activePlayerName); - + final var activePlayerName = getInitiator(inGameBoardState); final var expectedWinnerName = inGameBoardState.getOpponentName(activePlayerName); requireThat(outGameResultState.getWinnerName().compareTo(expectedWinnerName) == 0, "Expected winner "+expectedWinnerName.getCommonName() +", proposed winner " +outGameResultState.getWinnerName().getCommonName()); @@ -237,7 +235,6 @@ public class GameCommand implements Command { static final String SURRENDER_INPUT_STATE = "SURRENDER command should have exactly one GameBoardState input state"; static final String SURRENDER_OUTPUT_STATE = "SURRENDER command should have exactly one GameResultState output state"; - static final String SURRENDER_ACTOR = "Only active player can SURRENDER"; static final String MOVE_INPUT_STATE = "MOVE command should have exactly one GameBoardState input state"; static final String MOVE_OUTPUT_STATE = "MOVE command should have exactly one GameBoardState output state"; diff --git a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/UtxoLedgerTransactionUtil.java b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/UtxoLedgerTransactionUtil.java index 469014a..2553b1d 100644 --- a/corda/contracts/src/main/java/djmil/cordacheckers/contracts/UtxoLedgerTransactionUtil.java +++ b/corda/contracts/src/main/java/djmil/cordacheckers/contracts/UtxoLedgerTransactionUtil.java @@ -11,49 +11,25 @@ public class UtxoLedgerTransactionUtil { return single(utxoTrx.getCommands(clazz), clazz); } - // public static StateAndRef getSingleReferenceSar(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return singleSar(utxoTrx.getReferenceStateAndRefs(clazz), clazz); - // } - public static T getSingleInputState(UtxoLedgerTransaction utxoTrx, Class clazz) { return single(utxoTrx.getInputStates(clazz), clazz); } - // public static StateAndRef getSingleInputSar(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return singleSar(utxoTrx.getInputStateAndRefs(clazz), clazz); - // } - public static T getSingleOutputState(UtxoLedgerTransaction utxoTrx, Class clazz) { return single(utxoTrx.getOutputStates(clazz), clazz); } - // public static Optional getOptionalCommand(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return optional(utxoTrx.getCommands(clazz), clazz); - // } - - // public static Optional getOptionalReferenceState(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return optional(utxoTrx.getReferenceStates(clazz), clazz); - // } - - // public static Optional getOptionalInputState(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return optional(utxoTrx.getInputStates(clazz), clazz); - // } - - // public static Optional getOptionalOutputState(UtxoLedgerTransaction utxoTrx, Class clazz) { - // return optional(utxoTrx.getOutputStates(clazz), clazz); - // } - - private static Optional optional(List list, Class clazz) { - return list - .stream() - .reduce((a, b) -> {throw new IllegalStateException(MULTIPLE_INSTANCES_OF +clazz.getName());}); - } - private static T single(List list, Class clazz) { return optional(list, clazz) .orElseThrow( () -> new IllegalStateException(NO_INSTANCES_OF +clazz.getName()) ); } + private static Optional optional(List list, Class clazz) { + return list + .stream() + .reduce((a, b) -> {throw new IllegalStateException(MULTIPLE_INSTANCES_OF +clazz.getName());}); + } + private static String MULTIPLE_INSTANCES_OF = "Multiple instances of "; private static String NO_INSTANCES_OF = "No instances of "; }