.getTransaction()
This commit is contained in:
parent
946721c40e
commit
098645710f
@ -12,9 +12,9 @@ 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")
|
||||
@ -31,8 +31,8 @@ public class CommitTrxResponder implements ResponderFlow {
|
||||
@Suspendable
|
||||
@Override
|
||||
public void call(FlowSession session) {
|
||||
UtxoTransactionValidator txValidator = trxToValidate -> {
|
||||
try {
|
||||
UtxoTransactionValidator txValidator = trxToValidate -> {
|
||||
checkParticipants(session, trxToValidate);
|
||||
|
||||
/*
|
||||
@ -40,16 +40,13 @@ 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());
|
||||
@ -57,11 +54,11 @@ public class CommitTrxResponder implements ResponderFlow {
|
||||
}
|
||||
|
||||
@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))
|
||||
@ -69,13 +66,14 @@ public class CommitTrxResponder implements ResponderFlow {
|
||||
|
||||
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 +"'");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user