diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java index 8122551..b7152fb 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; import java.util.Arrays; -import java.util.UUID; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +24,7 @@ public class GameBoardTests { HoldingIdentityResolver holdingIdentityResolver; final String whitePlayerName = "alice"; - final String blackPlayerName = "bob"; + final String blackPlayerName = "bobik"; final static Stone WHITE_MAN = new Stone(Stone.Color.WHITE, Stone.Type.MAN); final static Stone WHITE_KING = new Stone(Stone.Color.WHITE, Stone.Type.KING); diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java index 3a59a0b..87b3665 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java @@ -21,8 +21,8 @@ public class GameProposalTests { @Autowired HoldingIdentityResolver holdingIdentityResolver; - final String issuer = "alice"; - final String acquier = "bob"; + final String issuer = "alice"; + final String acquier = "bobik"; final Stone.Color acquierColor = Stone.Color.WHITE; @Test diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java index d410307..a9151a6 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import djmil.cordacheckers.cordaclient.dao.GameState; -import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.user.HoldingIdentityResolver; @SpringBootTest @@ -19,22 +18,23 @@ public class GameStateTests { @Autowired HoldingIdentityResolver holdingIdentityResolver; - final String issuer = "alice"; - final String acquier = "bob"; - final Stone.Color acquierColor = Stone.Color.WHITE; + final String player1 = "alice"; + final String player2 = "bobik"; @Test void testList() { - List gsList = cordaClient.gameStateList( - holdingIdentityResolver.getByUsername("bob")); + final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); + + List gsList = cordaClient.gameStateList(hiPlayer1); System.out.println(gsList); } @Test void testGet() { - GameState gameStateView = cordaClient.gameStateGet( - holdingIdentityResolver.getByUsername("bob"), + final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); + + GameState gameStateView = cordaClient.gameStateGet(hiPlayer2, UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4") ); diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java index ef3c087..f0db6d9 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java @@ -21,6 +21,9 @@ public class RankingTests { @Autowired HoldingIdentityResolver holdingIdentityResolver; + final String player1 = "kumar"; + final String player2 = "bobik"; + @Test void testGlobalRanking() { final var hiCustodian = holdingIdentityResolver.getCustodian(); @@ -28,8 +31,8 @@ public class RankingTests { final List liderboard1 = cordaClient.fetchRanking(hiCustodian); - final var hiWinner = holdingIdentityResolver.getByUsername("Charlie"); - final var hiLooser = holdingIdentityResolver.getByUsername("Bob"); + final var hiWinner = holdingIdentityResolver.getByUsername(player1); + final var hiLooser = holdingIdentityResolver.getByUsername(player2); final GameState game = cordaClient.gameProposalCreate( hiWinner, hiLooser, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING test"); @@ -45,7 +48,7 @@ public class RankingTests { @Test void testIndividualRanking() { - final var hiCustodian = holdingIdentityResolver.getByUsername("Bob"); + final var hiCustodian = holdingIdentityResolver.getByUsername(player2); final List liderboard = cordaClient.fetchRanking(hiCustodian); System.out.println(liderboard); } diff --git a/corda/config/static-network-config.json b/corda/config/static-network-config.json index 7462400..a9398ac 100644 --- a/corda/config/static-network-config.json +++ b/corda/config/static-network-config.json @@ -4,20 +4,20 @@ "cpi" : "CordaCheckers" }, { - "x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA", + "x500Name" : "CN=Bobik, OU=Player, O=Checkers, L=Kyiv, C=UA", "cpi" : "CordaCheckers" }, { - "x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB", + "x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN", "cpi" : "CordaCheckers" }, { - "x500Name" : "CN=Kumar, OU=Custodian, O=Checkers, L=Mumbai, C=IN", + "x500Name" : "CN=Eva, OU=Custodian, O=Checkers, L=Rotkreuz, C=CH", "cpi" : "CordaCheckers" }, { - "x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB", + "x500Name" : "CN=NotaryRep1, OU=Notary, O=Checkers, L=Rotkreuz, C=CH", "cpi" : "NotaryServer", - "serviceX500Name": "CN=NotaryService, OU=Test Dept, O=R3, L=London, C=GB" + "serviceX500Name" : "CN=Djmil, OU=Notary, O=Checkers, L=Rotkreuz, C=CH" } ] diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/VNode.java b/corda/workflows/src/main/java/djmil/cordacheckers/VNode.java new file mode 100644 index 0000000..d5014d7 --- /dev/null +++ b/corda/workflows/src/main/java/djmil/cordacheckers/VNode.java @@ -0,0 +1,29 @@ +package djmil.cordacheckers; + +import net.corda.v5.application.flows.CordaInject; +import net.corda.v5.application.membership.MemberLookup; +import net.corda.v5.base.types.MemberX500Name; +import net.corda.v5.membership.MemberInfo; +import net.corda.v5.membership.NotaryInfo; + +public class VNode { + static final String CHECKERS = "Checkers"; // O aka Organization + static final String CUSTODIAN = "Custodian"; // OU aka OrganizationUnit + static final String NOTARY = "Notary"; // OU aka OrganizationUnit + + @CordaInject + MemberLookup memberLookup; + + public static boolean isCordaCherckersCustodian(MemberInfo memberInfo) { + final MemberX500Name memberName = memberInfo.getName(); + return memberName.getOrganization().equals(CHECKERS) && + memberName.getOrganizationUnit().equals(CUSTODIAN); + } + + public static boolean isCordaCherckersNotary(NotaryInfo notaryInfo) { + final MemberX500Name memberName = notaryInfo.getName(); + return memberName.getOrganization().equals(CHECKERS) && + memberName.getOrganizationUnit().equals(NOTARY); + } + +} 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 bb4601d..00594a3 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java @@ -10,6 +10,7 @@ import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import djmil.cordacheckers.VNode; import djmil.cordacheckers.checkers.Stone; import djmil.cordacheckers.contracts.GameCommand; import djmil.cordacheckers.gamestate.CommitTrx; @@ -30,6 +31,7 @@ import net.corda.v5.ledger.common.NotaryLookup; import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; import net.corda.v5.membership.MemberInfo; +import net.corda.v5.membership.NotaryInfo; public class CreateFlow implements ClientStartableFlow{ @@ -42,7 +44,7 @@ public class CreateFlow implements ClientStartableFlow{ public MemberLookup memberLookup; @CordaInject - public NotaryLookup notaryLookup; + NotaryLookup notaryLookup; @CordaInject public UtxoLedgerService utxoLedgerService; @@ -64,7 +66,7 @@ public class CreateFlow implements ClientStartableFlow{ .addCommand(command) .addOutputState(gameProposal) .addSignatories(gameProposal.getParticipants()) - .setNotary(notaryLookup.getNotaryServices().iterator().next().getName()) + .setNotary(findNotary().getName()) .setTimeWindowUntil(Instant.now().plusMillis(Duration.ofDays(1).toMillis())) .toSignedTransaction(); @@ -85,7 +87,7 @@ public class CreateFlow implements ClientStartableFlow{ } @Suspendable - private GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) { + GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) { final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class); final Stone.Color opponentColor = Stone.Color.valueOf(args.opponentColor); @@ -114,4 +116,13 @@ public class CreateFlow implements ClientStartableFlow{ ); } + @Suspendable + public NotaryInfo findNotary() { + return notaryLookup.getNotaryServices() + .stream() + .filter(notary -> VNode.isCordaCherckersNotary(notary)) + .reduce((a,b) -> {throw new IllegalStateException("Multiple Notary VNodes");}) + .orElseThrow( () -> new IllegalStateException("No Notary VNode found")); + } + } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultCommiter.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultCommiter.java index fe35a53..3480ca5 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultCommiter.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameresult/GameResultCommiter.java @@ -5,6 +5,7 @@ import java.time.Duration; import java.time.Instant; import java.util.UUID; +import djmil.cordacheckers.VNode; import djmil.cordacheckers.contracts.GameCommand; import djmil.cordacheckers.gamestate.CommitTrx; import djmil.cordacheckers.gamestate.GetFlow; @@ -72,7 +73,7 @@ public class GameResultCommiter implements SubFlow { MemberInfo findCustodian() { return memberLookup.lookup() .stream() - .filter(m -> m.getName().getOrganizationUnit().equals("Custodian") ) + .filter(member -> VNode.isCordaCherckersCustodian(member) ) .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) .orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); }