diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/AcceptFlow.java b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/AcceptFlow.java index 6914f54..bbba19c 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/AcceptFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/AcceptFlow.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import djmil.cordacheckers.VNode; import djmil.cordacheckers.contracts.GameCommand; import djmil.cordacheckers.gamestate.CommitTrx; import djmil.cordacheckers.gamestate.FlowResponce; @@ -21,16 +22,21 @@ import net.corda.v5.application.flows.ClientStartableFlow; import net.corda.v5.application.flows.CordaInject; import net.corda.v5.application.flows.FlowEngine; import net.corda.v5.application.marshalling.JsonMarshallingService; +import net.corda.v5.application.membership.MemberLookup; import net.corda.v5.base.annotations.Suspendable; import net.corda.v5.crypto.SecureHash; import net.corda.v5.ledger.utxo.StateAndRef; import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; +import net.corda.v5.membership.MemberInfo; public class AcceptFlow implements ClientStartableFlow{ private final static Logger log = LoggerFactory.getLogger(AcceptFlow.class); + @CordaInject + public MemberLookup memberLookup; + @CordaInject public JsonMarshallingService jsonMarshallingService; @@ -47,6 +53,7 @@ public class AcceptFlow implements ClientStartableFlow{ try { final GameCommand command = new GameCommand(GameCommand.Action.GAME_PROPOSAL_ACCEPT); + final MemberInfo custodianInfo = findCustodian(); final UUID gameUuid = UUID.fromString(requestBody.getRequestBody()); @@ -66,7 +73,10 @@ public class AcceptFlow implements ClientStartableFlow{ .toSignedTransaction(); utxoTrxId = this.flowEngine - .subFlow(new CommitTrx(gameProposalAcceptTrx, gameProposal.getIssuerName())); + .subFlow(new CommitTrx(gameProposalAcceptTrx, + gameProposal.getIssuerName(), + custodianInfo.getName() + )); final View gameView = this.flowEngine .subFlow(new ViewBuilder(utxoTrxId)); @@ -81,4 +91,13 @@ public class AcceptFlow implements ClientStartableFlow{ } } + @Suspendable + MemberInfo findCustodian() { + return memberLookup.lookup() + .stream() + .filter(member -> VNode.isCordaCherckersCustodian(member) ) + .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) + .orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); + } + } 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 807f66b..e214b27 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gameproposal/CreateFlow.java @@ -59,8 +59,9 @@ public class CreateFlow implements ClientStartableFlow{ try { final GameCommand command = new GameCommand(GameCommand.Action.GAME_PROPOSAL_CREATE); + final MemberInfo custodianInfo = findCustodian(); - final GameProposalState gameProposal = buildGameProposalStateFrom(requestBody); + final GameProposalState gameProposal = buildGameProposalStateFrom(requestBody, custodianInfo); final UtxoSignedTransaction gameProposalCreateTrx = utxoLedgerService.createTransactionBuilder() .addCommand(command) @@ -71,7 +72,10 @@ public class CreateFlow implements ClientStartableFlow{ .toSignedTransaction(); utxoTrxId = this.flowEngine - .subFlow(new CommitTrx(gameProposalCreateTrx, gameProposal.getAcquierName())); + .subFlow(new CommitTrx(gameProposalCreateTrx, + gameProposal.getAcquierName(), + custodianInfo.getName() + )); final View gameView = this.flowEngine .subFlow(new ViewBuilder(utxoTrxId)); @@ -87,7 +91,7 @@ public class CreateFlow implements ClientStartableFlow{ } @Suspendable - GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) { + GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody, MemberInfo custodiaInfo) { final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class); final MemberInfo myInfo = memberLookup.myInfo(); @@ -108,7 +112,8 @@ public class CreateFlow implements ClientStartableFlow{ args.message, Arrays.asList( myInfo.getLedgerKeys().get(0), - opponentInfo.getLedgerKeys().get(0)) + opponentInfo.getLedgerKeys().get(0), + custodiaInfo.getLedgerKeys().get(0)) ); } @@ -121,4 +126,13 @@ public class CreateFlow implements ClientStartableFlow{ .orElseThrow( () -> new IllegalStateException("No Notary VNode found")); } + @Suspendable + MemberInfo findCustodian() { + return memberLookup.lookup() + .stream() + .filter(member -> VNode.isCordaCherckersCustodian(member) ) + .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) + .orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); + } + } diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java index 5a1fa03..d3af519 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java @@ -7,7 +7,6 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import djmil.cordacheckers.VNode; import net.corda.v5.application.flows.CordaInject; import net.corda.v5.application.flows.InitiatingFlow; import net.corda.v5.application.flows.SubFlow; @@ -19,7 +18,6 @@ import net.corda.v5.base.types.MemberX500Name; import net.corda.v5.crypto.SecureHash; import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import net.corda.v5.membership.MemberInfo; @InitiatingFlow(protocol = "gamestate-commit") public class CommitTrx implements SubFlow { @@ -27,7 +25,7 @@ public class CommitTrx implements SubFlow { private final static Logger log = LoggerFactory.getLogger(CommitTrx.class); private final UtxoSignedTransaction utxTrxCandidate; private final MemberX500Name counterpartyName; - private /*final*/ MemberX500Name custodyName; + private final MemberX500Name custodyName; public CommitTrx(UtxoSignedTransaction signedTransaction, MemberX500Name counterpartyName) { this.utxTrxCandidate = signedTransaction; @@ -63,11 +61,6 @@ public class CommitTrx implements SubFlow { final FlowSession session = flowMessaging.initiateFlow(this.counterpartyName); List sessionsList = new LinkedList(Arrays.asList(session)); - if (custodyName == null) { - custodyName = findCustodian().getName(); - log.info("GameState: [UGLY FIX] backchain validation failure for custodian"); - } - if (custodyName != null) { sessionsList.add(flowMessaging.initiateFlow(custodyName)); } @@ -81,12 +74,4 @@ public class CommitTrx implements SubFlow { return trxId; } - @Suspendable - MemberInfo findCustodian() { - return memberLookup.lookup() - .stream() - .filter(member -> VNode.isCordaCherckersCustodian(member) ) - .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) - .orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); - } }