.getTransaction()
This commit is contained in:
parent
946721c40e
commit
098645710f
@ -12,14 +12,14 @@ import net.corda.v5.application.membership.MemberLookup;
|
|||||||
import net.corda.v5.application.messaging.FlowSession;
|
import net.corda.v5.application.messaging.FlowSession;
|
||||||
import net.corda.v5.base.annotations.Suspendable;
|
import net.corda.v5.base.annotations.Suspendable;
|
||||||
import net.corda.v5.base.exceptions.CordaRuntimeException;
|
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.UtxoLedgerService;
|
||||||
import net.corda.v5.ledger.utxo.transaction.UtxoLedgerTransaction;
|
import net.corda.v5.ledger.utxo.transaction.UtxoLedgerTransaction;
|
||||||
|
import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction;
|
||||||
import net.corda.v5.ledger.utxo.transaction.UtxoTransactionValidator;
|
import net.corda.v5.ledger.utxo.transaction.UtxoTransactionValidator;
|
||||||
|
|
||||||
@InitiatedBy(protocol = "gamestate-commit")
|
@InitiatedBy(protocol = "gamestate-commit")
|
||||||
public class CommitTrxResponder implements ResponderFlow {
|
public class CommitTrxResponder implements ResponderFlow {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(CommitTrxResponder.class);
|
private final static Logger log = LoggerFactory.getLogger(CommitTrxResponder.class);
|
||||||
|
|
||||||
@CordaInject
|
@CordaInject
|
||||||
@ -27,12 +27,12 @@ public class CommitTrxResponder implements ResponderFlow {
|
|||||||
|
|
||||||
@CordaInject
|
@CordaInject
|
||||||
public UtxoLedgerService utxoLedgerService;
|
public UtxoLedgerService utxoLedgerService;
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
@Override
|
@Override
|
||||||
public void call(FlowSession session) {
|
public void call(FlowSession session) {
|
||||||
UtxoTransactionValidator txValidator = trxToValidate -> {
|
try {
|
||||||
try {
|
UtxoTransactionValidator txValidator = trxToValidate -> {
|
||||||
checkParticipants(session, trxToValidate);
|
checkParticipants(session, trxToValidate);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -40,42 +40,40 @@ public class CommitTrxResponder implements ResponderFlow {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
log.info("Approval for " + trxToValidate.getId());
|
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 {
|
UtxoSignedTransaction finalizedSignedTransaction = this.utxoLedgerService
|
||||||
this.utxoLedgerService
|
.receiveFinality(session, txValidator)
|
||||||
.receiveFinality(session, txValidator);
|
.getTransaction();
|
||||||
|
|
||||||
|
log.info("Finished responder flow - " + finalizedSignedTransaction.getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Log Corda's specific message about finality validation failure
|
// Log Corda's specific message about finality validation failure
|
||||||
log.warn(e.getMessage());
|
log.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
void checkParticipants(FlowSession session, UtxoLedgerTransaction gameStateUtxo) throws ParticipantException {
|
void checkParticipants(FlowSession session, UtxoLedgerTransaction gameStateUtxo) {
|
||||||
final GameInfo info = new GameInfo(gameStateUtxo);
|
final GameInfo info = new GameInfo(gameStateUtxo);
|
||||||
final var conterpartyName = session.getCounterparty();
|
final var conterpartyName = session.getCounterparty();
|
||||||
if (info.issuer.compareTo(conterpartyName) != 0)
|
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();
|
final var myInfo = memberLookup.myInfo();
|
||||||
if (VNode.isCordaCherckersCustodian(myInfo))
|
if (VNode.isCordaCherckersCustodian(myInfo))
|
||||||
return; // Custodian shall not validate state's counterparty
|
return; // Custodian shall not validate state's counterparty
|
||||||
|
|
||||||
final var opponentName = info.state.getOpponentName(myInfo.getName()); // throws NotInvolved
|
final var opponentName = info.state.getOpponentName(myInfo.getName()); // throws NotInvolved
|
||||||
if (conterpartyName.compareTo(opponentName) != 0)
|
if (conterpartyName.compareTo(opponentName) != 0)
|
||||||
throw new ParticipantException("Opponent", conterpartyName, opponentName);
|
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 +"'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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