Rename Bob to Bobik
- rename Repository vNode - cluster topology: better vnodes lookup
This commit is contained in:
parent
d58a89e3b3
commit
07ce05bf01
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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<GameState> gsList = cordaClient.gameStateList(
|
||||
holdingIdentityResolver.getByUsername("bob"));
|
||||
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
|
||||
|
||||
List<GameState> 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")
|
||||
);
|
||||
|
||||
|
@ -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<Rank> 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<Rank> liderboard = cordaClient.fetchRanking(hiCustodian);
|
||||
System.out.println(liderboard);
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
29
corda/workflows/src/main/java/djmil/cordacheckers/VNode.java
Normal file
29
corda/workflows/src/main/java/djmil/cordacheckers/VNode.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<SecureHash> {
|
||||
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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user