From 098645710f6b307132687808fdfa53fb33747afc Mon Sep 17 00:00:00 2001 From: djmil Date: Tue, 28 Nov 2023 21:34:40 +0100 Subject: [PATCH] .getTransaction() --- .../gamestate/CommitTrxResponder.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrxResponder.java b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrxResponder.java index ae8d8a5..2b18211 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrxResponder.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrxResponder.java @@ -12,14 +12,14 @@ import net.corda.v5.application.membership.MemberLookup; import net.corda.v5.application.messaging.FlowSession; import net.corda.v5.base.annotations.Suspendable; import net.corda.v5.base.exceptions.CordaRuntimeException; -import net.corda.v5.base.types.MemberX500Name; import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.transaction.UtxoLedgerTransaction; +import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; import net.corda.v5.ledger.utxo.transaction.UtxoTransactionValidator; @InitiatedBy(protocol = "gamestate-commit") public class CommitTrxResponder implements ResponderFlow { - + private final static Logger log = LoggerFactory.getLogger(CommitTrxResponder.class); @CordaInject @@ -27,12 +27,12 @@ public class CommitTrxResponder implements ResponderFlow { @CordaInject public UtxoLedgerService utxoLedgerService; - + @Suspendable @Override public void call(FlowSession session) { - UtxoTransactionValidator txValidator = trxToValidate -> { - try { + try { + UtxoTransactionValidator txValidator = trxToValidate -> { checkParticipants(session, trxToValidate); /* @@ -40,42 +40,40 @@ public class CommitTrxResponder implements ResponderFlow { */ log.info("Approval for " + trxToValidate.getId()); - } catch (Exception e) { - log.warn("Validation has failed. " +e.getMessage()); - // We have to re-trow an exception to indicate validation failure - throw new CordaRuntimeException(e.getClass().getCanonicalName(), e.getMessage(), e.getCause()); - } - }; + }; - try { - this.utxoLedgerService - .receiveFinality(session, txValidator); + UtxoSignedTransaction finalizedSignedTransaction = this.utxoLedgerService + .receiveFinality(session, txValidator) + .getTransaction(); + + log.info("Finished responder flow - " + finalizedSignedTransaction.getId()); } catch (Exception e) { // Log Corda's specific message about finality validation failure - log.warn(e.getMessage()); + log.warn(e.getMessage()); } } @Suspendable - void checkParticipants(FlowSession session, UtxoLedgerTransaction gameStateUtxo) throws ParticipantException { + void checkParticipants(FlowSession session, UtxoLedgerTransaction gameStateUtxo) { final GameInfo info = new GameInfo(gameStateUtxo); final var conterpartyName = session.getCounterparty(); if (info.issuer.compareTo(conterpartyName) != 0) - throw new ParticipantException("Issuer", conterpartyName, info.issuer); + throw new CordaRuntimeException("Bad Issuer. Expected: " + conterpartyName + " actual: " + info.issuer); final var myInfo = memberLookup.myInfo(); if (VNode.isCordaCherckersCustodian(myInfo)) return; // Custodian shall not validate state's counterparty - + final var opponentName = info.state.getOpponentName(myInfo.getName()); // throws NotInvolved if (conterpartyName.compareTo(opponentName) != 0) - throw new ParticipantException("Opponent", conterpartyName, opponentName); - } - - public static class ParticipantException extends Exception { - public ParticipantException(String role, MemberX500Name expected, MemberX500Name actual) { - super("Bad participants. " +role +" role: expected '" +expected +"', actual '" +actual +"'"); - } + throw new CordaRuntimeException("Bad Opponent. Expcted: " + conterpartyName + " axtual: " + opponentName); } + // public static class ParticipantException extends Exception { + // public ParticipantException(String role, MemberX500Name expected, + // MemberX500Name actual) { + // super("Bad participants. " +role +" role: expected '" +expected +"', actual + // '" +actual +"'"); + // } + // } }