diff --git a/contracts/src/main/java/com/r3/developers/csdetemplate/utxoexample/states/ChatState.java b/contracts/src/main/java/com/r3/developers/csdetemplate/utxoexample/states/ChatState.java index 8073cac..ddff982 100644 --- a/contracts/src/main/java/com/r3/developers/csdetemplate/utxoexample/states/ChatState.java +++ b/contracts/src/main/java/com/r3/developers/csdetemplate/utxoexample/states/ChatState.java @@ -11,19 +11,6 @@ import org.jetbrains.annotations.NotNull; import java.security.PublicKey; import java.util.*; -/* -@BelongsToContract(ChatContract::class) -data class ChatState( - val id : UUID = UUID.randomUUID(), - val chatName: String, - val messageFrom: MemberX500Name, - val message: String, - override val participants: List) : ContractState { - - fun updateMessage(messageFrom: MemberX500Name, message: String) = copy(messageFrom = messageFrom, message = message) - } -*/ - @CordaSerializable @BelongsToContract(ChatContract.class) public class ChatState implements ContractState { @@ -105,7 +92,7 @@ public class ChatState implements ContractState { public List participants; public ChatState updateMessage(MemberX500Name name, String message) { - return new ChatState(chatName, name, message, participants); + return new ChatState(id, chatName, name, message, participants); } @Override diff --git a/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/GetChatFlow.java b/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/GetChatFlow.java index 264468e..a0557f4 100644 --- a/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/GetChatFlow.java +++ b/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/GetChatFlow.java @@ -36,8 +36,11 @@ public class GetChatFlow implements RPCStartableFlow { GetChatFlowArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, GetChatFlowArgs.class); List> stateAndRefs = ledgerService.findUnconsumedStatesByType(ChatState.class); + log.info("GetChatFlow Number of stateAndRefs = " + stateAndRefs.size()); + log.info("GetChatFlow stateAndRefs = " + stateAndRefs); + StateAndRef state = findAndExpectExactlyOne(stateAndRefs, - stateAndRef -> stateAndRef.getState().getContractState().getId() == flowArgs.getId(), + stateAndRef -> stateAndRef.getState().getContractState().getId().equals(flowArgs.getId()), "did not find an unique ChatState" ); diff --git a/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/UpdateChatFlow.java b/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/UpdateChatFlow.java index d3e4d31..d2b020c 100644 --- a/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/UpdateChatFlow.java +++ b/workflows/src/main/java/com/r3/developers/csdetemplate/utxoexample/workflows/UpdateChatFlow.java @@ -60,10 +60,11 @@ public class UpdateChatFlow implements RPCStartableFlow { try { UpdateChatFlowArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, UpdateChatFlowArgs.class); - // look up state (this is very inefficient) + // Look up state (this is very inefficient) + // Can get the error when you forget to update the ID. StateAndRef stateAndRef = findAndExpectExactlyOne( ledgerService.findUnconsumedStatesByType(ChatState.class), - sAndR -> sAndR.getState().getContractState().getId() == flowArgs.getId(), + sAndR -> sAndR.getState().getContractState().getId().equals(flowArgs.getId()), "Multiple or zero Chat states with id " + flowArgs.getId() + " found" ); @@ -74,15 +75,11 @@ public class UpdateChatFlow implements RPCStartableFlow { it -> requireNonNull(memberLookup.lookup(it), "Member not found from Key") ).collect(Collectors.toList()); - - // Now we want to check that there is only - /* - val otherMember = (members - myInfo).singleOrNull() - ?: throw Exception("Should be only one participant other than the initiator") - - */ - // NEED TO ADD CHECKS + // Now we want to check that there is only one member other than ourselves in the chat. members.remove(myInfo); + if(members.size() != 1) { + throw new IllegalArgumentException("Should be only one participant other than the initiator"); + } MemberInfo otherMember = members.get(0); // This needs to be a deep copy? @@ -114,7 +111,7 @@ RequestBody for triggering the flow via http-rpc: "clientRequestId": "update-1", "flowClassName": "com.r3.developers.csdetemplate.utxoexample.workflows.UpdateChatFlow", "requestData": { - "id":" ** chat id **", + "id":" ** fill in id **", "message": "How are you today?" } }