Fixes to avoid Quasar bug, bug fix in chat verification, switch from List.of to Array.asList

This commit is contained in:
Chris Barratt 2023-01-18 11:25:33 +00:00
parent d475cb19d7
commit e9c1139bfd
6 changed files with 35 additions and 10 deletions

View File

@ -20,25 +20,24 @@ import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderVali
import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderValidationHelpers.checkMessageFromMatchesCounterparty; import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderValidationHelpers.checkMessageFromMatchesCounterparty;
@InitiatedBy(protocol = "append-chat-protocol") @InitiatedBy(protocol = "append-chat-protocol")
class AppendChatResponderFlow implements ResponderFlow { public class AppendChatResponderFlow implements ResponderFlow {
private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class); private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class);
@CordaInject @CordaInject
public UtxoLedgerService utxoLedgerService; public UtxoLedgerService utxoLedgerService;
@CordaSerializable /*
static public class TxValidator implements UtxoTransactionValidator { static public class TxValidator implements UtxoTransactionValidator {
private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class); private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class);
@ConstructorForDeserialization
public TxValidator(FlowSession session) { public TxValidator(FlowSession session) {
this.session = session; this.session = session;
} }
@Override @Override
public void checkTransaction(@NotNull UtxoLedgerTransaction ledgerTransaction) { public void checkTransaction(@NotNull UtxoLedgerTransaction ledgerTransaction) {
ChatState state = (ChatState) ledgerTransaction.getInputContractStates().get(0); ChatState state = (ChatState) ledgerTransaction.getOutputContractStates().get(0);
if (checkForBannedWords(state.getMessage()) || !checkMessageFromMatchesCounterparty(state, session.getCounterparty())) { if (checkForBannedWords(state.getMessage()) || !checkMessageFromMatchesCounterparty(state, session.getCounterparty())) {
throw new IllegalStateException("Failed verification"); throw new IllegalStateException("Failed verification");
} }
@ -48,12 +47,27 @@ public UtxoLedgerService utxoLedgerService;
private FlowSession session; private FlowSession session;
} }
*/
@Suspendable @Suspendable
@Override @Override
public void call(@NotNull FlowSession session) { public void call(@NotNull FlowSession session) {
log.info("AppendChatResponderFlow.call() called");
try { try {
TxValidator txValidator = new TxValidator(session); //TxValidator txValidator = new TxValidator(session);
UtxoTransactionValidator txValidator = ledgerTransaction -> {
ChatState state = (ChatState) ledgerTransaction.getOutputContractStates().get(0);
log.info("ChatState.getMessage() = " + state.getMessage());
log.info("ledgerTransaction.getOutputContractStates().size() = " + ledgerTransaction.getOutputContractStates().size()) ;
log.info("session.getCounterParty()=" + session.getCounterparty());
log.info("state.getMessageFrom()=" + state.getMessageFrom());
log.info("checkForBannedWords(state.getMessage) = " + checkForBannedWords(state.getMessage()));
log.info("checkMessageFromMatchesCounterparty(state, session.getCounterparty())=" + checkMessageFromMatchesCounterparty(state, session.getCounterparty()));
if (checkForBannedWords(state.getMessage()) || !checkMessageFromMatchesCounterparty(state, session.getCounterparty())) {
throw new IllegalStateException("Failed verification");
}
log.info("Verified the transaction - " + ledgerTransaction.getId());
};
// This is not a problem. // This is not a problem.
UtxoSignedTransaction finalizedSignedTransaction = utxoLedgerService.receiveFinality(session, txValidator); UtxoSignedTransaction finalizedSignedTransaction = utxoLedgerService.receiveFinality(session, txValidator);

View File

@ -52,7 +52,6 @@ public class AppendChatSubFlow implements SubFlow<String> {
); );
retVal = finalizedSignedTransaction.getId().toString(); retVal = finalizedSignedTransaction.getId().toString();
//retVal = "The returned";
log.info("Success! Response: " + retVal); log.info("Success! Response: " + retVal);
} catch (Exception e) { } catch (Exception e) {
log.warn("Finality failed", e); log.warn("Finality failed", e);

View File

@ -32,7 +32,7 @@ import static java.util.Objects.*;
@InitiatingFlow(protocol = "create-chat-protocol") @InitiatingFlow(protocol = "create-chat-protocol")
public class CreateNewChatFlow implements RPCStartableFlow { public class CreateNewChatFlow implements RPCStartableFlow {
private final Logger log = LoggerFactory.getLogger(CreateNewChatFlow.class); private final static Logger log = LoggerFactory.getLogger(CreateNewChatFlow.class);
@CordaInject @CordaInject
public JsonMarshallingService jsonMarshallingService; public JsonMarshallingService jsonMarshallingService;
@ -90,6 +90,8 @@ public class CreateNewChatFlow implements RPCStartableFlow {
*/ */
// Quasar checkpointing has a bugs handling lambdas in flows.
// This is being worked upon.
PublicKey notaryKey = null; PublicKey notaryKey = null;
for(MemberInfo info: memberLookup.lookup()){ for(MemberInfo info: memberLookup.lookup()){
if(Objects.equals(info.getMemberProvidedContext().get("corda.notary.service.name"), notary.getName().toString()) ) { if(Objects.equals(info.getMemberProvidedContext().get("corda.notary.service.name"), notary.getName().toString()) ) {

View File

@ -17,7 +17,7 @@ public final class ResponderValidationHelpers {
@Suspendable @Suspendable
public static boolean checkMessageFromMatchesCounterparty(ChatState state, MemberX500Name otherMember) { public static boolean checkMessageFromMatchesCounterparty(ChatState state, MemberX500Name otherMember) {
return state.getMessageFrom() == otherMember; return state.getMessageFrom().equals(otherMember);
} }
// This class just introduces a scope for some helper functions and should not be instantiated. // This class just introduces a scope for some helper functions and should not be instantiated.

View File

@ -108,3 +108,14 @@ public class UpdateChatFlow implements RPCStartableFlow {
} }
} }
/*
RequestBody for triggering the flow via http-rpc:
{
"clientRequestId": "update-1",
"flowClassName": "com.r3.developers.csdetemplate.utxoexample.workflows.UpdateChatFlow",
"requestData": {
"id":" ** chat id **",
"message": "How are you today?"
}
}
*/

View File

@ -13,7 +13,6 @@ public final class CorDappHelpers {
Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList()); Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList());
if(results.size() != 1){ if(results.size() != 1){
throw new IllegalArgumentException(exceptionMsg); throw new IllegalArgumentException(exceptionMsg);
//throw new Exception(exceptionMsg);
} }
return results.iterator().next(); return results.iterator().next();
} }