Fixes to avoid Quasar bug, bug fix in chat verification, switch from List.of to Array.asList
This commit is contained in:
parent
d475cb19d7
commit
e9c1139bfd
@ -20,25 +20,24 @@ import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderVali
|
||||
import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderValidationHelpers.checkMessageFromMatchesCounterparty;
|
||||
|
||||
@InitiatedBy(protocol = "append-chat-protocol")
|
||||
class AppendChatResponderFlow implements ResponderFlow {
|
||||
public class AppendChatResponderFlow implements ResponderFlow {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class);
|
||||
|
||||
@CordaInject
|
||||
public UtxoLedgerService utxoLedgerService;
|
||||
|
||||
@CordaSerializable
|
||||
/*
|
||||
static public class TxValidator implements UtxoTransactionValidator {
|
||||
private final Logger log = LoggerFactory.getLogger(AppendChatResponderFlow.class);
|
||||
|
||||
@ConstructorForDeserialization
|
||||
public TxValidator(FlowSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
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())) {
|
||||
throw new IllegalStateException("Failed verification");
|
||||
}
|
||||
@ -48,12 +47,27 @@ public UtxoLedgerService utxoLedgerService;
|
||||
private FlowSession session;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Suspendable
|
||||
@Override
|
||||
public void call(@NotNull FlowSession session) {
|
||||
|
||||
log.info("AppendChatResponderFlow.call() called");
|
||||
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.
|
||||
UtxoSignedTransaction finalizedSignedTransaction = utxoLedgerService.receiveFinality(session, txValidator);
|
||||
|
@ -52,7 +52,6 @@ public class AppendChatSubFlow implements SubFlow<String> {
|
||||
);
|
||||
|
||||
retVal = finalizedSignedTransaction.getId().toString();
|
||||
//retVal = "The returned";
|
||||
log.info("Success! Response: " + retVal);
|
||||
} catch (Exception e) {
|
||||
log.warn("Finality failed", e);
|
||||
|
@ -32,7 +32,7 @@ import static java.util.Objects.*;
|
||||
@InitiatingFlow(protocol = "create-chat-protocol")
|
||||
public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CreateNewChatFlow.class);
|
||||
private final static Logger log = LoggerFactory.getLogger(CreateNewChatFlow.class);
|
||||
|
||||
@CordaInject
|
||||
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;
|
||||
for(MemberInfo info: memberLookup.lookup()){
|
||||
if(Objects.equals(info.getMemberProvidedContext().get("corda.notary.service.name"), notary.getName().toString()) ) {
|
||||
|
@ -17,7 +17,7 @@ public final class ResponderValidationHelpers {
|
||||
|
||||
@Suspendable
|
||||
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.
|
||||
|
@ -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?"
|
||||
}
|
||||
}
|
||||
*/
|
@ -13,7 +13,6 @@ public final class CorDappHelpers {
|
||||
Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList());
|
||||
if(results.size() != 1){
|
||||
throw new IllegalArgumentException(exceptionMsg);
|
||||
//throw new Exception(exceptionMsg);
|
||||
}
|
||||
return results.iterator().next();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user